Skip to content

Commit

Permalink
Merge pull request #10 from smartsendio/develop
Browse files Browse the repository at this point in the history
v0.1
  • Loading branch information
bilfeldt authored Jun 5, 2020
2 parents 13ae507 + a208026 commit c8778ee
Show file tree
Hide file tree
Showing 53 changed files with 4,186 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
50 changes: 50 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Tests

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]
schedule:
- cron: '0 0 * * *'

jobs:
test:

runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [7.2, 7.3, 7.4]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]

name: P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

steps:
- uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: dependencies-php-${{ matrix.php }}-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
dependencies-php-${{ matrix.php }}-${{ runner.os }}-composer-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Run test suite
run: composer run-script test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
composer.lock
vendor
phpcs.xml
phpunit.xml
.phpunit.result.cache
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: psr2
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

All notable changes to `api` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## NEXT - YYYY-MM-DD

### Added
- Nothing

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2020 SmartSend <[email protected]>

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
153 changes: 151 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,151 @@
# php-sdk
PHP SDK for the Smart Send API
# Smart Send API

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
![Tests](https://github.com/smartsendio/php-sdk/workflows/Tests/badge.svg)
[![Total Downloads][ico-downloads]][link-downloads]

PHP SDK for interacting with the Smart Send API.

## Install

Via Composer

``` bash
$ composer require smartsendio/api
```

## Usage

Use Composer's autoload:

```php
require __DIR__.'/../vendor/autoload.php';
```

And finally create an instance of the SDK:

```php
$client = new Smartsendio\Api\Adapters\GuzzleClientAdapter(new \GuzzleHttp\Client()); // Any client implementing ClientInterface
$api = new Smartsendio\Api\ApiFactory($client);
$api->apiToken('API_TOKEN_HERE')->website('WEBSITE'); // Set the authentication parameters
```

### Demo mode
Demo mode can be used for testing and is activated like so:

```php
$api->demo(); // Not the api is in demo mode.
```

### Fetching agents
Agents are fetched using the `agent` API.

```php
// Example: All agents for a given carrier in a zipcode
$response = $api->agents()
->carrier('postnord')
->country('DK')
->zipcode('2100')
->get(); // ApiResponseInterface

// Example: The closest agents for a given carrier based on a given address
$response = $api->agents()
->carrier('postnord')
->country('DK')
->zipcode('2100')
->street('Nordre Frihavnsgade 1')
->closest(); // ApiResponseInterface
```

### Shipments
```php
$item = new \Smartsendio\Api\Data\Item([
'internal_id' => '000000123',
'internal_reference' => 'PRODUCT-1231456',
'sku' => '012345678',
'name' => 'Product A',
'description' => 'Small product A',
'hs_code' => '10203040',
'country_of_origin' => 'dk',
'image_url' => 'https://example.com/catalog/product-a.jpg',
'unit_weight' => 1.2,
'unit_price_excluding_tax' => 40.6,
'unit_price_including_tax' => 50.75,
'quantity' => 2,
'total_price_excluding_tax' => 81.2,
'total_price_including_tax' => 101.5,
'total_tax_amount' => 20.3,
]);

$parcel = new \Smartsendio\Api\Data\Parcel([
'internal_id' => '00100025556',
'internal_reference' => 'ABC12345678',
'weight' => 9.3,
'height' => 1,
'width' => 1,
'length' => 1,
'freetext' => 'Please handle this package',
'total_price_excluding_tax' => 141.2,
'total_price_including_tax' => 176.5,
'total_tax_amount' => 35.3,
]);
$parcel->addItem($item);

$shipment = new \Smartsendio\Api\Data\Shipment();
$shipment->setReceiver([
'internal_id' => '00000158895',
'internal_reference' => '123456',
'company' => 'Smart Send',
'name_line1' => 'Sven',
'name_line2' => 'Andersson',
'address_line1' => 'Drottninggatan 75',
'address_line2' => 'LGH 1102',
'postal_code' => '46133',
'city' => 'Trollhøttan',
'state' => 'AL',
'country' => 'SE',
'sms' => '+46851972000',
'email' => '[email protected]',
])->addParcel($parcel);

$api->book($shipment); // ApiResponseInterface
```

### Dealing with errors
This is how to deal with API errors:

```php
$api->shipments()->book($shipment); // ApiResponseInterface
$api->isSuccessful(); // false
$api->getError(); // ApiErrorInterface
```

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Testing

``` bash
$ composer test
```

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/smartsendio/api.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/smartsendio/api/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/smartsendio/api.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/smartsendio/api.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/smartsendio/api.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/smartsendio/api
[link-travis]: https://travis-ci.org/smartsendio/api
[link-scrutinizer]: https://scrutinizer-ci.com/g/smartsendio/api/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/smartsendio/api
[link-downloads]: https://packagist.org/packages/smartsendio/api
[link-author]: https://github.com/smartsendio
[link-contributors]: ../../contributors
56 changes: 56 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "smartsendio/api",
"type": "library",
"description": "API Package for the Smart Send API",
"keywords": [
"SmartSend",
"Smart Send",
"SmartSendIo",
"Smart Send Io",
"api",
"sdk"
],
"homepage": "https://github.com/smartsendio/api",
"license": "MIT",
"authors": [
{
"name": "SmartSend",
"email": "[email protected]",
"homepage": "https://smartsend.io",
"role": "Developer"
}
],
"require": {
"ext-json": "*",
"php": "~7.2",
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"phpunit/phpunit": ">=8.4",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"Smartsendio\\Api\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Smartsendio\\Api\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit",
"check-style": "phpcs src tests",
"fix-style": "phpcbf src tests"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
}
}
14 changes: 14 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset name="api">
<description>The coding standard of api package</description>
<arg value="p" />

<config name="ignore_warnings_on_exit" value="1" />
<config name="ignore_errors_on_exit" value="1" />

<arg name="colors" />
<arg value="s" />

<!-- Use the PSR2 Standard-->
<rule ref="PSR2" />
</ruleset>
28 changes: 28 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Smart Send Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
Loading

0 comments on commit c8778ee

Please sign in to comment.