1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Helpers; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class UrlHelper. |
7
|
|
|
*/ |
8
|
|
|
class UrlBuilder |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Login |
12
|
|
|
*/ |
13
|
|
|
const RESOURCE_LOGIN = 'resource/UserSessionResource/create/'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Password |
17
|
|
|
*/ |
18
|
|
|
const RESOURCE_RESET_PASSWORD_SEND_LINK = 'resource/UserResetPasswordResource/create/'; |
19
|
|
|
const RESOURCE_RESET_PASSWORD_UPDATE = 'resource/ResetPasswordFromEmailResource/update/'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Boards |
23
|
|
|
*/ |
24
|
|
|
const RESOURCE_GET_BOARDS = 'resource/BoardsResource/get/'; |
25
|
|
|
const RESOURCE_GET_BOARD = 'resource/BoardResource/get/'; |
26
|
|
|
const RESOURCE_GET_BOARD_FEED = 'resource/BoardFeedResource/get/'; |
27
|
|
|
const RESOURCE_PROFILE_BOARDS = 'resource/ProfileBoardsResource/get/'; |
28
|
|
|
const RESOURCE_FOLLOW_BOARD = 'resource/BoardFollowResource/create/'; |
29
|
|
|
const RESOURCE_UNFOLLOW_BOARD = 'resource/BoardFollowResource/delete/'; |
30
|
|
|
const RESOURCE_DELETE_BOARD = 'resource/BoardResource/delete/'; |
31
|
|
|
const RESOURCE_CREATE_BOARD = 'resource/BoardResource/create/'; |
32
|
|
|
const RESOURCE_UPDATE_BOARD = 'resource/BoardResource/update/'; |
33
|
|
|
const RESOURCE_BOARD_FOLLOWERS = 'resource/BoardFollowersResource/get/'; |
34
|
|
|
const RESOURCE_FOLLOWING_BOARDS = 'resource/BoardFollowingResource/get/'; |
35
|
|
|
const RESOURCE_TITLE_SUGGESTIONS = 'resource/BoardTitleSuggestionsResource/get'; |
36
|
|
|
const RESOURCE_BOARDS_INVITES = 'resource/BoardInvitesResource/get/'; |
37
|
|
|
const RESOURCE_CREATE_USER_ID_INVITE = 'resource/BoardInviteResource/create'; |
38
|
|
|
const RESOURCE_CREATE_EMAIL_INVITE = 'resource/BoardEmailInviteResource/create/'; |
39
|
|
|
const RESOURCE_ACCEPT_INVITE = 'resource/BoardInviteResource/update/'; |
40
|
|
|
const RESOURCE_DELETE_INVITE = 'resource/BoardInviteResource/delete/'; |
41
|
|
|
const RESOURCE_LEAVE_BOARD = 'resource/BoardCollaboratorResource/delete/'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Board section |
45
|
|
|
*/ |
46
|
|
|
const RESOURCE_GET_BOARD_SECTIONS = 'resource/BoardSectionsResource/get/'; |
47
|
|
|
const RESOURCE_ADD_BOARD_SECTION = 'resource/BoardSectionResource/create/'; |
48
|
|
|
const RESOURCE_EDIT_BOARD_SECTION = 'resource/BoardSectionEditResource/create/'; |
49
|
|
|
const RESOURCE_DELETE_BOARD_SECTION = 'resource/BoardSectionEditResource/delete/'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Pins |
53
|
|
|
*/ |
54
|
|
|
const RESOURCE_CREATE_PIN = 'resource/PinResource/create/'; |
55
|
|
|
const RESOURCE_UPDATE_PIN = 'resource/PinResource/update/'; |
56
|
|
|
const RESOURCE_REPIN = 'resource/RepinResource/create/'; |
57
|
|
|
const RESOURCE_USER_FOLLOWERS = 'resource/UserFollowersResource/get/'; |
58
|
|
|
const RESOURCE_DELETE_PIN = 'resource/PinResource/delete/'; |
59
|
|
|
const RESOURCE_LIKE_PIN = 'resource/PinLikeResource/create/'; |
60
|
|
|
const RESOURCE_UNLIKE_PIN = 'resource/PinLikeResource/delete/'; |
61
|
|
|
const RESOURCE_COMMENT_PIN = 'resource/AggregatedCommentResource/create/'; |
62
|
|
|
const RESOURCE_COMMENT_DELETE_PIN = 'resource/AggregatedCommentResource/delete/'; |
63
|
|
|
const RESOURCE_PIN_INFO = 'resource/PinResource/get/'; |
64
|
|
|
const RESOURCE_DOMAIN_FEED = 'resource/DomainFeedResource/get/'; |
65
|
|
|
const RESOURCE_ACTIVITY = 'resource/AggregatedActivityFeedResource/get/'; |
66
|
|
|
const RESOURCE_USER_FEED = 'resource/UserHomefeedResource/get/'; |
67
|
|
|
const RESOURCE_RELATED_PINS = 'resource/RelatedPinFeedResource/get/'; |
68
|
|
|
const RESOURCE_VISUAL_SIMILAR_PINS = 'resource/VisualLiveSearchResource/get/'; |
69
|
|
|
const RESOURCE_BULK_COPY = 'resource/BulkEditResource/create/'; |
70
|
|
|
const RESOURCE_BULK_MOVE = 'resource/BulkEditResource/update/'; |
71
|
|
|
const RESOURCE_BULK_DELETE = 'resource/BulkEditResource/delete/'; |
72
|
|
|
const RESOURCE_EXPLORE_PINS = 'resource/ExploreSectionFeedResource/get/'; |
73
|
|
|
const RESOURCE_PIN_ANALYTICS = 'resource/OnPinAnalyticsResource/get/'; |
74
|
|
|
const RESOURCE_TRY_PIN_CREATE = 'resource/DidItActivityResource/create/'; |
75
|
|
|
const RESOURCE_TRY_PIN_EDIT = 'resource/DidItActivityResource/update/'; |
76
|
|
|
const RESOURCE_TRY_PIN_DELETE = 'resource/DidItActivityResource/delete/'; |
77
|
|
|
const RESOURCE_TRY_PIN_IMAGE_UPLOAD = 'resource/DidItImageUploadResource/create/'; |
78
|
|
|
const RESOURCE_SHARE_VIA_SOCIAL = 'resource/CreateExternalInviteResource/create/'; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Pinners |
82
|
|
|
*/ |
83
|
|
|
const RESOURCE_FOLLOW_USER = 'resource/UserFollowResource/create/'; |
84
|
|
|
const RESOURCE_UNFOLLOW_USER = 'resource/UserFollowResource/delete/'; |
85
|
|
|
const RESOURCE_USER_INFO = 'resource/UserResource/get/'; |
86
|
|
|
const RESOURCE_USER_FOLLOWING = 'resource/UserFollowingResource/get/'; |
87
|
|
|
const RESOURCE_USER_PINS = 'resource/UserPinsResource/get/'; |
88
|
|
|
const RESOURCE_USER_LIKES = 'resource/UserLikesResource/get/'; |
89
|
|
|
const RESOURCE_USER_TRIED = 'resource/DidItUserFeedResource/get/'; |
90
|
|
|
|
91
|
|
|
const RESOURCE_CONTACTS_REQUESTS = 'resource/ContactRequestsResource/get'; |
92
|
|
|
const RESOURCE_CONTACT_REQUEST_ACCEPT = 'resource/ContactRequestAcceptResource/update/'; |
93
|
|
|
const RESOURCE_CONTACT_REQUEST_IGNORE = 'resource/ContactRequestIgnoreResource/delete/'; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Search |
97
|
|
|
*/ |
98
|
|
|
const RESOURCE_SEARCH = 'resource/BaseSearchResource/get/'; |
99
|
|
|
const RESOURCE_SEARCH_WITH_PAGINATION = 'resource/SearchResource/get/'; |
100
|
|
|
const RESOURCE_TYPE_AHEAD_SUGGESTIONS = 'resource/AdvancedTypeaheadResource/get'; |
101
|
|
|
const RESOURCE_HASHTAG_TYPE_AHEAD_SUGGESTIONS = 'resource/HashtagTypeaheadResource/get'; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Interests. |
105
|
|
|
*/ |
106
|
|
|
const RESOURCE_FOLLOW_INTEREST = 'resource/InterestFollowResource/create/'; |
107
|
|
|
const RESOURCE_UNFOLLOW_INTEREST = 'resource/InterestFollowResource/delete/'; |
108
|
|
|
const RESOURCE_FOLLOWING_INTERESTS = 'resource/InterestFollowingResource/get/'; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Conversations. |
112
|
|
|
*/ |
113
|
|
|
const RESOURCE_SEND_MESSAGE = 'resource/ConversationsResource/create/'; |
114
|
|
|
const RESOURCE_GET_CONVERSATION_MESSAGES = 'resource/ConversationMessagesResource/get/'; |
115
|
|
|
const RESOURCE_GET_LAST_CONVERSATIONS = 'resource/ConversationsResource/get/'; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* UserSettings |
119
|
|
|
*/ |
120
|
|
|
const RESOURCE_UPDATE_USER_SETTINGS = 'resource/UserSettingsResource/update/'; |
121
|
|
|
const RESOURCE_GET_USER_SETTINGS = 'resource/UserSettingsResource/get/'; |
122
|
|
|
const RESOURCE_CHANGE_PASSWORD = 'resource/UserPasswordResource/update/'; |
123
|
|
|
const RESOURCE_DEACTIVATE_ACCOUNT = 'resource/DeactivateAccountResource/create/'; |
124
|
|
|
const RESOURCE_BLOCK_USER = 'resource/UserBlockResource/create/'; |
125
|
|
|
const RESOURCE_CLEAR_SEARCH_HISTORY = 'resource/TypeaheadClearRecentResource/delete/'; |
126
|
|
|
const RESOURCE_SESSIONS_HISTORY = 'resource/UserSessionStoreResource/get/'; |
127
|
|
|
const RESOURCE_AVAILABLE_LOCALES = 'resource/LocalesResource/get/'; |
128
|
|
|
const RESOURCE_AVAILABLE_COUNTRIES = 'resource/CountriesResource/get/'; |
129
|
|
|
const RESOURCE_AVAILABLE_ACCOUNT_TYPES = 'resource/BusinessTypesResource/get/'; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* News |
133
|
|
|
*/ |
134
|
|
|
const RESOURCE_GET_LATEST_NEWS = 'resource/NetworkStoriesResource/get/'; |
135
|
|
|
const RESOURCE_GET_NOTIFICATIONS = 'resource/NewsHubResource/get/'; |
136
|
|
|
const RESOURCE_GET_NEWS_HUB_DETAILS = 'resource/NewsHubDetailsResource/get/'; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Registration |
140
|
|
|
*/ |
141
|
|
|
const RESOURCE_CREATE_REGISTER = 'resource/UserRegisterResource/create/'; |
142
|
|
|
const RESOURCE_CHECK_EMAIL = 'resource/EmailExistsResource/get/'; |
143
|
|
|
const RESOURCE_SET_ORIENTATION = 'resource/OrientationContextResource/create/'; |
144
|
|
|
const RESOURCE_UPDATE_REGISTRATION_TRACK = 'resource/UserRegisterTrackActionResource/update/'; |
145
|
|
|
const RESOURCE_REGISTRATION_COMPLETE = 'resource/UserExperienceCompletedResource/update/'; |
146
|
|
|
const RESOURCE_CONVERT_TO_BUSINESS = 'resource/PartnerResource/update/'; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Uploads |
150
|
|
|
*/ |
151
|
|
|
const IMAGE_UPLOAD = 'upload-image/'; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Categories |
155
|
|
|
*/ |
156
|
|
|
const RESOURCE_GET_CATEGORIES = 'resource/CategoriesResource/get/'; |
157
|
|
|
const RESOURCE_GET_CATEGORY = 'resource/CategoryResource/get/'; |
158
|
|
|
const RESOURCE_GET_CATEGORIES_RELATED = 'resource/RelatedInterestsResource/get/'; |
159
|
|
|
const RESOURCE_GET_CATEGORY_FEED = 'resource/CategoryFeedResource/get/'; |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Topics |
163
|
|
|
*/ |
164
|
|
|
const RESOURCE_GET_TOPIC_FEED = 'resource/TopicFeedResource/get/'; |
165
|
|
|
const RESOURCE_GET_TOPIC = 'resource/TopicResource/get/'; |
166
|
|
|
const RESOURCE_EXPLORE_SECTIONS = 'resource/ExploreSectionsResource/get/'; |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Invite |
170
|
|
|
*/ |
171
|
|
|
const RESOURCE_INVITE = 'resource/EmailInviteSentResource/create/'; |
172
|
|
|
|
173
|
|
|
const URL_BASE = 'https://www.pinterest.com/'; |
174
|
|
|
const HOST = 'www.pinterest.com'; |
175
|
|
|
|
176
|
|
|
const FOLLOWING_INTERESTS = 'interests'; |
177
|
|
|
const FOLLOWING_PEOPLE = 'people'; |
178
|
|
|
const FOLLOWING_BOARDS = 'boards'; |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param array $request |
182
|
|
|
* |
183
|
|
|
* @return mixed |
184
|
|
|
*/ |
185
|
|
|
public static function buildRequestString($request) |
186
|
|
|
{ |
187
|
|
|
return self::fixEncoding(http_build_query($request)); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Appends resource url to base pinterest url. |
192
|
|
|
* |
193
|
|
|
* @param string $resourceUrl |
194
|
|
|
* |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public static function buildApiUrl($resourceUrl) |
198
|
|
|
{ |
199
|
|
|
if (strpos($resourceUrl, 'http') === 0) { |
200
|
|
|
return $resourceUrl; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return self::URL_BASE . $resourceUrl; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Fix URL-encoding for some characters. |
208
|
|
|
* |
209
|
|
|
* @param string $str |
210
|
|
|
* |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
|
|
public static function fixEncoding($str) |
214
|
|
|
{ |
215
|
|
|
return str_replace( |
216
|
|
|
['%28', '%29', '%7E'], ['(', ')', '~'], $str |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param string $type |
223
|
|
|
* @return string|null |
224
|
|
|
*/ |
225
|
|
|
public static function getFollowingUrlByType($type) |
226
|
|
|
{ |
227
|
|
|
$urls = [ |
228
|
|
|
self::FOLLOWING_INTERESTS => self::RESOURCE_FOLLOWING_INTERESTS, |
229
|
|
|
self::FOLLOWING_BOARDS => self::RESOURCE_FOLLOWING_BOARDS, |
230
|
|
|
self::FOLLOWING_PEOPLE => self::RESOURCE_USER_FOLLOWING, |
231
|
|
|
]; |
232
|
|
|
|
233
|
|
|
if (array_key_exists($type, $urls)) { |
234
|
|
|
return $urls[$type]; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
return null; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|