bagart / laravel-api-provider
Test work: Laravel response for location API
dev-master
2017-12-05 02:25 UTC
Requires
- php: >=7.1.0
- guzzlehttp/guzzle: ^6.2@dev
This package is not auto-updated.
Last update: 2025-03-08 18:38:40 UTC
README
Need to implement Symfony3 or Laravel bundle for getting JSON-encoded locations data stored in predefined format.
Acceptance criteria
- Client should be defined as a service class in a bundle config;
- Client should utilize CURL as a transport layer (can rely upon any third-party **bundle however should be implemented as a separate class/package);
- Properly defined exceptions should be thrown on CURL errors, malformed JSON response and error JSON response;
- Resulting data should be fetched as an array (or other collection) of properly
JSON response format
{ "data": { "locations": [ { "name": "Eiffel Tower", "coordinates": { "lat": 21.12, "long": 19.56 } }, ... ] }, "success": true }
JSON error response format
{
"data": {
"message": <string error message>,
"code": <string error code>
},
"success": false
}
INSTALL
composer require bagart/laravel-api-provider '@dev'
Usage
/** * @var \Bagart\LaravelApiProvider\Providers\DataProvider $data_provider */ $data_provider = app(\Bagart\LaravelApiProvider\Providers\DataProvider::class); dump($data_provider->request('http://dockerhost/example.json', 'locations')); dump($data_provider->request('http://dockerhost/example2.json', 'locations')); try { $data_provider->request('http://dockerhost/error.json', 'locations'); } catch (\Bagart\LaravelApiProvider\Exceptions\LaravelApiProviderException $e) { dump("LaravelApiProviderException: {$e->getMessage()}"); }
Features
used:
Guzzle
(curl inside as options)
Todo
- request empty logic and API empty format
- PHPUnit tests
Tech details
Contracts
Bagart\LaravelApiProvider\ApiClientContract
Bagart\LaravelApiProvider\DataProviderContract
Bagart\LaravelApiProvider\DataContainerContract
Exceptions
All of expected Exception is instance of Bagart\LaravelApiProvider\Exceptions\LaravelApiProviderException