1 | <?php |
||
7 | class Response implements ResponseInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $response; |
||
13 | |||
14 | /** |
||
15 | * @var array|null |
||
16 | */ |
||
17 | protected $lastError; |
||
18 | |||
19 | /** |
||
20 | * Check if specified data exists in response |
||
21 | * @param array $response |
||
22 | * @param null $key |
||
23 | * @return array|bool |
||
24 | */ |
||
25 | public function getData($response, $key = null) |
||
26 | { |
||
27 | if ( ! $this->checkErrorInResponse($response)) { |
||
28 | return false; |
||
29 | } |
||
30 | |||
31 | return $this->parseData($response, $key); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Parse data from Pinterest Api response. |
||
36 | * Data stores in ['resource_response']['data'] array |
||
37 | * |
||
38 | * @param array $response |
||
39 | * @param string $key |
||
40 | * @return bool|array |
||
41 | */ |
||
42 | protected function parseData($response, $key) |
||
56 | |||
57 | /** |
||
58 | * Checks if response is not empty |
||
59 | * |
||
60 | * @param array $response |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function notEmpty($response) |
||
67 | |||
68 | /** |
||
69 | * @param array $response |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function checkResponse($response) |
||
76 | |||
77 | /** |
||
78 | * Check for error info in api response and save |
||
79 | * it. |
||
80 | * |
||
81 | * @param array $response |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function checkErrorInResponse($response) |
||
95 | |||
96 | /** |
||
97 | * Parse bookmarks from response |
||
98 | * @param array $response |
||
99 | * @return array|null |
||
100 | */ |
||
101 | public function getBookmarksFromResponse($response) |
||
112 | |||
113 | /** |
||
114 | * Checks Pinterest API paginated response, and parses data |
||
115 | * with bookmarks info from it. |
||
116 | * |
||
117 | * @param array $response |
||
118 | * @return array |
||
119 | */ |
||
120 | public function getPaginationData($response) |
||
133 | |||
134 | /** |
||
135 | * Parses Pinterest search API response for data and bookmarks |
||
136 | * for next pagination page |
||
137 | * |
||
138 | * @param array $response |
||
139 | * @param bool $bookmarksUsed |
||
140 | * @return array|null |
||
141 | */ |
||
142 | public function parseSearchResponse($response, $bookmarksUsed = true) |
||
150 | |||
151 | /** |
||
152 | * Parses simple Pinterest search API response |
||
153 | * on request with bookmarks |
||
154 | * |
||
155 | * @param array $response |
||
156 | * @return array |
||
157 | */ |
||
158 | public function parseSimpledSearchResponse($response) |
||
171 | |||
172 | /** |
||
173 | * @return array |
||
174 | */ |
||
175 | public function getLastError() |
||
179 | } |