2017 © Pedro Peláez
 

library resdiary-api-client

PHP client for ResDiary REST API

image

thalvik/resdiary-api-client

PHP client for ResDiary REST API

  • Thursday, April 12, 2018
  • by thalvik
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP client for ResDiary API

This is an unoffical PHP client for ResDiary API. It includes basic HTTP client, which is a simple HTTP wrapper around Guzzle HTTP client library. It then communicates with ResDiary API by calling available endpoints. Check the ResDiary API documentation for available API calls., (*1)

Basic usage

Run composer, (*2)

composer require thalvik/resdiary-api-client, (*3)

Initalize the class with parameters, (*4)

use Thalvik\ResDiaryApiClient\RdaClient;

$rdaClient = new RDAClient([
    'api_url' => 'https://thegreatapi.com/', //Change this to value given by ResDiary
    'username' => 'someusername', //Change this to value given by ResDiary
    'password' => 'somepassword' //Change this to value given by ResDiary
]);

Since token is lasting 24 hours, you want to check if you havent already saved token, for example calling in your custom function to check it in database, (*5)

$tokenSaved = someFunctionToRetrieveSaved24hToken('YOUR_RESDIARY_TOKEN_NAME');

You then call setAccessToken() on a client, which if token has expired, will set new token and retrieve it, (*6)

$tokenClient = $rdaClient->setAccessToken($tokenSaved);

You can then check if token has changed, you set new one for next 24 hours calling in your custom function, (*7)

if ($tokenClient != $tokenSaved) {
    someFunctionToSave24hToken( 'YOUR_RESDIARY_TOKEN_NAME', $tokenClient);
}

You can then use client to call methods on available services, (*8)

$now = new \DateTime();

$restaurantSetup = $rdaClient->getConsumerService('Restaurant') //Service name
->setMicroSiteName('TestProvider') //Set microSiteName
->getSetup([ //Call method
    'date' => $now->format('Y-m-d'),
    'channelCode' => 'ONLINE',
]);

If there are some errors in client request, you can check them by calling hasErrors and getErrors methods. getErrors will return array with Message and ValidationErrors, (*9)

if ($rdaClient->hasErrors()) {
    print_r($rdaClient->getErrors());
    exit();
}

Else, the call will return relevant data, (*10)

print_r($restaurantSetup);

To run tests, fill the credentials in phpunit.xml.dist file, (*11)

<const name="BASE_URI" value=""/>
<const name="USERNAME" value=""/>
<const name="PASSWORD" value=""/>

Then run PHPUnit, (*12)

vendor/bin/phpunit, (*13)

The Versions

12/04 2018

dev-master

9999999-dev

PHP client for ResDiary REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aleksandar Andrijevic

resdiary