2017 © Pedro Peláez
 

library laravel-api-provider

Test work: Laravel response for location API

image

bagart/laravel-api-provider

Test work: Laravel response for location API

  • Tuesday, December 5, 2017
  • by bagart
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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
}

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), (*5)

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, (*6)

The Versions

05/12 2017

dev-master

9999999-dev

Test work: Laravel response for location API

  Sources   Download

MIT

The Requires

 

by Avatar bagart