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