@@ 106-126 (lines=21) @@ | ||
103 | * @return array Decoded array containing response |
|
104 | * @throws Exception\RequestException |
|
105 | */ |
|
106 | public function post($resource, $content) |
|
107 | { |
|
108 | $url = $this->baseUrl . $resource; |
|
109 | ||
110 | $headers = array( |
|
111 | 'Content-Type' => 'application/json', |
|
112 | 'Authorization' => $this->auth->getCredential() |
|
113 | ); |
|
114 | ||
115 | try { |
|
116 | $response = $this->browser->post($url, $headers, json_encode($content)); |
|
117 | } catch (\Buzz\Exception\ClientException $e) { |
|
118 | throw new RequestException($e->getMessage()); |
|
119 | } |
|
120 | ||
121 | if ($this->browser->getLastResponse()->getStatusCode() > 299) { |
|
122 | throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true)); |
|
123 | } |
|
124 | ||
125 | return json_decode($response->getContent(), true); |
|
126 | } |
|
127 | ||
128 | /** |
|
129 | * Common put request for all API calls |
|
@@ 144-163 (lines=20) @@ | ||
141 | * @return array Decoded array containing response |
|
142 | * @throws Exception\RequestException |
|
143 | */ |
|
144 | public function put($resource, $content = array()) |
|
145 | { |
|
146 | $url = $this->baseUrl . $resource; |
|
147 | $headers = array( |
|
148 | 'Content-Type' => 'application/json', |
|
149 | 'Authorization' => $this->auth->getCredential() |
|
150 | ); |
|
151 | ||
152 | try { |
|
153 | $response = $this->browser->put($url, $headers, json_encode($content)); |
|
154 | } catch (\Buzz\Exception\ClientException $e) { |
|
155 | throw new RequestException($e->getMessage()); |
|
156 | } |
|
157 | ||
158 | if ($this->browser->getLastResponse()->getStatusCode() > 299) { |
|
159 | throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true)); |
|
160 | } |
|
161 | ||
162 | return json_decode($response->getContent(), true); |
|
163 | } |
|
164 | ||
165 | /** |
|
166 | * Common delete request for all API calls |
|
@@ 173-192 (lines=20) @@ | ||
170 | * @return array Decoded array containing response |
|
171 | * @throws Exception\RequestException |
|
172 | */ |
|
173 | public function delete($resource) |
|
174 | { |
|
175 | $url = $this->baseUrl . $resource; |
|
176 | ||
177 | $headers = array( |
|
178 | 'Authorization' => $this->auth->getCredential() |
|
179 | ); |
|
180 | ||
181 | try { |
|
182 | $response = $this->browser->delete($url, $headers); |
|
183 | } catch (\Buzz\Exception\ClientException $e) { |
|
184 | throw new RequestException($e->getMessage()); |
|
185 | } |
|
186 | ||
187 | if ($this->browser->getLastResponse()->getStatusCode() > 299) { |
|
188 | throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true)); |
|
189 | } |
|
190 | ||
191 | return json_decode($response->getContent(), true); |
|
192 | } |
|
193 | } |
|
194 |