Overview

Namespaces

  • Comprobo
    • Verify
      • Auth
      • Exceptions
      • HTTP

Classes

  • Comprobo\Verify\Api
  • Comprobo\Verify\Auth\Server
  • Comprobo\Verify\Factory
  • Comprobo\Verify\HTTP\Request
  • Comprobo\Verify\State
  • Comprobo\Verify\User
  • Comprobo\Verify\Workflow

Exceptions

  • Comprobo\Verify\Exceptions\Auth
  • Comprobo\Verify\Exceptions\Misconfiguration
  • Comprobo\Verify\Exceptions\Upload
  • Comprobo\Verify\Exceptions\User
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 
<?php
namespace Comprobo\Verify\HTTP;

/**
 * A thin wrapper around Guzzle with convenience methods for signing outgoing requests.
 *
 * Internal use only, subject to change
 */
class Request
{
    private $request;
    private $token;

    public function __construct()
    {
        $this->request = new \GuzzleHttp\Client(['timeout' => 20.0, 'connect_timeout' => 20.0, 'http_errors' => false]);
    }

    public function __call($method, $args)
    {
        $methodName = strtolower($method);
        if ($methodName === 'get' || $methodName === 'post' || $methodName === 'put' || $methodName === 'patch') {
            $options = isset($args[1]) ? $args[1] : [];
            $args[1] = $this->mungeOptions($options);
        }
        if ($methodName === 'request') {
            $options = isset($args[2]) ? $args[2] : [];
            $args[2] = $this->mungeOptions($options);
        }

        return call_user_func_array([$this->request, $method], $args);
    }

    /**
     * AmericaniZed spelling because why not.
     *
     * @param  string $token an access token for Comprobo systems
     * @return self
     */
    public function authorize($token)
    {
        $this->token = $token;
        return $this;
    }

    private function mungeOptions($options)
    {
        $options['headers'] = isset($options['headers']) ? $options['headers'] : [];
        if (!array_key_exists('Accept', $options['headers'])) {
            $options['headers']['Accept'] = 'application/json';
        }

        if ($this->token && !array_key_exists('Authorization', $options['headers'])) {
            $options['headers']['Authorization'] = 'Bearer ' . $this->token;
        }

        return $options;
    }
}
API documentation generated by ApiGen