Exemplo n.º 1
0
 public function create_scan_form($params = null)
 {
     $requestor = new Requestor($this->_apiKey);
     $url = $this->instanceUrl() . '/scan_form';
     list($response, $apiKey) = $requestor->request('post', $url, $params);
     return Util::convertToEasyPostObject($response, $apiKey);
 }
Exemplo n.º 2
0
 /**
  * retrieve item reference
  *
  * @param mixed  $params
  * @param string $apiKey
  * @return array
  */
 public static function retrieve_reference($params = null, $apiKey = null)
 {
     $class = get_class();
     $requestor = new Requestor($apiKey);
     $url = self::classUrl($class);
     list($response, $apiKey) = $requestor->request('get', $url . '/retrieve_reference', $params);
     return Util::convertToEasyPostObject($response, $apiKey);
 }
Exemplo n.º 3
0
 /**
  * cancel a pickup
  *
  * @param mixed $params
  * @return $this
  * @throws \EasyPost\Error
  */
 public function cancel($params = null)
 {
     $requestor = new Requestor($this->_apiKey);
     $url = $this->instanceUrl() . '/cancel';
     list($response, $apiKey) = $requestor->request('post', $url, $params);
     $this->refreshFrom($response, $apiKey, true);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * create a list of trackers
  *
  * @param mixed  $params
  * @param string $apiKey
  * @return mixed
  */
 public static function create_list($params = null, $apiKey = null)
 {
     $class = get_class();
     if (!isset($params['trackers']) || !is_array($params['trackers'])) {
         $clone = $params;
         unset($params);
         $params['trackers'] = $clone;
     }
     $requestor = new Requestor($apiKey);
     $url = self::classUrl($class);
     list($response, $apiKey) = $requestor->request('post', $url . '/create_list', $params);
 }
Exemplo n.º 5
0
 public function buy($params = null)
 {
     $requestor = new Requestor($this->_apiKey);
     $url = $this->instanceUrl() . '/buy';
     if ($params instanceof Rate) {
         $clone = $params;
         unset($params);
         $params['carrier'] = $clone->carrier;
         $params['service'] = $clone->service;
     }
     list($response, $apiKey) = $requestor->request('post', $url, $params);
     $this->refreshFrom($response, $apiKey, false);
     return $this;
 }
Exemplo n.º 6
0
 public function verify($params = null)
 {
     $requestor = new Requestor($this->_apiKey);
     $url = $this->instanceUrl() . '/verify';
     list($response, $apiKey) = $requestor->request('get', $url, $params);
     if (isset($response['address'])) {
         $verified_address = Util::convertToEasyPostObject($response['address'], $apiKey);
         if (!empty($response['message'])) {
             $verified_address->message = $response['message'];
             $verified_address->_immutableValues[] = 'message';
         }
         return $verified_address;
     } else {
         return Util::convertToEasyPostObject($response, $apiKey);
     }
 }
Exemplo n.º 7
0
 protected function _delete($class, $params = null)
 {
     self::_validate('delete');
     $requestor = new Requestor($this->_apiKey);
     $url = $this->instanceUrl();
     list($response, $apiKey) = $requestor->request('delete', $url, $params);
     $this->refreshFrom($response, $apiKey);
     return $this;
 }
Exemplo n.º 8
0
 /**
  * insure the shipment
  *
  * @param mixed $params
  * @return $this
  * @throws \EasyPost\Error
  */
 public function insure($params = null)
 {
     $requestor = new Requestor($this->_apiKey);
     $url = $this->instanceUrl() . '/insure';
     if (!isset($params['amount'])) {
         $clone = $params;
         unset($params);
         $params['amount'] = $clone;
     }
     list($response, $apiKey) = $requestor->request('post', $url, $params);
     $this->refreshFrom($response, $apiKey);
     return $this;
 }
Exemplo n.º 9
0
 /**
  * get types of carrier account
  *
  * @param mixed  $params
  * @param string $apiKey
  * @return mixed
  */
 public static function types($params = null, $apiKey = null)
 {
     $requestor = new Requestor($apiKey);
     list($response, $apiKey) = $requestor->request('get', '/carrier_types', $params);
     return Util::convertToEasyPostObject($response, $apiKey);
 }
Exemplo n.º 10
0
 public function testRequestResponseException()
 {
     $server = new TestServer(new TestProtocolResponder(AvroProtocol::parse($this->protocol)));
     $client = TestTransceiver::getTestClient($server);
     $requestor = new Requestor(AvroProtocol::parse($this->protocol), $client);
     $exception_raised = false;
     try {
         $response = $requestor->request('testRequestResponseException', array("exception" => array("cause" => "callback")));
     } catch (AvroRemoteException $e) {
         $exception_raised = true;
         $exception_datum = $e->getDatum();
         $this->assertEquals("raised on callback cause", $exception_datum["exception"]);
     }
     $this->assertTrue($exception_raised);
     $exception_raised = false;
     try {
         $response = $requestor->request('testRequestResponseException', array("exception" => array("cause" => "system")));
     } catch (AvroRemoteException $e) {
         $exception_raised = true;
         $exception_datum = $e->getDatum();
         $this->assertEquals("System exception", $exception_datum);
     }
     $this->assertTrue($exception_raised);
 }
Exemplo n.º 11
0
     "testNotification": {
         "doc" : "Notification : one-way message",
         "request": [{"name": "notification", "type": "Notification"}],
         "one-way": true
     },
     "testRequestResponseException": {
         "doc" : "Request Response with Exception",
         "request": [{"name": "exception", "type": "RaiseException"}],
         "response" : "NeverSend",
         "errors" : ["AlwaysRaised"]
     }
 }
}
PROTO;
$client = NettyFramedSocketTransceiver::create('127.0.0.1', 1411);
$requestor = new Requestor(AvroProtocol::parse($protocol), $client);
try {
    $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "pong")));
    echo "Response received: " . json_encode($response) . "\n";
    $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "ping")));
    echo "Response received: " . json_encode($response) . "\n";
} catch (AvroRemoteException $e) {
    echo "Exception received: " . json_encode($e->getDatum()) . "\n";
}
try {
    $response = $requestor->request('testSimpleRequestWithoutParameters', array());
    echo "Response received: " . json_encode($response) . "\n";
} catch (AvroRemoteException $e) {
    echo "Exception received: " . json_encode($e->getDatum()) . "\n";
}
try {
Exemplo n.º 12
0
 public static function all_api_keys($apiKey = null)
 {
     $requestor = new Requestor($apiKey);
     list($response, $apiKey) = $requestor->request('get', '/api_keys');
     return Util::convertToEasyPostObject($response, $apiKey);
 }
 public function __construct($host, $port)
 {
     $client = \NettyFramedSocketTransceiver::create($host, $port);
     parent::__construct(\AvroProtocol::parse(self::$json_protocol), $client);
 }