Skip to content

Latest commit

 

History

History
86 lines (63 loc) · 2.26 KB

README.md

File metadata and controls

86 lines (63 loc) · 2.26 KB

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.

Basic usage

Run composer

composer require thalvik/resdiary-api-client

Initalize the class with parameters

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

$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

$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

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

You can then use client to call methods on available services

$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

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

Else, the call will return relevant data

print_r($restaurantSetup);

To run tests, fill the credentials in phpunit.xml.dist file

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

Then run PHPUnit

vendor/bin/phpunit