Example #1
0
 public function get()
 {
     if (!is_null($this->id) && count($this->data) == 0) {
         $this->data = $this->client->call($this->getBaseUri());
     }
     return $this->data;
 }
Example #2
0
 /**
  * Get current data
  * @return array
  */
 public function get()
 {
     $uri = null;
     if ($this->context) {
         $uri = $this->context->getBaseUri() . '/';
     }
     $uri .= $this->params['endpoint'];
     $uri .= sprintf("?page=%d&perpage=%d", $this->page, $this->perpage);
     // add filter if value is not empty
     foreach ($this->filters as $filter) {
         if (!empty($filter['value'])) {
             $uri .= sprintf("&%s=%s", $filter['field'], rawurlencode($filter['value']));
         }
     }
     $res = $this->client->call($uri);
     // get and preserve pagination
     $lr = Client::getLastResponse();
     $this->pagination = isset($lr['body']) && isset($lr['body']['pagination']) ? $lr['body']['pagination'] : [];
     // convert array to Entities collection
     $this->data = [];
     foreach ($res as $data) {
         $this->data[] = (new Entity([], $this->client))->setData($data);
     }
     $this->current = 0;
     return $this->data;
 }
Example #3
0
 /**
  * Magic method for static calls
  * @param string $name
  * @param array $arguments
  * @return mixed
  */
 public static function __callstatic($name, $arguments)
 {
     // Get global services or entity services
     $services = Client::getServices(isset($arguments['context']) ? $arguments['context'] : null);
     if (array_key_exists($name, $services)) {
         $service = $services[$name];
         switch ($service['type']) {
             case 'collection':
                 return new Cursor($service, Client::getInstance(), isset($arguments['context']) ? $arguments['context'] : null);
                 break;
             case 'entity':
                 return new Entity($service, Client::getInstance(), isset($arguments[0]) ? $arguments[0] : null);
                 break;
                 // $name represents an action on an entity
             // $name represents an action on an entity
             case 'action':
                 return new Action($service, $arguments['context'], Client::getInstance());
                 break;
             default:
                 throw new \Exception("Don't know of any service type named '{$name}'");
                 break;
         }
     } else {
         throw new \Exception("can't find service definition for '{$name}'");
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     xAC::setApiKey(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_APIKEY'));
     xAC::setApiBaseUrl(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_URL'));
     xAC::setApiVersion(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_APIVERSION'));
     xAC::initServices(true);
     return printf("Services list has been refreshed \n");
 }
 /**
  * Register the service provider
  * @return XacAPI
  */
 public function register()
 {
     $this->app['arrowsphere.client'] = $this->app->share(function ($app) {
         //Set apiKey and baseUrl on client.
         xACClient::setApiKey(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_APIKEY'));
         xACClient::setApiBaseUrl(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_URL'));
         xACClient::setApiVersion(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_APIVERSION'));
         return xACClient::getInstance();
     });
     $this->app['command.arrowsphere.list'] = $this->app->share(function ($app) {
         return new servicesListCommand($app['config'], $app['files'], $app['view']);
     });
     $this->app['command.arrowsphere.refresh'] = $this->app->share(function ($app) {
         return new refreshListCommand($app['files']);
     });
     $this->commands('command.arrowsphere.list', 'command.arrowsphere.refresh');
     $this->app->bind('Arrowsphere\\Client\\xAC', 'arrowsphere.client');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     return xAC::getServicesList();
 }
Example #7
0
 public function testInstanceIsSingleton()
 {
     $this->assertEquals(xAC::getInstance(), $this->client);
 }