Overview

Namespaces

  • Loco
    • Http
      • Response

Classes

  • ApiClient
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Loco\Http;
 4: 
 5: use Guzzle\Common\Collection;
 6: use Guzzle\Service\Client;
 7: use Guzzle\Service\Description\ServiceDescription;
 8: 
 9: /**
10:  * Loco REST API Client.
11:  * 
12:  * @usage $client = ApiClient::factory( array( 'key' => 'my-api-key' ) );
13:  */
14: class ApiClient extends Client {
15: 
16:     
17:     /**
18:      * Factory method to create a new Loco API client.
19:      * @param array|Collection $config Configuration data
20:      * @return ApiClient
21:      */
22:     public static function factory( $config = array() ){
23:        
24:         // Provide a hash of default client configuration options
25:         $default = array (
26:             'base_url' => 'https://localise.biz/api',
27:             'key' => '',
28:         );
29: 
30:         // No values are currently required when creating the client
31:         $required = array ();
32: 
33:         // Merge in default settings and validate the config
34:         $config = Collection::fromConfig( $config, $default, $required );
35:         
36:         // add common command parameters. They should only be appended when required
37:         $config->add( Client::COMMAND_PARAMS, array ( 
38:             'key' => $config->get('key'),
39:         ) );
40: 
41:         // Create a new instance of self
42:         $client = new self( $config->get('base_url'), $config );
43: 
44:         // describe service from included php file.
45:         $service = ServiceDescription::factory( __DIR__.'/Resources/service.php');
46:         
47:         // Prefix Loco identifier to user agent string
48:         $client->setUserAgent( $service->getName().'/'.$service->getApiVersion(), true );
49: 
50:         return $client->setDescription( $service );
51:                 
52:     }   
53: 
54: 
55:     /**
56:      * Get API version that service was built against.
57:      * @return string
58:      */
59:     public function getVersion(){
60:         return $this->getDescription()->getApiVersion();
61:     }
62: 
63: }
64: 
65: 
Loco SDK - PHP API documentation generated by ApiGen 2.8.0