|
1 | | -BaseKit REST API Client |
2 | | -======================= |
| 1 | +# BaseKit REST API Client |
3 | 2 |
|
4 | | -[](http://travis-ci.org/basekit/php-api-client) |
5 | | -[](https://scrutinizer-ci.com/g/basekit/php-api-client/) |
| 3 | +A PHP client for [BaseKit](http://basekit.com/)'s REST API. This client will provide documentation of the services available from the BaseKit API, describing URIs, HTTP methods and input parameters. |
6 | 4 |
|
7 | | -A PHP client for [BaseKit]'s REST API. This client will provide documentation of |
8 | | -the services available from the BaseKit API, describing URIs, HTTP methods and |
9 | | -input parameters. |
| 5 | +## Installation |
10 | 6 |
|
11 | | -Installation |
12 | | ------------- |
| 7 | +The recommended way of including this package in your project is by using Composer. Add it to the `require` section of your project's `composer.json`. |
13 | 8 |
|
14 | | -The recommended way of including this package in your project is by using |
15 | | -Composer. Add it to the `require` section of your project's `composer.json`. |
16 | | - |
17 | | - "basekit/php-api-client": "1.2.1" |
| 9 | +```bash |
| 10 | +composer require basekit/php-api-client |
| 11 | +``` |
18 | 12 |
|
19 | | -Usage |
20 | | ------ |
| 13 | +## Usage |
21 | 14 |
|
22 | 15 | ```php |
23 | | -<?php |
24 | | - |
25 | | -require 'vendor/autoload.php'; |
26 | | -use BaseKit\Api\Client; |
27 | | - |
28 | | -$client = Client::factory( |
29 | | - array( |
30 | | - 'base_url' => 'http://api.example.org', |
31 | | - 'consumer_key' => '1234567890', |
32 | | - 'consumer_secret' => 'qwertyuiop', |
33 | | - 'token' => 'asdfghjkl', |
34 | | - 'token_secret' => 'zxcvbnm', |
35 | | - ) |
| 16 | +use BaseKit\Api\AuthType; |
| 17 | +use BaseKit\Api\ClientFactory; |
| 18 | + |
| 19 | +$client = ClientFactory::create( |
| 20 | + [ |
| 21 | + 'base_uri' => 'http://api.testing.com', |
| 22 | + 'username' => 'foo', |
| 23 | + 'password' => 'bar', |
| 24 | + ], |
| 25 | + AuthType::BASIC, // defaults to basic auth |
36 | 26 | ); |
37 | 27 |
|
38 | 28 | $createSite = $client->getCommand( |
39 | 29 | 'CreateSite', |
40 | | - array( |
| 30 | + [ |
41 | 31 | 'accountHolderRef' => 123, |
42 | | - 'brandRef' => 456, |
| 32 | + 'brandRef' => 789, |
43 | 33 | 'domain' => 'test.example.org', |
44 | | - ) |
| 34 | + ] |
45 | 35 | ); |
46 | | -$response = $createSite->execute(); |
47 | | -print_r($response); |
| 36 | + |
| 37 | +$client->execute($createSite); |
48 | 38 | ``` |
49 | 39 |
|
50 | | -Contributing |
51 | | ------------- |
| 40 | +## Testing |
52 | 41 |
|
53 | | -This project adheres to the [PSR2] coding style guide. Checking your |
54 | | -contribution's correctness is easy. |
| 42 | +Feed an optional `handler` into the config of `clientFactory` to control the responses from the http client. |
55 | 43 |
|
56 | | -```bash |
57 | | -$ make lint |
58 | | -``` |
| 44 | +```php |
| 45 | +use BaseKit\Api\ClientFactory; |
| 46 | +use GuzzleHttp\HandlerStack; |
| 47 | +use GuzzleHttp\Handler\MockHandler; |
| 48 | +use GuzzleHttp\Psr7\Response; |
| 49 | + |
| 50 | +$client = ClientFactory::create([ |
| 51 | + 'base_uri' => 'https://api.testing.com', |
| 52 | + 'username' => 'foo', |
| 53 | + 'password' => 'bar', |
| 54 | + 'handler' => HandlerStack::create( |
| 55 | + new MockHandler([ |
| 56 | + new Response(404, [], 'Hello, World! This is a test response.'), |
| 57 | + ]) |
| 58 | + ) , |
| 59 | +]); |
59 | 60 |
|
60 | | -There's a very small unit test suite, using [PHPUnit]. Making sure you haven't |
61 | | -broken any tests is easy too. |
| 61 | +$createSite = $client->getCommand( |
| 62 | + 'CreateSite', |
| 63 | + [ |
| 64 | + 'accountHolderRef' => 123, |
| 65 | + 'brandRef' => 789, |
| 66 | + 'domain' => 'test.example.org', |
| 67 | + ] |
| 68 | +); |
62 | 69 |
|
63 | | -```bash |
64 | | -$ make test |
| 70 | +$client->execute($createSite); // Throws a 404 CommandClientException |
65 | 71 | ``` |
66 | 72 |
|
67 | | -License |
68 | | -------- |
69 | | - |
70 | | -This software is released under the [MIT License]. |
| 73 | +## License |
71 | 74 |
|
72 | | -[BaseKit]: http://basekit.com/ |
73 | | -[PHPUnit]: http://phpunit.de/ |
74 | | -[PSR2]: http://www.php-fig.org/psr/psr-2/ |
75 | | -[MIT License]: http://www.opensource.org/licenses/MIT |
| 75 | +This software is released under the [MIT License](http://www.opensource.org/licenses/MIT). |
0 commit comments