PHP code example of amara / onehydra

1. Go to this page and download the library: Download amara/onehydra library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

amara / onehydra example snippets


use Amara\OneHydra\Api;
use Amara\OneHydra\Http\HttpRequestBuilder;
use Amara\OneHydra\Http\Transport\GuzzleTransport;
use Amara\OneHydra\ResultBuilder\ResultBuilderEngine;
use GuzzleHttp\Client;

$isUat = false;
$authToken = 'your auth token';

// Use the standard request builder
$httpRequestBuilder = new HttpRequestBuilder($isUat, $authToken);

// Create a Guzzle transport, in UAT you'll need to ignore the OneHydra SSL cert
$guzzleClient = new Client();
$transport = new GuzzleTransport($guzzleClient);

// Create the result builder engine, which will create result objects 
// for our requests
$resultBuilderEngine = new ResultBuilderEngine();

$api = new Api($httpRequestBuilder, $transport, $resultBuilderEngine);

$pagesResult = $api->getPagesResult();
    
// Print the urls of the pages we will need to fetch details for
foreach ($pagesResult->getPageUrls() as $pageUrl) {
    echo $pageUrl;
}

$pageResult = $api->getPageResult('/my/page');
$pageLinks = $pageResult->getPage()->getLinks();