PHP code example of minicli / curly

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

    

minicli / curly example snippets


$crawler = new Client();

$articles_response = $crawler->get('https://dev.to/api/articles?username=erikaheidi');

if ($articles_response['code'] !== 200) {
    $app->getPrinter->error('Error while contacting the dev.to API.');
    return 1;
}

$articles = json_decode($articles_response['body'], true);
print_r($articles);

#!/usr/bin/env php

if (php_sapi_name() !== 'cli') {
    exit;
}

Minicli\Curly\Client;

$app = new App([
    'debug' => true,
    'theme' => '\Unicorn'
]);

$app->registerCommand('devto', function () use ($app) {
    $app->getPrinter()->display('Fetching from DEV...');
    $crawler = new Client();

    $articles_response = $crawler->get('https://dev.to/api/articles?username=DEVUSERNAME');

    if ($articles_response['code'] !== 200) {
        $app->getPrinter->error('Error while contacting the dev.to API.');
        return 1;
    }

    $articles = json_decode($articles_response['body'], true);
    $table[] = ['Title', 'Reactions'];
    foreach($articles as $article) {
        $table[] = [$article['title'], $article['positive_reactions_count']];
    }
    $app->getPrinter()->printTable($table);
    return 0;
});

try {
    $app->runCommand($argv);
} catch (CommandNotFoundException $notFoundException) {
    $app->getPrinter()->error("Command Not Found.");
    return 1;
}

return 0;