/**
  * Requests a list of or specific resource
  *
  * @param string     $resource The resource to retrieve
  * @param mixed|null $id       An id to append to the resource request
  *
  * @return array|bool|\stdClass
  */
 public function resource($resource, $id = null)
 {
     try {
         $_response = (array) $this->get(Uri::segment([$resource, $id]));
         return array_get($_response, 'resource', false);
     } catch (\Exception $_ex) {
         $this->error('[dfe.instance-api-client] resource() call failure from instance "' . $this->instance->instance_id_text . '": ' . $_ex->getMessage(), Curl::getInfo());
         return [];
     }
 }
 /**
  * Makes a shout out to an instance's private back-end. Should be called bootyCall()  ;)
  *
  * @param string $uri     The REST uri (i.e. "/[rest|api][/v[1|2]]/db", "/rest/system/users", etc.) to retrieve
  *                        from the instance
  * @param array  $payload Any payload to send with request
  * @param array  $options Any options to pass to transport layer
  * @param string $method  The HTTP method. Defaults to "POST"
  *
  * @return array|bool|\stdClass
  */
 public function call($uri, $payload = [], $options = [], $method = Request::METHOD_POST)
 {
     $options[CURLOPT_HTTPHEADER] = array_merge(array_get($options, CURLOPT_HTTPHEADER, []), [EnterpriseDefaults::CONSOLE_X_HEADER . ': ' . $this->token]);
     try {
         $_response = Curl::request($method, Uri::segment([$this->resourceUri, $uri], false), $payload, $options);
     } catch (\Exception $_ex) {
         return false;
     }
     return $_response;
 }
Пример #3
0
 /**
  * Makes a shout out to an instance's private back-end. Should be called bootyCall()  ;)
  *
  * @param string $uri     The REST uri (i.e. "/[rest|api][/v[1|2]]/db", "/rest/system/users", etc.) to retrieve from the instance
  * @param array  $payload Any payload to send with request
  * @param array  $options Any options to pass to transport layer
  * @param string $method  The HTTP method. Defaults to "POST"
  * @param bool   $object  If true, the default, the response is returned as an object. If false, an array is returned.
  *
  * @return array|bool|\stdClass
  */
 public function call($uri, $payload = [], $options = [], $method = Request::METHOD_POST, $object = true)
 {
     $_token = $this->generateToken();
     $options['headers'] = array_merge(array_get($options, 'headers', []), [EnterpriseDefaults::CONSOLE_X_HEADER => $_token, 'Content-Type' => 'application/json', 'Accept' => 'application/json']);
     try {
         return $this->guzzleAny(Uri::segment([$this->getProvisionedEndpoint(), $uri], false), $payload, $options, $method, $object);
     } catch (\Exception $_ex) {
         return false;
     }
 }