2017 © Pedro Peláez
 

library api-client

Official Realo API client

image

realo/api-client

Official Realo API client

  • Thursday, September 7, 2017
  • by mcuelenaere
  • Repository
  • 7 Watchers
  • 2 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Realo API PHP Library

The official PHP library for using the Realo REST API., (*1)

Before using this library, you must have a valid API Key. To get an API Key, please contact your Realo customer success manager., (*2)

Installation

The recommended way to install the Realo PHP API client is through composer., (*3)

Next, run the composer command to install the Realo PHP API client:, (*4)

composer require realo/api-client

After installing, you need to require Composer's autoloader:, (*5)

require_once __DIR__ . '/vendor/autoload.php';

As a Phar

You may download a ready-to-use version of the Realo API client library as a Phar from our releases. This includes the API client and all its dependencies., (*6)

After downloading, you need to require the bundled autoloader:, (*7)

require_once 'phar://' . __DIR__ . '/realo-api-client.phar/vendor/autoload.php';

Initialization

RealoApi::create(publicKey, privateKey, environment)

  • publicKey
    • Type: string
    • API public key
  • privateKey
    • Type: string
    • API private key
  • environment
    • Type: string
    • Default value: production
    • API environment (either production or sandbox)

RealoApi::createWithClient(publicKey, privateKey, client)

  • publicKey
    • Type: string
    • API public key
  • privateKey
    • Type: string
    • API private key
  • client
    • Type: GuzzleHttp\Client
    • Guzzle HTTP client, used for communicating with the REST API

Methods

request(path, method, [, payload [, headers]])

  • path
    • Type: string
    • The path of the resource
  • method
    • Type: string
    • HTTP method for request
  • payload
    • Type: array
    • HTTP payload (to be encoded as JSON), only applies when the HTTP method is not GET
  • headers
    • Type: array
    • Custom headers to be sent with the request.

Examples

Use The Bundled CLI Tool

We provide a simple CLI utility which you can use to interact with our API., (*8)

$ php example/simple-cli.php --public-key=xxx --private-key=xxx /valuations/xxx/data/mobility
{
    "data": {
        "mobilityScore": 0.88,
        "distanceToCityCenter": 3130,
        "distanceToBusStop": 323,
        "distanceToTrainStation": 1197,
        "distanceToSchool": 77,
        "distanceToStores": 33,
        "distanceToHighways": 3282,
        "buildingDensity": 1688.01,
        "inhabitantsDensity": 32346.18,
        "transitTypeCityCenter": "cycling-distance",
        "transitTypeBusStop": "walking-distance",
        "transitTypeTrainStation": "walking-distance",
        "transitTypeSchool": "walking-distance",
        "transitTypeStores": "walking-distance"
    }
}

Send An API Call Using The Request Function

We provide a base request function to access any of our API resources., (*9)

use Realo\Api\RealoApi;
use Realo\Api\RealoApiException;

$api = RealoApi::create('YOUR_PUBLIC_KEY', 'YOUR_PRIVATE_KEY');
try {
    $response = $api->request('/agencies', 'GET');
    var_dump($response);
} catch (RealoApiException $e) {
    printf("Error %d: %s\n", $e->getCode(), $e->getMessage());
}

Exceptions

An exception will be thrown in two cases: there is a problem with the request or the server returns a status code of 400 or higher., (*10)

RealoApiException

  • getCode()
    • Returns the response status code of 400 or higher.
  • getMessage()
    • Returns the exception message.
  • getErrors()
    • If there is a response body containing an array of errors, return these. Otherwise returns null.
  • getType()
    • If there is a response body containing an error, return its type. Otherwise returns null.

The Versions

07/09 2017

dev-master

9999999-dev

Official Realo API client

  Sources   Download

MIT

The Requires

 

07/09 2017

v1.0.2

1.0.2.0

Official Realo API client

  Sources   Download

MIT

The Requires

 

24/05 2017

v1.0.1

1.0.1.0

Official Realo API client

  Sources   Download

MIT

The Requires

 

17/05 2017

v1.0

1.0.0.0

Official Realo API client

  Sources   Download

MIT

The Requires