Exemplo n.º 1
0
 /**
  * @param Application $app
  * @param $endpoint
  * @param null $api
  * @throws \XeroPHP\Exception
  */
 public function __construct(Application $app, $endpoint, $api = null)
 {
     //Handle full URLs and pull them back apart.
     //Annoying internal references are http??? and absolute.
     if (strpos($endpoint, 'http') === 0) {
         if (preg_match('@^http(s)?://[^/]+/(?<api>[^/]+)/(?<version>[^/]+)/(?<endpoint>.+)$@i', $endpoint, $matches)) {
             $endpoint = $matches['endpoint'];
             $api = $matches['api'];
             //$version = $matches['version'];
         }
     }
     if ($api === null) {
         //Assume that it's an OAuth endpoint if no API is given.
         //If this becomes an issue it can just check every time, but it seems a little redundant
         $oauth_endpoints = $app->getConfig('oauth');
         $this->is_oauth = false;
         switch ($endpoint) {
             case self::OAUTH_REQUEST_TOKEN:
                 $this->path = $oauth_endpoints['request_token_path'];
                 $this->is_oauth = true;
                 break;
             case self::OAUTH_ACCESS_TOKEN:
                 $this->path = $oauth_endpoints['access_token_path'];
                 $this->is_oauth = true;
                 break;
             default:
                 //default to core API for backward compatibility
                 $api = self::API_CORE;
         }
     }
     //This contains API versions and base URLs
     $xero_config = $app->getConfig('xero');
     $this->base_url = $xero_config['base_url'];
     $this->endpoint = $endpoint;
     //Check here that the URI hasn't been set by one of the OAuth methods and handle as normal
     if (!isset($this->path)) {
         switch ($api) {
             case self::API_CORE:
                 $version = $xero_config['core_version'];
                 break;
             case self::API_PAYROLL:
                 $version = $xero_config['payroll_version'];
                 break;
             case self::API_FILE:
                 $version = $xero_config['file_version'];
                 break;
             default:
                 throw new Exception('Invalid API passed to XeroPHP\\URL::__construct(). Must be XeroPHP\\URL::API_*');
         }
         $this->path = sprintf('%s/%s/%s', $api, $version, $this->endpoint);
     }
 }
Exemplo n.º 2
0
 /**
  * Shorthand delete an object if it is instantiated with app context.
  *
  * @return Response|null
  * @throws Exception
  */
 public function delete()
 {
     if ($this->_application === null) {
         throw new Exception('->delete() is only available on objects that have an injected application context.');
     }
     return $this->_application->delete($this);
 }
Exemplo n.º 3
0
 /**
  * @param string $class
  * @return $this
  */
 public function from($class)
 {
     $this->from = $this->app->validateModelClass($class);
     return $this;
 }
Exemplo n.º 4
0
 public function __construct($config)
 {
     //As we don't need to Authorize/RequestToken, it's populated here.
     $config['oauth']['token'] = $config['oauth']['consumer_key'];
     parent::__construct($config);
 }
Exemplo n.º 5
0
 public function testGetAuthorizeURL()
 {
     $expectedUrl = $this->application->getOAuthClient()->getAuthorizeURL();
     $this->assertEquals($expectedUrl, $this->application->getAuthorizeURL());
     $this->assertEquals($expectedUrl . '?oauth_token=test', $this->application->getAuthorizeURL('test'));
 }