src/DivideIQ.php
public function request($serviceName, $payload = [], $method = 'GET')
    {
        // Setup the connection.
        $this->setup();

        $path = $this->settings->getPath($serviceName);

        switch ($method) {
            case 'GET':
                // Perform the request with the payload as a query string.
                $response = $this->client->get($path, [
                    'headers' => ['Authentication' => $this->accessToken->getToken()],
                    'query' => $payload,
                ]);

                break;
            case 'POST':
                $response = $this->client->post($path, [
                    'headers' => ['Authentication' => $this->accessToken->getToken()],
                    'json' => $payload,
                ]);

                break;
        }

        // Parse the response body.
        $json = json_decode($response->getBody());
        $body = $json->{'nl.divide.iq'};

        // Check if the settings object is outdated. If so, unset it.
        if ($this->settings->isOutdated($body->settings_updated)) {
            unset($this->settings);
        }

        // Check if there was an error.
        if (!isset($body->response->content)) {
            $message = $body->response->answer;
            $message .= isset($body->response->message) ? ": {$body->response->message}" : '';

            // Throw an exception with the error description from the service.
            throw new \Exception($message);
        }

        // Return only the response content, without the metadata.
        return $body->response->content;
    }
public function request($serviceName, $payload = [], $method = 'GET')
    {
        // Setup the connection.
        $this->setup();

        $path = $this->settings->getPath($serviceName);

        switch ($method) {
            case 'GET':
                // Perform the request with the payload as a query string.
                $response = $this->client->get($path, [
                    'headers' => ['Authentication' => $this->accessToken->getToken()],
                    'query' => $payload,
                ]);

                break;
            case 'POST':
                $response = $this->client->post($path, [
                    'headers' => ['Authentication' => $this->accessToken->getToken()],
                    'json' => $payload,
                ]);

                break;
        }

        // Parse the response body.
        $json = json_decode($response->getBody());
        $body = $json->{'nl.divide.iq'};

        // Check if the settings object is outdated. If so, unset it.
        if ($this->settings->isOutdated($body->settings_updated)) {
            unset($this->settings);
        }

        // Check if there was an error.
        if (!isset($body->response->content)) {
            $message = $body->response->answer;
            $message .= isset($body->response->message) ? ": {$body->response->message}" : '';

            // Throw an exception with the error description from the service.
            throw new \Exception($message);
        }

        // Return only the response content, without the metadata.
        return $body->response->content;
    }
public function request ( $ serviceName , $ payload = [ ] , $ method = 'GET' ) { // Setup the connection. $ this -> setup ( ) ; $ path = $ this -> settings -> getPath ( $ serviceName ) ; switch ( $ method ) { case 'GET' : // Perform the request with the payload as a query string. $ response = $ this -> client -> get ( $ path , [ 'headers' => [ 'Authentication' => $ this -> accessToken -> getToken ( ) ] , 'query' => $ payload , ] ) ; break ; case 'POST' : $ response = $ this -> client -> post ( $ path , [ 'headers' => [ 'Authentication' => $ this -> accessToken -> getToken ( ) ] , 'json' => $ payload , ] ) ; break ; } // Parse the response body. $ json = json_decode ( $ response -> getBody ( ) ) ; $ body = $ json -> { 'nl.divide.iq' } ; // Check if the settings object is outdated. If so, unset it. if ( $ this -> settings -> isOutdated ( $ body -> settings_updated ) ) { unset ( $ this -> settings ) ; } // Check if there was an error. if ( ! isset ( $ body -> response -> content ) ) { $ message = $ body -> response -> answer ; $ message .= isset ( $ body -> response -> message ) ? ": {$body->response->message}" : '' ; // Throw an exception with the error description from the service. throw new \ Exception ( $ message ) ; } // Return only the response content, without the metadata. return $ body -> response -> content ; }
Accesses a service provided by Divide.IQ using the stored access token.

@param string $serviceName
The codename of the service to access.
@param array $payload
(optional) The data to send with the request.
@param string $method
(optional) The HTTP method to use to access the service. Defaults to
`GET`.

@see http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
Accesses a service provided by Divide . IQ using the stored access token .