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 | * |
||
22 | * @param array $response |
||
23 | * @param null $key |
||
24 | * |
||
25 | * @return array|bool |
||
26 | */ |
||
27 | public function getData($response, $key = null) |
||
28 | { |
||
29 | if (!$this->hasErrors($response)) { |
||
30 | return false; |
||
31 | } |
||
32 | |||
33 | return $this->parseData($response, $key); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Parse data from Pinterest Api response. |
||
38 | * Data stores in ['resource_response']['data'] array. |
||
39 | * |
||
40 | * @param array $response |
||
41 | * @param string $key |
||
42 | * |
||
43 | * @return bool|array |
||
44 | */ |
||
45 | protected function parseData($response, $key) |
||
59 | |||
60 | /** |
||
61 | * Checks if response is empty. |
||
62 | * |
||
63 | * @param array $response |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | public function isEmpty($response) |
||
71 | |||
72 | /** |
||
73 | * Check for error info in api response and save |
||
74 | * it. |
||
75 | * |
||
76 | * @param array $response |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function hasErrors($response) |
||
92 | |||
93 | /** |
||
94 | * Parse bookmarks from response. |
||
95 | * |
||
96 | * @param array $response |
||
97 | * |
||
98 | * @return array|null |
||
99 | */ |
||
100 | public function getBookmarks($response) |
||
108 | |||
109 | /** |
||
110 | * Checks Pinterest API paginated response, and parses data |
||
111 | * with bookmarks info from it. |
||
112 | * |
||
113 | * @param array $response |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | public function getPaginationData($response) |
||
130 | |||
131 | /** |
||
132 | * @return array |
||
133 | */ |
||
134 | public function getLastError() |
||
138 | } |
||
139 |