PHP code example of adaiasmagdiel / g1-client

1. Go to this page and download the library: Download adaiasmagdiel/g1-client 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/ */

    

adaiasmagdiel / g1-client example snippets




daiasMagdiel\G1\Client;
use AdaiasMagdiel\G1\Enum\Estado;

// Initialize the client (cache enabled by default)
$api = new Client();

// Fetch latest news from all regions
$resAll = $api->ultimas();
echo $resAll->news[0]->title . PHP_EOL;

// Fetch latest news from a specific state (e.g., Pará)
$resPara = $api->ultimas(estado: Estado::PARA);
echo $resPara->news[0]->title . PHP_EOL;

// Fetch page 2 of the latest news
$resPage2 = $api->ultimas(page: 2);
echo $resPage2->news[0]->title . PHP_EOL;

$api = new Client(
    cache: true,
    cacheDir: __DIR__ . '/.g1-cache',
    cacheTtl: 600 // seconds
);

$api = new Client(cache: false);

$img =
    $news->images['S']['url']
    ?? $news->images['M']['url']
    ?? $news->images['L']['url']
    ?? null;