Example #1
0
 /**
  * @return Response
  * @throws \Exception
  */
 public function send()
 {
     $this->xmlStr = self::generateXML();
     $ch = curl_init();
     //initiate the curl session
     curl_setopt($ch, CURLOPT_TIMEOUT, 40);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_URL, 'https://' . $this->ADRIPAddress . ":" . $this->ADRPort);
     //set to url to post to
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // tell curl to return data in a variable;
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, 'OrderXml=' . $this->xmlStr);
     // post the xml
     $xmlResponse = curl_exec($ch);
     if (!$xmlResponse) {
         throw new \Exception('Unable to connect to ADR: ' . curl_error($ch));
     }
     curl_close($ch);
     $response = new Response();
     $response->loadXML($xmlResponse);
     $response->parse();
     //Let's check for any errors
     if ($response->getError() != '0') {
         throw new \Exception('ADR ERROR: ' . $response->getError() . ' ' . $response->getErrorDescription() . PHP_EOL);
     }
     return $response;
 }
Example #2
0
 public function testSetError()
 {
     $response = new Response();
     $response->setError("DEFAULT_ERROR", "DEFAULT_ERROR_DETAIL");
     $error = $response->getError(true);
     $this->assertEquals('DEFAULT_ERROR', $error['error']);
     $this->assertEquals('DEFAULT_ERROR_DETAIL', $error["errorDetail"]);
 }
Example #3
0
 /**
  * Send the HTTP message.
  * 
  * @param $status int
  * @return array
  */
 public function send($status)
 {
     $context = stream_context_create($this->options);
     $body = @file_get_contents($this->url, false, $context);
     $http_response_header = isset($http_response_header) ? $http_response_header : array();
     $response = new Response($http_response_header, $body, $status);
     return array($response->getError(), $response);
 }
Example #4
0
 public function send($message = null, $attachments = null)
 {
     $config = $this->client->getConfig();
     $query = array_merge(array('text' => $message, 'channel' => $this->channel, 'attachments' => json_encode($attachments)), $config);
     $request = $this->client->request('chat.postMessage', $query)->send();
     $response = new Response($request);
     if ($this->client->debug) {
         if ($response->isOkay()) {
             //echo $this->client->config['username'].' ['.$this->channel.']: '.$message.PHP_EOL;
             return true;
         } else {
             echo '[Error] ' . $response->getError() . '.' . PHP_EOL;
             echo '[Query] ' . var_export($this->client->request('chat.postMessage', $query)->getQuery(), true);
             return false;
         }
     }
 }
 public function testCreateWithErrorCode()
 {
     $code = 403;
     $rawResult = '{"code":0,"message":""}';
     $response = new Response();
     $response->create($code, $rawResult);
     $this->assertFalse($response->isOk());
     $this->assertEquals($rawResult, $response->getRawResult());
     $error = $response->getError();
     $this->assertEquals('HTTP_CODE_ERROR', $error);
 }
 /**
  * (non-PHPdoc)
  * @see Response::getError()
  */
 public function getError()
 {
     return $this->response->getError();
 }
Example #7
0
 public function testGetError()
 {
     $error = array('test');
     $response = new Response(true, $error);
     $this->assertEquals($error, $response->getError());
 }
Example #8
0
 /**
  * Get the response. 
  * @throws ApiException
  * @return mixed JSON response
  */
 public function getResponse()
 {
     if ($this->status !== 200) {
         throw new \Exception('Something went wrong...  Status: ' . $this->status . ' Body: ' . $this->body);
     }
     $jsonRawResponse = json_decode($this->body, true);
     $jsonResponse = new Response($jsonRawResponse);
     if ($jsonResponse->getCode() !== 0) {
         throw new ApiException($jsonResponse->getError(), $jsonResponse->getContext(), $jsonResponse->getCode());
     }
     return $jsonResponse->getContext();
 }