PHP code example of germania-kg / downloadsapi-client

1. Go to this page and download the library: Download germania-kg/downloadsapi-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/ */

    

germania-kg / downloadsapi-client example snippets


// Provided by interface 
// Germania\DownloadsApi\DownloadsApiInterface

public function all() : iterable;
public function latest() : iterable;
public function request( string $path ) : iterable ;

public function setAuthentication( ?string $key ) : DownloadsApiInterface;
public function getAuthentication( ) : string;

// Inherited from abstract class 
// Germania\DownloadsApi\DownloadsApiAbstract
  
$api->setLogger( \Monolog\Logger( ... ) ); 

$api->setErrorLoglevel( \LogLevel::ERROR );
$api->setSuccessLoglevel( \LogLevel::INFO );

$api->setAuthentication( "secrete" );
$api->getAuthentication(); // "secret"


use Germania\DownloadsApi\DownloadsApi;
use Germania\DownloadsApi\CacheDownloadsApiDecorator;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$api = new DownloadsApi( ... );
$psr6 = new FilesystemAdapter( ... );

$cached_api = new CacheDownloadsApiDecorator( $api, $psr6);
$cached_api = new CacheDownloadsApiDecorator( $api, $psr6, 14400);


use Germania\DownloadsApi\DownloadsApi;
use GuzzleHttp\Client;
use Nyholm\Psr7\Factory\Psr17Factory;

$psr18 = new Client;
$psr17 = new Psr17Factory;
$key = "secret"
  
$api = new DownloadsApi($psr18, $psr17, $key);

$downloads = $api->latest();
$downloads = $api->all();

foreach( $downloads as $document):
	print_r( $document );
endforeach;

$filters = array(
  'company' => "ACME",
  'brand'   => "mybrand",
  'category' => "brochure",
  'language' => "en",
  'keyword' => "customers,retailers",
  'product' => "cars,bikes"
);

$downloads = $api->latest($filters);
$downloads = $api->all($filters);


use Germania\DownloadsApi\DownloadsApiExceptionInterface;
use Germania\DownloadsApi\DownloadsApiRuntimeException;
use Germania\DownloadsApi\DownloadsApiResponseException;
use Germania\DownloadsApi\DownloadsApiUnexpectedValueException;

try {
  $client->latest();
}
catch (\Germania\DownloadsApi\DownloadsApiExceptionInterface $e) {
	echo $e->getMessage();
}