示例#1
0
 public function testDisablesSubscribersWhenFalse()
 {
     $client = new Client();
     $description = new Description([]);
     $guzzle = new GuzzleClient($client, $description, ['validate' => false, 'process' => false]);
     $this->assertCount(1, $guzzle->getEmitter()->listeners('prepare'));
     $this->assertCount(0, $guzzle->getEmitter()->listeners('process'));
 }
示例#2
0
 /**
  * PhraseAppApiClient constructor.
  *
  * @param string      $token
  * @param string|null $serviceDescriptionPath
  *
  * @throws \Exception
  */
 public function __construct($token, $serviceDescriptionPath = null)
 {
     $serviceDescriptionPath = $serviceDescriptionPath ?: __DIR__ . '/../PhraseAppDescription.json';
     if (false === file_exists($serviceDescriptionPath)) {
         throw new \Exception('PhraseApp service descriptio file does not exists.');
     }
     $serviceDescription = json_decode(file_get_contents($serviceDescriptionPath), true);
     $client = new Client();
     $description = new Description($serviceDescription);
     $this->guzzleClient = new GuzzleClient($client, $description, ['defaults' => [], 'process' => false]);
     $this->guzzleClient->getEmitter()->attach(new ProcessResponse($description, ['link' => new LinkLocation('link')]));
     $this->token = $token;
 }
示例#3
0
 /**
  * Set custom guzzle subscriber (ie. History, mock, etc)
  *
  * @param SubscriberInterface $subscriber
  * @return static
  */
 public function setClientSubscriber(\GuzzleHttp\Event\SubscriberInterface $subscriber)
 {
     if (!$this->serviceClient) {
         $this->getBaseClient()->getEmitter()->attach($subscriber);
     } else {
         $this->serviceClient->getEmitter()->attach($subscriber);
     }
     return $this;
 }
示例#4
0
 public function createGuzzleClient(array $config)
 {
     $config = new Collection($config);
     $httpClient = new \GuzzleHttp\Client();
     $description = new Description($this->getDescription());
     $serializer = new Serializer($description, ['json_body' => new JsonBodyLocation('body')]);
     $client = new GuzzleClient($httpClient, $description, ['serializer' => $serializer]);
     $client->getEmitter()->attach(new Authorization($config->get('token'), $config->get('secret')));
     return $client;
 }
 public static function factory($apiKey, array $config = [])
 {
     $defaultConfig = ['defaults' => ['headers' => ['User-Agent' => 'php-kissmetrics-api/1.0.0 +https://github.com/ricbra/php-kissmetrics-api']]];
     $client = new Client(self::mergeRecursive($defaultConfig, $config));
     $service = (include __DIR__ . '/../../resources/service.php');
     $description = new Description($service);
     $client = new GuzzleClient($client, $description);
     // Inject key & convert bools to int so false doesnt get lost
     $client->getEmitter()->on('init', function (InitEvent $event) use($apiKey) {
         $command = $event->getCommand();
         $command['_k'] = $apiKey;
         foreach ($command->toArray() as $key => $value) {
             if (is_bool($value)) {
                 $command[$key] = (int) $value;
             }
         }
     }, 'first');
     return $client;
 }