diff --git a/src/Starshipit/Api.php b/src/Starshipit/Api.php index 57ce9ca..3768a54 100644 --- a/src/Starshipit/Api.php +++ b/src/Starshipit/Api.php @@ -1,76 +1,81 @@ $endpoint]); + + return new Ping($starshipitClient); + } /** - * Class Api - * @package Starshipit\Api + * Attempt to create an Order endpoint returns Order on success + * @return object */ - class Api + public static function order(Authorization $authorization, Client $client = null, SerializerInterface $serializer = null) { + AnnotationReader::addGlobalIgnoredName('alias'); + AnnotationRegistry::registerLoader('class_exists'); - /** - * Attempt to access the ping endpoint and will return true on success. - * @return bool - */ - public static function ping($endpoint, ClientInterface $client = null) - { - AnnotationRegistry::registerLoader('class_exists'); - - $starshipitClient = $client ?: new Client([ 'base_uri' => $endpoint ]); - - return new Ping($starshipitClient); - } - - /** - * Attempt to create an Order endpoint returns Order on success - * @return object - */ - public static function order(Authorization $authorization, Client $client = null, SerializerInterface $serializer = null) - { - AnnotationRegistry::registerLoader('class_exists'); - - $starshipitClient = $client ? : new Client([ 'base_uri' => $authorization->getEndpoint() ]); - $starshipitSerializer = $serializer ? : SerializerFactory::getSerializer(); - - return new OrderService($starshipitClient, $authorization, $starshipitSerializer); - } - - /** - * Attempt to create an Label endpoint returns Order on success - * @return object - */ - public static function label(Authorization $authorization, Client $client = null, SerializerInterface $serializer = null) - { - AnnotationRegistry::registerLoader('class_exists'); - - $starshipitClient = $client ? : new Client([ 'base_uri' => $authorization->getEndpoint() ]); - $starshipitSerializer = $serializer ? : SerializerFactory::getSerializer(); - - return new LabelService($starshipitClient, $authorization, $starshipitSerializer); - } - - /** - * Attempt to create an Label endpoint returns Order on success - * @return object - */ - public static function tracking(Authorization $authorization, Client $client = null, SerializerInterface $serializer = null) - { - AnnotationRegistry::registerLoader('class_exists'); - - $starshipitClient = $client ? : new Client([ 'base_uri' => $authorization->getEndpoint() ]); - $starshipitSerializer = $serializer ? : SerializerFactory::getSerializer(); - - return new TrackingService($starshipitClient, $authorization, $starshipitSerializer); - } + $starshipitClient = $client ?: new Client(['base_uri' => $authorization->getEndpoint()]); + $starshipitSerializer = $serializer ?: SerializerFactory::getSerializer(); + return new OrderService($starshipitClient, $authorization, $starshipitSerializer); } + /** + * Attempt to create an Label endpoint returns Order on success + * @return object + */ + public static function label(Authorization $authorization, Client $client = null, SerializerInterface $serializer = null) + { + AnnotationReader::addGlobalIgnoredName('alias'); + AnnotationRegistry::registerLoader('class_exists'); + + $starshipitClient = $client ?: new Client(['base_uri' => $authorization->getEndpoint()]); + $starshipitSerializer = $serializer ?: SerializerFactory::getSerializer(); + + return new LabelService($starshipitClient, $authorization, $starshipitSerializer); + } + + /** + * Attempt to create an Label endpoint returns Order on success + * @return object + */ + public static function tracking(Authorization $authorization, Client $client = null, SerializerInterface $serializer = null) + { + AnnotationReader::addGlobalIgnoredName('alias'); + AnnotationRegistry::registerLoader('class_exists'); + + $starshipitClient = $client ?: new Client(['base_uri' => $authorization->getEndpoint()]); + $starshipitSerializer = $serializer ?: SerializerFactory::getSerializer(); + + return new TrackingService($starshipitClient, $authorization, $starshipitSerializer); + } + +} + diff --git a/src/Starshipit/Model/Label.php b/src/Starshipit/Model/Label.php index acb0710..db4a7ce 100644 --- a/src/Starshipit/Model/Label.php +++ b/src/Starshipit/Model/Label.php @@ -14,8 +14,41 @@ class Label * @var string */ protected $success; + + /** + * @var array + */ protected $errors; - protected $order; + + /** + * @var int + */ + protected $order_id; + + /** + * @var string + */ + protected $carrier_name; + + /** + * @var int + */ + protected $order_number; + + /** + * @var array + */ + protected $tracking_numbers; + + /** + * @var array + */ + protected $labels; + + /** + * @var array + */ + protected $label_types; /** * @param string $success @@ -48,7 +81,7 @@ public function setErrors(array $errors) } /** - * @return string + * @return \Starshipit\Model\Error[] */ public function getErrors() { @@ -56,12 +89,50 @@ public function getErrors() } /** - * @param string $order + * @return string + */ + public function getOrderId() + { + return $this->order_id; + } + + /** + * @param string $orderId + * @return $this + */ + public function setOrderId($orderId) + { + $this->order_id = $order_id; + + return $this; + } + + /** + * @param string $name + * @return $this + */ + public function setCarrierName($name) + { + $this->carrier_name = $name; + + return $this; + } + + /** + * @return string + */ + public function getCarrierName() + { + return $this->carrier_name; + } + + /** + * @param string $orderNumber * @return $this */ - public function setOrder($order) + public function setOrderNumber($orderNumber) { - $this->order = $order; + $this->order_number = $orderNumber; return $this; } @@ -69,9 +140,66 @@ public function setOrder($order) /** * @return string */ - public function getOrder() + public function getOrderNumber() + { + return $this->order_number; + } + + /** + * @param array $numbers + * @return $this + */ + public function setTrackingNumbers($numbers) + { + $this->tracking_numbers = $numbers; + + return $this; + } + + /** + * @return array + */ + public function getTrackingNumbers() + { + return $this->tracking_numbers; + } + + /** + * @param array $labels + * @return $this + */ + public function setLabels($labels) + { + $this->labels = $labels; + + return $this; + } + + /** + * @return array + */ + public function getLabels() + { + return $this->labels; + } + + /** + * @param array $types + * @return $this + */ + public function setLabelTypes($types) + { + $this->label_types = $types; + + return $this; + } + + /** + * @return array + */ + public function getLabelTypes() { - return $this->order; + return $this->label_types; } } diff --git a/src/Starshipit/Model/Order.php b/src/Starshipit/Model/Order.php index 3dbf5b2..09149fb 100644 --- a/src/Starshipit/Model/Order.php +++ b/src/Starshipit/Model/Order.php @@ -16,9 +16,9 @@ class Order protected $success; /** - * @var string + * @var array */ - protected $errors; + protected $errors = []; /** * @var OrderDetails @@ -71,7 +71,7 @@ public function setErrors(array $errors) } /** - * @return string + * @return \Starshipit\Model\Error[] */ public function getErrors() { diff --git a/src/Starshipit/Serializer/Starshipit.Model.Label.yml b/src/Starshipit/Serializer/Starshipit.Model.Label.yml new file mode 100644 index 0000000..052865b --- /dev/null +++ b/src/Starshipit/Serializer/Starshipit.Model.Label.yml @@ -0,0 +1,18 @@ +Starshipit\Model\Label: + properties: + success: + type: boolean + errors: + type: array + order_id: + type: int + order_number: + type: string + carrier_name: + type: string + tracking_numbers: + type: array + labels: + type: array + label_types: + type: array diff --git a/src/Starshipit/Service/Label.php b/src/Starshipit/Service/Label.php index 12ea9c6..07b7a92 100644 --- a/src/Starshipit/Service/Label.php +++ b/src/Starshipit/Service/Label.php @@ -66,7 +66,14 @@ public function print_label(OrderModel $order) ); } - return $result->getBody(); + /** @var LabelModel $label */ + $label = $this->getSerializer()->deserialize( + (string) $result->getBody(), + LabelModel::class, + 'json' + ); + + return $label; } }