Download the PHP package dan-rogers/shiptheory-php-client without Composer
On this page you can find all versions of the php package dan-rogers/shiptheory-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dan-rogers/shiptheory-php-client
More information about dan-rogers/shiptheory-php-client
Files in dan-rogers/shiptheory-php-client
Package shiptheory-php-client
Short Description An API client to communicate with the Shiptheory API
License MIT
Informations about the package shiptheory-php-client
shiptheory-php-client
Client to handle sending HTTP requests to the Shiptheory V1 REST API. Handles logging, authentication/refreshing tokens. Uses PSR compliant interfaces and dependency injection where possible.
View on Pakagist: https://packagist.org/packages/dan-rogers/shiptheory-php-client
View Shiptheory API Docs: https://shiptheory.com/developer/index.html
Installation
Usage
The client uses DI in conjunction with existing PSR standards so that you can operate in your preferred environment with your preferred libraries. The HTTP client required on instantiation must implement PSR18 and the optional logger you can use on instantiation must implement PSR3.
Tokens
Types of Token
Shiptheory offers 2 kinds of authentication:
- Credential based access: Users must pass their login credentials to the
/token
endpoint to exchange them for a JWT access token which can then be used in subsequent requests. This token lasts for one hour, but a new one can be generated at any time. - Permanent tokens: You can generate an unchanging, permanent token by logging into your account and going to https://helm.shiptheory.com/user_tokens
Implementation
To use credential access tokens you should pass an instance of ShiptheoryClient\Authorization\CredentialsAccessToken
to your new instance of the Shiptheory Client. The token will automatically refresh itself. When instantiated you must pass your username and password as arguments.
To use a permanent access token you should pass and instance of ShiptheoryClient\Authorization\PermanentAccessToken
to your new instance of the Shiptheory Client. When instantiated you must pass your permanent token as the argument.
Example Usage
The below example uses guzzlehttp/guzzle
for the client, the CredentialsAccessToken
for authorisation and monolog/monolog
for the logging.
Logging
Enabling Logging
Logging is provided via DI. Pass in any PSR3 compliant logger object when instantiating ShiptheoryClient and the logging will be handled automatically for both requests and responses. If a logger is not provided then all logs a "blackholed" via use of Psr\Log\NullLogger
.
Example Log Output
When using logging your PSR7 messages will be converted into their HTTP request quivalent. The following was generated using monolog/monlog
, but the general format of a transaction ID followed by a stringed request or response will be consistent regardless of the PSR3 compliant logging solution you use.
Using a Shiptheory Partner Tag
"If you are developing an application that will be used by more than 1 company, or an application that you intend to distribute in anyway, you must include the Shiptheory-Partner-Tag http request header in all of your requests. Please contact Shiptheory support to obtain a partner tag. There is no charge for this, tags are used to provide better support to customers and partners." - API Docs
In order to add a partner tag to your API requests add it as the fourth argument when instantiating a new ShiptheoryClient.
All versions of shiptheory-php-client with dependencies
psr/http-client Version ^1.0
psr/log Version ^3.0
nyholm/psr7 Version ^1.8