forked from James-Azzopardi/starshipit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2126ca8
commit bb5787f
Showing
5 changed files
with
235 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters