Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
milindsingh committed Dec 27, 2019
1 parent 2126ca8 commit bb5787f
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 77 deletions.
137 changes: 71 additions & 66 deletions src/Starshipit/Api.php
Original file line number Diff line number Diff line change
@@ -1,76 +1,81 @@
<?php
namespace Starshipit;

use Doctrine\Common\Annotations\AnnotationRegistry;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Starshipit\Model\Authorization;
use JMS\Serializer\SerializerInterface;
use Starshipit\Service\Order as OrderService;
use Starshipit\Service\Label as LabelService;
use Starshipit\Service\Tracking as TrackingService;
namespace Starshipit;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\AnnotationReader;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Starshipit\Model\Authorization;
use JMS\Serializer\SerializerInterface;
use Starshipit\Service\Order as OrderService;
use Starshipit\Service\Label as LabelService;
use Starshipit\Service\Tracking as TrackingService;

/**
* Class Api
* @package Starshipit\Api
*/
class Api
{
/**
* Attempt to access the ping endpoint and will return true on success.
* @return bool
*/
public static function ping($endpoint, ClientInterface $client = null)
{
AnnotationReader::addGlobalIgnoredName('alias');
AnnotationRegistry::registerLoader('class_exists');

$starshipitClient = $client ?: new Client(['base_uri' => $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);
}

}

142 changes: 135 additions & 7 deletions src/Starshipit/Model/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,30 +81,125 @@ public function setErrors(array $errors)
}

/**
* @return string
* @return \Starshipit\Model\Error[]
*/
public function getErrors()
{
return $this->errors;
}

/**
* @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;
}

/**
* @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;
}
}

6 changes: 3 additions & 3 deletions src/Starshipit/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class Order
protected $success;

/**
* @var string
* @var array
*/
protected $errors;
protected $errors = [];

/**
* @var OrderDetails
Expand Down Expand Up @@ -71,7 +71,7 @@ public function setErrors(array $errors)
}

/**
* @return string
* @return \Starshipit\Model\Error[]
*/
public function getErrors()
{
Expand Down
18 changes: 18 additions & 0 deletions src/Starshipit/Serializer/Starshipit.Model.Label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Starshipit\Model\Label:
properties:
success:
type: boolean
errors:
type: array<Starshipit\Model\Error>
order_id:
type: int
order_number:
type: string
carrier_name:
type: string
tracking_numbers:
type: array<string>
labels:
type: array<string>
label_types:
type: array<string>
9 changes: 8 additions & 1 deletion src/Starshipit/Service/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit bb5787f

Please sign in to comment.