dev-master
9999999-devTest work: Laravel response for location API
MIT
The Requires
- php >=7.1.0
- guzzlehttp/guzzle ^6.2@dev
by bagart
Test work: Laravel response for location API
Need to implement Symfony3 or Laravel bundle for getting JSON-encoded locations data stored in predefined format., (*1)
Acceptance criteria 1. Client should be defined as a service class in a bundle config; 2. Client should utilize CURL as a transport layer (can rely upon any third-party **bundle however should be implemented as a separate class/package); 3. Properly defined exceptions should be thrown on CURL errors, malformed JSON response and error JSON response; 4. Resulting data should be fetched as an array (or other collection) of properly, (*2)
JSON response format, (*3)
{ "data": { "locations": [ { "name": "Eiffel Tower", "coordinates": { "lat": 21.12, "long": 19.56 } }, ... ] }, "success": true }
JSON error response format, (*4)
{ "data": { "message": <string error message>, "code": <string error code> }, "success": false }
composer require bagart/laravel-api-provider '@dev'
/** * @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()}"); }
used:
- Guzzle
(curl inside as options), (*5)
Bagart\LaravelApiProvider\ApiClientContract
Bagart\LaravelApiProvider\DataProviderContract
Bagart\LaravelApiProvider\DataContainerContract
All of expected Exception is instance of Bagart\LaravelApiProvider\Exceptions\LaravelApiProviderException
, (*6)
Test work: Laravel response for location API
MIT