/**
  * Initializes the BeHat context for every scenario
  *
  * @param array $parameters Context parameters defined in behat.yml (default.context.parameters...)
  */
 public function __construct(array $parameters)
 {
     $this->client = new \Guzzle\Service\Client();
     $this->client->setDefaultOption('exceptions', false);
     // disable exceptions: we want to test error responses
     self::$parameters = $parameters;
     $this->restObj = new \stdClass();
 }
Example #2
0
 public function setSignature($path, $arr = array())
 {
     $nonce = time();
     $url = $this->apiBase . $path;
     $message = $nonce . $url . http_build_query($arr);
     $signature = hash_hmac("sha256", $message, $this->secretKey);
     $this->client->setDefaultOption('headers/ACCESS-NONCE', $nonce);
     $this->client->setDefaultOption('headers/ACCESS-SIGNATURE', $signature);
 }
Example #3
0
 /**
  * Authenticate to the API
  * 
  * @return boolean
  */
 private function logOnClient()
 {
     $logOnRequest = new LogOnRequest();
     $logOnRequest->UserName = $this->config->getUserName();
     $logOnRequest->Password = $this->config->getPassword();
     $LogOnResponse = $this->client->logOn($logOnRequest->jsonSerialize());
     if ($LogOnResponse->IsSuccess) {
         $this->setHeader('SecurityToken', $LogOnResponse->SecurityToken);
         $this->client->setDefaultOption('headers', $this->getHeaders());
         return true;
     } else {
         return false;
     }
 }
Example #4
0
 /**
  * Performs the API Call to PostMarkApp using GuzzlePHP
  *
  * @param $type
  *
  * @return string
  */
 private function execute($type)
 {
     $client = new Client($this->_api_url);
     $client->setDefaultOption("headers", array('X-Postmark-Server-Token' => $this->_credentials, 'Accept' => 'application/json', 'Content-Type' => ' application/json'));
     $url = "";
     switch ($type) {
         case "SEND":
             $url = $this->_api_send_url;
             break;
         case "BATCH":
             $url = $this->_api_batch_url;
     }
     $request = $client->post($url, null, json_encode($this->_send_object));
     return $request->send()->json();
 }
Example #5
0
 /**
  * Get guzzle client
  * @return Client
  */
 public function getClient()
 {
     if ($this->client instanceof Client) {
         return $this->client;
     }
     $client = new Client();
     $client->setDefaultOption('verify', false);
     return $client;
 }
 public function docUploadTestAction()
 {
     $client = new Client('https://lossync.sudoux.com/losService.svc', array('ssl.certificate_authority' => false));
     $client->setDefaultOption('auth', array('dan', 'letmein!789', 'Basic'));
     /*$user = array(
           'AuthUser' => array(
               'uri' => 'https://lossync.sudoux.com/losService.svc',
               'username' => 'dan',
               'password' =>
           ),
           'lostype' => 0,
           'apiKey' => 'AAKLPCALBX',
       );*/
     $filePath = $this->container->get('kernel')->getRootDir() . '/../web/fff.jpg';
     if (!is_file($filePath)) {
         $e = new \Exception('Local file not found');
         $this->logger->crit($e->getMessage());
         throw $e;
     }
     // first upload the file
     $params = array('file' => '@' . $filePath);
     //  $request = $client->post('uploadFile');
     // Set the body of the POST to stream the contents of /path/to/large_body.txt
     //    $request->setBody(fopen('/path/to/large_body.txt', 'r'));
     //   $response = $request->send();
     $request = $client->post('uploadFile');
     $request->setBody(fopen($filePath, 'r'));
     $response = $request->send();
     $data = $response->json();
 }
 public function setAcceptLanguage($value)
 {
     $this->client->setDefaultOption('headers/Accept-Language', $value);
 }
Example #8
0
 /**
  * @param string $keyOrPath
  * @param mixed  $value
  *
  * @return $this
  */
 public function setDefaultOption($keyOrPath, $value)
 {
     return parent::setDefaultOption($keyOrPath, $value);
 }