1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Helpers; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class UrlHelper |
7
|
|
|
*/ |
8
|
|
|
class UrlHelper |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Login |
13
|
|
|
*/ |
14
|
|
|
const RESOURCE_LOGIN = '/resource/UserSessionResource/create/'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Boards |
18
|
|
|
*/ |
19
|
|
|
const RESOURCE_GET_BOARDS = '/resource/BoardsResource/get/'; |
20
|
|
|
const RESOURCE_GET_BOARD_FEED = '/resource/BoardFeedResource/get/'; |
21
|
|
|
const RESOURCE_PROFILE_BOARDS = '/resource/ProfileBoardsResource/get/'; |
22
|
|
|
const RESOURCE_FOLLOW_BOARD = '/resource/BoardFollowResource/create/'; |
23
|
|
|
const RESOURCE_UNFOLLOW_BOARD = '/resource/BoardFollowResource/delete/'; |
24
|
|
|
const RESOURCE_DELETE_BOARD = '/resource/BoardResource/delete/'; |
25
|
|
|
const RESOURCE_CREATE_BOARD = '/resource/BoardResource/create/'; |
26
|
|
|
const RESOURCE_BOARD_FOLLOWERS = '/resource/BoardFollowersResource/get/'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Pins |
30
|
|
|
*/ |
31
|
|
|
const RESOURCE_CREATE_PIN = '/resource/PinResource/create/'; |
32
|
|
|
const RESOURCE_REPIN = '/resource/RepinResource/create/'; |
33
|
|
|
const RESOURCE_USER_FOLLOWERS = '/resource/UserFollowersResource/get/'; |
34
|
|
|
const RESOURCE_DELETE_PIN = '/resource/PinResource/delete/'; |
35
|
|
|
const RESOURCE_LIKE_PIN = '/resource/PinLikeResource2/create/'; |
36
|
|
|
const RESOURCE_UNLIKE_PIN = '/resource/PinLikeResource2/delete/'; |
37
|
|
|
const RESOURCE_COMMENT_PIN = '/resource/PinCommentResource/create/'; |
38
|
|
|
const RESOURCE_COMMENT_DELETE_PIN = '/resource/PinCommentResource/delete/'; |
39
|
|
|
const RESOURCE_PIN_INFO = '/resource/PinResource/get/'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Pinners |
43
|
|
|
*/ |
44
|
|
|
const RESOURCE_FOLLOW_USER = '/resource/UserFollowResource/create/'; |
45
|
|
|
const RESOURCE_UNFOLLOW_USER = '/resource/UserFollowResource/delete/'; |
46
|
|
|
const RESOURCE_USER_INFO = '/resource/UserResource/get/'; |
47
|
|
|
const RESOURCE_USER_FOLLOWING = '/resource/UserFollowingResource/get/'; |
48
|
|
|
const RESOURCE_USER_PINS = '/resource/UserPinsResource/get/'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Search |
52
|
|
|
*/ |
53
|
|
|
const RESOURCE_SEARCH = '/resource/BaseSearchResource/get/'; |
54
|
|
|
const RESOURCE_SEARCH_WITH_PAGINATION = '/resource/SearchResource/get/'; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Interests |
58
|
|
|
*/ |
59
|
|
|
const RESOURCE_FOLLOW_INTEREST = '/resource/InterestFollowResource/create/'; |
60
|
|
|
const RESOURCE_UNFOLLOW_INTEREST = '/resource/InterestFollowResource/delete/'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Conversations |
64
|
|
|
*/ |
65
|
|
|
const RESOURCE_SEND_MESSAGE = '/resource/ConversationsResource/create/'; |
66
|
|
|
const RESOURCE_GET_LAST_CONVERSATIONS = 'resource/ConversationsResource/get/'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* UserSettings |
70
|
|
|
*/ |
71
|
|
|
const RESOURCE_UPDATE_USER_SETTINGS = '/resource/UserSettingsResource/update/'; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* News |
75
|
|
|
*/ |
76
|
|
|
const RESOURCE_GET_LATEST_NEWS = '/resource/NetworkStoriesResource/get/'; |
77
|
|
|
const URL_BASE = 'https://nl.pinterest.com/'; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param array $request |
81
|
|
|
* @return mixed |
82
|
|
|
*/ |
83
|
|
|
public static function buildRequestString($request) |
84
|
|
|
{ |
85
|
|
|
return self::fixEncoding(http_build_query($request)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Appends resource url to base pinterest url |
90
|
|
|
* |
91
|
|
|
* @param string $resourceUrl |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public static function buildApiUrl($resourceUrl) |
95
|
|
|
{ |
96
|
|
|
return self::URL_BASE.ltrim($resourceUrl, '/'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Fix URL-encoding for some characters |
101
|
|
|
* |
102
|
|
|
* @param string $str |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public static function fixEncoding($str) |
106
|
|
|
{ |
107
|
|
|
return str_replace( |
108
|
|
|
['%28', '%29', '%7E'], ['(', ')', '~'], $str |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Return Pinterest API url for search requests |
114
|
|
|
* |
115
|
|
|
* @param bool $bookmarksUsed |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public static function getSearchUrl($bookmarksUsed) |
119
|
|
|
{ |
120
|
|
|
if ( ! $bookmarksUsed) { |
121
|
|
|
return self::RESOURCE_SEARCH; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return self::RESOURCE_SEARCH_WITH_PAGINATION; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|