/**
  * Internal method to make a general API request based on the provided options
  * @param $call_options
  * @access private
  */
 function _call($call_options, $method, $route, $data = NULL)
 {
     $call_options['route'] = $route;
     $call_options['method'] = $method;
     if (!is_null($data)) {
         $call_options['data'] = $this->_serialiser->serialise($data);
     }
     $call_options = array_merge($this->_default_call_options, $call_options);
     $this->_log->log_message('Making ' . $call_options['method'] . ' call to: ' . $call_options['route'], get_class($this), CS_REST_LOG_WARNING);
     $call_result = $this->_transport->make_call($call_options);
     $this->_log->log_message('Call result: <pre>' . var_export($call_result, true) . '</pre>', get_class($this), CS_REST_LOG_VERBOSE);
     if ($call_options['deserialise']) {
         $call_result['response'] = $this->_serialiser->deserialise($call_result['response']);
     }
     return new CS_REST_Wrapper_Result($call_result['response'], $call_result['code']);
 }
示例#2
0
 /**
  * Constructor.
  * @param $auth_details array Authentication details to use for API calls.
  *        This array must take one of the following forms:
  *        If using OAuth to authenticate:
  *        array(
  *          'access_token' => 'your access token',
  *          'refresh_token' => 'your refresh token')
  *
  *        Or if using an API key:
  *        array('api_key' => 'your api key')
  *
  *        Note that this method will continue to work in the deprecated
  *        case when $auth_details is passed in as a string containing an
  *        API key.
  * @param $protocol string The protocol to use for requests (http|https)
  * @param $debug_level int The level of debugging required CS_REST_LOG_NONE | CS_REST_LOG_ERROR | CS_REST_LOG_WARNING | CS_REST_LOG_VERBOSE
  * @param $host string The host to send API requests to. There is no need to change this
  * @param $log CS_REST_Log The logger to use. Used for dependency injection
  * @param $serialiser The serialiser to use. Used for dependency injection
  * @param $transport The transport to use. Used for dependency injection
  * @access public
  */
 function CS_REST_Wrapper_Base($auth_details, $protocol = 'https', $debug_level = CS_REST_LOG_NONE, $host = CS_HOST, $log = NULL, $serialiser = NULL, $transport = NULL)
 {
     if (is_string($auth_details)) {
         # If $auth_details is a string, assume it is an API key
         $auth_details = array('api_key' => $auth_details);
     }
     $this->_log = is_null($log) ? new CS_REST_Log($debug_level) : $log;
     $this->_protocol = $protocol;
     $this->_base_route = $protocol . '://' . $host . '/api/v3.1/';
     $this->_log->log_message('Creating wrapper for ' . $this->_base_route, get_class($this), CS_REST_LOG_VERBOSE);
     $this->_transport = is_null($transport) ? CS_REST_TRANSPORT_get_available($this->is_secure(), $this->_log) : $transport;
     $transport_type = method_exists($this->_transport, 'get_type') ? $this->_transport->get_type() : 'Unknown';
     $this->_log->log_message('Using ' . $transport_type . ' for transport', get_class($this), CS_REST_LOG_WARNING);
     $this->_serialiser = is_null($serialiser) ? CS_REST_SERIALISATION_get_available($this->_log) : $serialiser;
     $this->_log->log_message('Using ' . $this->_serialiser->get_type() . ' json serialising', get_class($this), CS_REST_LOG_WARNING);
     $this->_default_call_options = array('authdetails' => $auth_details, 'userAgent' => 'CS_REST_Wrapper v' . CS_REST_WRAPPER_VERSION . ' PHPv' . phpversion() . ' over ' . $transport_type . ' with ' . $this->_serialiser->get_type(), 'contentType' => 'application/json; charset=utf-8', 'deserialise' => true, 'host' => $host, 'protocol' => $protocol);
 }