コード例 #1
0
 /**
  * test getParametersForSignature
  *
  * @param string $operation
  * @param array  $params
  * @param array  $expectedSignatureParams
  *
  * @dataProvider dataGetParametersForSignature
  */
 public function testGetParametersForSignature($operation, $params, $expectedSignatureParams)
 {
     $description = new Description(json_decode(file_get_contents(__DIR__ . '/../Data/service.json'), true));
     //$client = new GuzzleClient(new Client(), $description);
     $operation = $description->getOperation($operation);
     $method = new \ReflectionMethod('Wk\\AmazonMwsApi\\Services\\MwsConnection', 'getParametersForSignature');
     $method->setAccessible(true);
     $args = array($operation, $params);
     $this->assertEquals($expectedSignatureParams, $method->invokeArgs($this->mwsConnection, $args));
 }
コード例 #2
0
 /**
  * Run a value through the filters OR format attribute associated with the
  * parameter.
  *
  * @param mixed $value Value to filter
  *
  * @return mixed Returns the filtered value
  * @throws \RuntimeException when trying to format when no service
  *     description is available.
  */
 public function filter($value)
 {
     // Formats are applied exclusively and supersed filters
     if ($this->format) {
         if (!$this->serviceDescription) {
             throw new \RuntimeException('No service description was set so ' . 'the value cannot be formatted.');
         }
         return $this->serviceDescription->format($this->format, $value);
     }
     // Convert Boolean values
     if ($this->type == 'boolean' && !is_bool($value)) {
         $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
     }
     // Apply filters to the value
     if ($this->filters) {
         foreach ($this->filters as $filter) {
             if (is_array($filter)) {
                 // Convert complex filters that hold value place holders
                 foreach ($filter['args'] as &$data) {
                     if ($data == '@value') {
                         $data = $value;
                     } elseif ($data == '@api') {
                         $data = $this;
                     }
                 }
                 $value = call_user_func_array($filter['method'], $filter['args']);
             } else {
                 $value = call_user_func($filter, $value);
             }
         }
     }
     return $value;
 }
コード例 #3
0
ファイル: GuzzleClient.php プロジェクト: daskleinesys/slimpd
 /**
  * Creates a callable function used to create command objects from a
  * service description.
  *
  * @param Description $description Service description
  *
  * @return callable Returns a command factory
  */
 public static function defaultCommandFactory(Description $description)
 {
     return function ($name, array $args = [], GuzzleClientInterface $client) use($description) {
         $operation = null;
         if ($description->hasOperation($name)) {
             $operation = $description->getOperation($name);
         } else {
             $name = ucfirst($name);
             if ($description->hasOperation($name)) {
                 $operation = $description->getOperation($name);
             }
         }
         if (!$operation) {
             return null;
         }
         return new Command($operation, $args, clone $client->getEmitter());
     };
 }
コード例 #4
0
ファイル: Operation.php プロジェクト: bobozhangshao/HeartCare
 private function resolveExtends($name, array $config)
 {
     if (!$this->description->hasOperation($name)) {
         throw new \InvalidArgumentException('No operation named ' . $name);
     }
     // Merge parameters together one level deep
     $base = $this->description->getOperation($name)->toArray();
     $result = $config + $base;
     if (isset($base['parameters']) && isset($config['parameters'])) {
         $result['parameters'] = $config['parameters'] + $base['parameters'];
     }
     return $result;
 }
コード例 #5
0
 /**
  * Resolves the API service description for usage.
  *
  * @throws InvalidDescriptionException
  */
 private function resolveApiDescription()
 {
     $resolveByClassNameAttempted = false;
     while (!$this->apiDescription instanceof AbstractApiDescription) {
         if ($resolveByClassNameAttempted) {
             $error = is_null($this->apiDescription) ? 'No API service description found' : 'Malformed API service description';
             throw new InvalidDescriptionException($error);
         }
         $resolveByClassNameAttempted = true;
         if (class_exists($this->apiDescription) && is_subclass_of($this->apiDescription, AbstractApiDescription::class)) {
             $this->apiDescription = new $this->apiDescription([]);
         }
     }
     return $this->apiDescription = $this->apiDescription->load();
 }
コード例 #6
0
 public function testCanExtendFromOtherOperations()
 {
     $d = new Description(['operations' => ['A' => ['parameters' => ['A' => ['type' => 'object', 'properties' => ['foo' => ['type' => 'string']]], 'B' => ['type' => 'string']], 'summary' => 'foo'], 'B' => ['extends' => 'A', 'summary' => 'Bar'], 'C' => ['extends' => 'B', 'summary' => 'Bar', 'parameters' => ['B' => ['type' => 'number']]]]]);
     $a = $d->getOperation('A');
     $this->assertEquals('foo', $a->getSummary());
     $this->assertTrue($a->hasParam('A'));
     $this->assertEquals('string', $a->getParam('B')->getType());
     $b = $d->getOperation('B');
     $this->assertTrue($a->hasParam('A'));
     $this->assertEquals('Bar', $b->getSummary());
     $this->assertEquals('string', $a->getParam('B')->getType());
     $c = $d->getOperation('C');
     $this->assertTrue($a->hasParam('A'));
     $this->assertEquals('Bar', $c->getSummary());
     $this->assertEquals('number', $c->getParam('B')->getType());
 }
コード例 #7
0
 public function testCanUseCustomFormatter()
 {
     $formatter = $this->getMockBuilder('GuzzleHttp\\Common\\Guzzle\\SchemaFormatter')->setMethods(['format'])->getMock();
     $formatter->expects($this->once())->method('format');
     $s = new Description([], ['formatter' => $formatter]);
     $s->format('time', 'now');
 }
コード例 #8
0
 /**
  * @param array $options Custom options to apply to the description
  *     - formatter: Can provide a custom SchemaFormatter class
  */
 public function __construct(array $options = [])
 {
     parent::__construct(['name' => 'prostor-sms.ru API', 'baseUrl' => 'http://api.prostor-sms.ru', 'operations' => ['version' => ['httpMethod' => 'GET', 'uri' => '/messages/v2/version/', 'description' => 'Проверка активной версии API. При успешной авторизации, в ответ сервис должен вернуть plain/text ответ вида: "2", где выводится номер активной версии API', 'responseModel' => 'getResponse'], 'balance' => ['httpMethod' => 'GET', 'uri' => '/messages/v2/balance/', 'description' => 'Проверка состояния счета. При успешной авторизации, в ответ сервис должен вернуть plain/text ответ вида: "RUB;540.15;0.0\\nSMS;589;100", где в каждой строке 1 значение – тип баланса, 2 значение – баланс, 3 значение – кредит (возможность использовать сервис при отрицательномбалансе)', 'responseModel' => 'getResponse'], 'send' => ['httpMethod' => 'GET', 'uri' => '/messages/v2/send/', 'description' => 'Передача сообщения. При успешной авторизации, в ответ сервис должен вернуть plain/text ответ вида accepted;A132571BC', 'responseModel' => 'getResponse', 'parameters' => ['statusQueueName' => ['type' => 'string', 'location' => 'json', 'required' => false, 'min' => 3, 'max' => 16, 'description' => 'Название очереди статусов отправленных сообщений, в случае, если вы хотите использовать очередь статусов отправленных сообщений. От 3 до 16 символов, буквы и цифры (например myQueue1)'], 'scheduleTime' => ['type' => 'string', 'location' => 'json', 'required' => false, 'description' => 'Дата для отложенной отправки сообщения, в UTC (2008-07-12T14:30:01Z)'], 'messages' => ['type' => 'array', 'location' => 'json', 'required' => true, 'items' => ['clientId' => ['type' => 'string', 'location' => 'json', 'required' => true, 'description' => 'ID в вашей системе'], 'phone' => ['type' => 'string', 'location' => 'json', 'required' => true, 'description' => 'Номер телефона, в формате +71234567890'], 'text' => ['type' => 'string', 'location' => 'json', 'required' => true, 'description' => 'Текст сообщения, в UTF-8 кодировке'], 'sender' => ['type' => 'string', 'location' => 'json', 'required' => false, 'description' => 'Подпись отправителя (например TEST)']]]]]], 'models' => ['getResponse' => ['type' => 'object', 'properties' => ['additionalProperties' => ['location' => 'body']]]]], $options);
 }
コード例 #9
0
 public function __construct(array $config, array $options = [])
 {
     $config = $this->normalizeConfig($config);
     parent::__construct($config, $options);
 }
コード例 #10
0
ファイル: MaibDecription.php プロジェクト: slavic18/MaibAPI
 /**
  * @param array $options Custom options to apply to the description
  *     - formatter: Can provide a custom SchemaFormatter class
  */
 public function __construct(array $options = [])
 {
     parent::__construct(['name' => 'Maib API', 'operations' => ['registerSmsTransaction' => ['httpMethod' => 'POST', 'uri' => '/ecomm2/MerchantHandler', 'description' => 'identifies the request for register SMS transaction', 'responseModel' => 'getResponse', 'parameters' => ['command' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'amount' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'currency' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'client_ip_addr' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 15], 'description' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 125], 'language' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 32]]], 'registerDmsAuthorization' => ['httpMethod' => 'POST', 'uri' => '/ecomm2/MerchantHandler', 'description' => 'identifies the request for register DMS transaction', 'responseModel' => 'getResponse', 'parameters' => ['command' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'amount' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 12], 'currency' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 3], 'client_ip_addr' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 15], 'description' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 125], 'language' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 32]]], 'makeDMSTrans' => ['httpMethod' => 'POST', 'uri' => '/ecomm2/MerchantHandler', 'description' => 'identifies the request for execute DMS transaction', 'responseModel' => 'getResponse', 'parameters' => ['command' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'auth_id' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'amount' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 12], 'currency' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 3], 'client_ip_addr' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 15], 'description' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 125], 'language' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 32]]], 'getTransactionResult' => ['httpMethod' => 'POST', 'uri' => '/ecomm2/MerchantHandler', 'description' => 'identifies the request for get transaction result', 'responseModel' => 'getResponse', 'parameters' => ['command' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'trans_id' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'client_ip_addr' => ['type' => 'string', 'location' => 'postField', 'required' => true, 'max' => 15]]], 'revertTransaction' => ['httpMethod' => 'POST', 'uri' => '/ecomm2/MerchantHandler', 'description' => 'identifies the request for revert transaction', 'responseModel' => 'getResponse', 'parameters' => ['command' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'trans_id' => ['type' => 'string', 'location' => 'postField', 'required' => true], 'amount ' => ['type' => 'string', 'location' => 'postField', 'required' => false, 'max' => 12]]], 'closeDay' => ['httpMethod' => 'POST', 'uri' => '/ecomm2/MerchantHandler', 'description' => 'End of business day', 'responseModel' => 'getResponse', 'parameters' => ['command' => ['type' => 'string', 'location' => 'postField', 'required' => true]]]], 'models' => ['getResponse' => ['type' => 'object', 'properties' => ['additionalProperties' => ['location' => 'body']]]]], $options);
 }
コード例 #11
0
 /**
  * @param string $baseUrl
  */
 public function __construct($baseUrl = 'http://api.viewranger.com/public/v1/')
 {
     parent::__construct(['baseUrl' => $baseUrl, 'operations' => ['getLastBBPosition' => ['httpMethod' => 'GET', 'responseModel' => 'getResponse', 'parameters' => ['service' => ['required' => true, 'static' => true, 'name' => 'service', 'default' => 'getLastBBPosition', 'location' => 'query'], 'username' => ['type' => 'string', 'required' => true, 'location' => 'query'], 'pin' => ['required' => true, 'type' => 'integer', 'location' => 'query']]], 'getBBPositions' => ['httpMethod' => 'GET', 'responseModel' => 'getResponse', 'parameters' => ['service' => ['required' => true, 'static' => true, 'name' => 'service', 'default' => 'getBBPositions', 'location' => 'query'], 'username' => ['required' => true, 'type' => 'string', 'location' => 'query'], 'pin' => ['required' => true, 'type' => 'integer', 'location' => 'query'], 'date_from' => ['type' => 'string', 'location' => 'query'], 'date_until' => ['type' => 'string', 'location' => 'query'], 'limit' => ['type' => 'integer', 'location' => 'query']]]], 'models' => ['getResponse' => ['type' => 'object', 'additionalProperties' => ['location' => 'json']]]]);
 }
コード例 #12
0
 public function __construct($baseUrl = 'http://vindinium.org/', array $options = [])
 {
     parent::__construct(array_merge(['baseUrl' => $baseUrl], $this->toArray()), $options);
 }