You are here

public function RequestBuilder::call in Auth0 Single Sign On 8.2

Return value

mixed|string

Throws

RequestException

File

vendor/auth0/auth0-php/src/API/Helpers/RequestBuilder.php, line 276

Class

RequestBuilder
Class RequestBuilder

Namespace

Auth0\SDK\API\Helpers

Code

public function call() {

  // Create a new Guzzle client.
  $client = new Client($this
    ->getGuzzleOptions());
  try {
    $data = [
      'headers' => $this->headers,
      'body' => $this->body,
    ];
    if (!empty($this->files)) {
      $data['multipart'] = $this
        ->buildMultiPart();
    }
    else {
      if (!empty($this->form_params)) {
        $data['form_params'] = $this->form_params;
      }
    }
    $response = $client
      ->request($this->method, $this
      ->getUrl(), $data);
    switch ($this->returnType) {
      case 'headers':
        return $response
          ->getHeaders();
      case 'object':
        return $response;
      case 'body':
      default:
        $body = (string) $response
          ->getBody();
        if (strpos($response
          ->getHeaderLine('content-type'), 'json') !== false) {
          return json_decode($body, true);
        }
        return $body;
    }
  } catch (RequestException $e) {
    throw $e;
  }
}