PHP code example of andreibesleaga / ocm-php

1. Go to this page and download the library: Download andreibesleaga/ocm-php 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/ */

    

andreibesleaga / ocm-php example snippets




use Ocm\Client;

$client = new Client(apiKey: getenv('OCM_API_KEY') ?: 'My API Key');

$pois = $client->poi->list();

var_dump($pois);



use Ocm\Core\Exceptions\APIConnectionException;
use Ocm\Core\Exceptions\RateLimitException;
use Ocm\Core\Exceptions\APIStatusException;

try {
  $pois = $client->poi->list();
} catch (APIConnectionException $e) {
  echo "The server could not be reached", PHP_EOL;
  var_dump($e->getPrevious());
} catch (RateLimitException $e) {
  echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
} catch (APIStatusException $e) {
  echo "Another non-200-range status code was received", PHP_EOL;
  echo $e->getMessage();
}



use Ocm\Client;

// Configure the default for all requests:
$client = new Client(requestOptions: ['maxRetries' => 0]);

// Or, configure per-request:
$result = $client->poi->list(requestOptions: ['maxRetries' => 5]);



$pois = $client->poi->list(
  requestOptions: [
    'extraQueryParams' => ['my_query_parameter' => 'value'],
    'extraBodyParams' => ['my_body_parameter' => 'value'],
    'extraHeaders' => ['my-header' => 'value'],
  ],
);



$response = $client->request(
  method: "post",
  path: '/undocumented/endpoint',
  query: ['dog' => 'woof'],
  headers: ['useful-header' => 'interesting-value'],
  body: ['hello' => 'world']
);
json
{
  "repositories": [
    {
      "type": "vcs",
      "url": "[email protected]:andreibesleaga/ocm-php.git"
    }
  ],
  "