Ejemplo n.º 1
0
 /**
  * Call the API.
  *
  * On success (HTTP status == 200) $this->error_code and $this->error_msg will be false.
  * On failure (HTTP status != 200) $this->error_code and $this->error_msg will contain error information.
  *
  * On success or failure,  $this->response will contain the response captured by HTTP agent
  * except when username and password are not passed as part of auth.
  *
  * @return object|RESTian_Response
  */
 function make_request()
 {
     $response = new RESTian_Response(array('request' => $this));
     $api = $this->client;
     /**
      * Assign request & response to API so they are accessible inside the auth_provider
      */
     $api->request = $this;
     $api->response = $response;
     $auth_provider = $api->get_auth_provider();
     if ($this->needs_authentication() && !$this->has_authentication()) {
         $response->set_error('NO_AUTH', $this->service);
     } else {
         $http_agent = RESTian::get_new_http_agent($this->client->http_agent);
         $this->assign_settings();
         $response = $http_agent->make_request($this, $response);
         if ($response->is_http_error()) {
             /**
              * See if we can provide more than one error type here.
              */
             $msg = 'There was a problem reaching %s when calling the %s. Please try again later or contact the site\'s administrator.';
             $response->set_error('API_FAIL', sprintf($msg, $this->client->api_name, $this->service->service_name));
         } else {
             if ('authenticate' == $response->request->service->service_name) {
                 $handled = $auth_provider->authenticated($response);
             } else {
                 $handled = $auth_provider->handle_response($response);
             }
             if (!$handled) {
                 // @todo Add more HTTP status code responses as we better understand the use-cases.
                 switch ($response->status_code) {
                     case '200':
                         /**
                          * @var RESTian_Parser_Base $parser
                          */
                         $parser = RESTian::get_new_parser($this->service->content_type, $this, $response);
                         if ($parser instanceof RESTian_Parser_Base) {
                             $response->data = $parser->parse($response->body);
                         }
                         break;
                     case '401':
                         $response->set_error('BAD_AUTH', $this->service);
                         break;
                     default:
                         /**
                          * See if we can provide more than one error type here.
                          */
                         $response->set_error('UNKNOWN', 'Unexpected API response code: ' . $response->status_code);
                         break;
                 }
             }
             if ($this->omit_body) {
                 $response->body = null;
             }
             if ($this->omit_result) {
                 $response->result = null;
             }
         }
     }
     return $response;
 }
Ejemplo n.º 2
0
<?php

/**
 * Used by PhpStorm to map factory methods to classes for code completion, source code analysis, etc.
 *
 * The code is not ever actually executed and it only needed during development when coding with PhpStorm.
 *
 * @see http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
 * @see http://blog.jetbrains.com/webide/2013/04/phpstorm-6-0-1-eap-build-129-177/
 */
namespace PHPSTORM_META;

/** @noinspection PhpUnusedLocalVariableInspection */
/** @noinspection PhpIllegalArrayKeyTypeInspection */
$STATIC_METHOD_TYPES = array(\RESTian::get_new_parser('', null, null) => array('application/xml' instanceof \RESTian_Application_Xml_Parser, 'application/json' instanceof \RESTian_Application_Json_Parser, 'text/plain' instanceof \RESTian_Text_Plain_Parser, 'text/html' instanceof \RESTian_Text_Html_Parser, 'text/csv' instanceof \RESTian_Text_Csv_Parser, 'application/vnd.php.serialized' instanceof \RESTian_Application_Serialized_Php_Parser), \RESTian::get_new_auth_provider('') => array('n/a' instanceof \RESTian_Not_Applicable_Provider, 'basic_http' instanceof \RESTian_Basic_Http_Auth_Provider), \RESTian::get_new_http_agent('') => array('wordpress' instanceof \RESTian_WordPress_Http_Agent, 'php_curl' instanceof \RESTian_Php_Curl_Http_Agent));