| @@ 82-102 (lines=21) @@ | ||
| 79 | /** |
|
| 80 | * @inheritdoc |
|
| 81 | */ |
|
| 82 | public function post($resource, $content) |
|
| 83 | { |
|
| 84 | $url = $this->baseUrl . $resource; |
|
| 85 | ||
| 86 | $headers = array( |
|
| 87 | 'Content-Type' => 'application/json', |
|
| 88 | 'Authorization' => $this->auth->getCredential() |
|
| 89 | ); |
|
| 90 | ||
| 91 | try { |
|
| 92 | $response = $this->browser->post($url, $headers, json_encode($content)); |
|
| 93 | } catch (\Buzz\Exception\ClientException $e) { |
|
| 94 | throw new RequestException($e->getMessage()); |
|
| 95 | } |
|
| 96 | ||
| 97 | if ($this->browser->getLastResponse()->getStatusCode() > 299) { |
|
| 98 | throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true)); |
|
| 99 | } |
|
| 100 | ||
| 101 | return json_decode($response->getContent(), true); |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * @inheritdoc |
|
| @@ 107-126 (lines=20) @@ | ||
| 104 | /** |
|
| 105 | * @inheritdoc |
|
| 106 | */ |
|
| 107 | public function put($resource, $content = array()) |
|
| 108 | { |
|
| 109 | $url = $this->baseUrl . $resource; |
|
| 110 | $headers = array( |
|
| 111 | 'Content-Type' => 'application/json', |
|
| 112 | 'Authorization' => $this->auth->getCredential() |
|
| 113 | ); |
|
| 114 | ||
| 115 | try { |
|
| 116 | $response = $this->browser->put($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 | * @inheritdoc |
|
| @@ 131-150 (lines=20) @@ | ||
| 128 | /** |
|
| 129 | * @inheritdoc |
|
| 130 | */ |
|
| 131 | public function delete($resource) |
|
| 132 | { |
|
| 133 | $url = $this->baseUrl . $resource; |
|
| 134 | ||
| 135 | $headers = array( |
|
| 136 | 'Authorization' => $this->auth->getCredential() |
|
| 137 | ); |
|
| 138 | ||
| 139 | try { |
|
| 140 | $response = $this->browser->delete($url, $headers); |
|
| 141 | } catch (\Buzz\Exception\ClientException $e) { |
|
| 142 | throw new RequestException($e->getMessage()); |
|
| 143 | } |
|
| 144 | ||
| 145 | if ($this->browser->getLastResponse()->getStatusCode() > 299) { |
|
| 146 | throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true)); |
|
| 147 | } |
|
| 148 | ||
| 149 | return json_decode($response->getContent(), true); |
|
| 150 | } |
|
| 151 | } |
|
| 152 | ||