11 defined(
'JPATH_PLATFORM') or die();
53 $this->options = isset($options) ? $options :
new JRegistry;
54 $this->client = isset($client) ? $client :
new JHttp($this->options);
55 $this->oauth = $oauth;
73 protected function fetchUrl($path, $limit = 0, $offset = 0, $until = null, $since = null)
76 $uri =
new JUri($this->options->get(
'api.url') . $path);
80 $uri->
setVar(
'limit', (
int) $limit);
85 $uri->setVar(
'offset', (
int) $offset);
90 $uri->setVar(
'until', $until);
95 $uri->setVar(
'since', $since);
117 public function sendRequest($path, $data =
'', array $headers = null, $limit = 0, $offset = 0, $until = null, $since = null)
120 $response = $this->client->get($this->fetchUrl($path, $limit, $offset, $until, $since), $headers);
122 $response = json_decode($response->body);
125 if (property_exists($response,
'error'))
127 throw new RuntimeException($response->error->message);
142 public function get($object)
144 if ($this->oauth != null)
146 if ($this->oauth->isAuthenticated())
148 $response = $this->oauth->query($this->fetchUrl($object));
150 return json_decode($response->body);
159 return $this->sendRequest($object);
177 public function getConnection($object, $connection = null, $extra_fields =
'', $limit = 0, $offset = 0, $until = null, $since = null)
179 $path = $object .
'/' . $connection . $extra_fields;
181 if ($this->oauth != null)
183 if ($this->oauth->isAuthenticated())
185 $response = $this->oauth->query($this->fetchUrl($path, $limit, $offset, $until, $since));
187 if (strcmp($response->body,
''))
189 return json_decode($response->body);
193 return $response->headers[
'Location'];
203 return $this->sendRequest($path,
'', null, $limit, $offset, $until, $since);
218 public function createConnection($object, $connection = null, $parameters = null, array $headers = null)
220 if ($this->oauth->isAuthenticated())
223 if ($connection != null)
225 $path = $object .
'/' . $connection;
233 $response = $this->oauth->query($this->fetchUrl($path), $parameters, $headers,
'post');
235 return json_decode($response->body);
254 public function deleteConnection($object, $connection = null, $extra_fields =
'')
256 if ($this->oauth->isAuthenticated())
259 if ($connection != null)
261 $path = $object .
'/' . $connection . $extra_fields;
265 $path = $object . $extra_fields;
269 $response = $this->oauth->query($this->fetchUrl($path), null, array(),
'delete');
271 return json_decode($response->body);
288 public function setOAuth($oauth)
290 $this->oauth = $oauth;
302 public function getOAuth()