PHP code example of galafeno / lingo
1. Go to this page and download the library: Download galafeno/lingo 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/ */
galafeno / lingo example snippets
protected $sync = [
'base_url' => 'https://awesome.api/v1',
'commands' => [
'getMovie' => [
'verb' => 'get',
'url' => "/movies/{:?}"
],
]
];
$movie = Lingo::awesomeApi()->command('getMovie',1)->send();
echo $movie->name; // Batman v Superman: Dawn of Justice
protected $headers = [
'DomainId' => 15,
'SafeMode' => 'Unguarded'
];
Lingo::awesomeApi()
->command('getMovie',1)
->withHeaders(['Scope' => 'readOnly'])
->send();
protected $params = [
'start' => '2020-02-02',
'end' => '2020-04-04'
];
Lingo::awesomeApi()
->command('getMovie',1)
->withParams(['user_id' => 1])
->send();
protected $data = [
'username' => 'superuser',
'email' => '[email protected] '
];
Lingo::awesomeApi()
->command('getMovie',1)
->withData(['user_id' => 1])
->send();
'commands' => [
...
'list' => [
'function' => 'getCommandList'
],
...
];
...
protected function getCommandList($bindings)
{
foreach ($this->sync['commands'] as $command) {
if ( isset($command['verb']) && isset($command['url']) ){
echo strtoupper($command['verb']) . " " . $command['url'] . PHP_EOL;
}
}
}
...
Lingo::awesomeApi()->command('list')->send();
// GET /peoples
// POST /peoples
// GET peoples/{:?}
// PUT peoples/{:?}
// DELETE peoples/{:?}
protected $sync = [
'base_url' => 'https://protected.rest/v1',
'auth' => [
'apiKeys' => [
'my-key' => 'my-secret'
]
],
'commands' => [
...
]
];
protected $sync = [
'base_url' => 'https://protected.rest',
'auth' => [
'oauth2' => [
'url' => '/oauth/token',
'grant_type' => 'client_credentials',
'client_id' => 'my-client-id',
'client_secret' => 'my-client-secret'
]
],
'commands' => [
...
]
];
protected $sync = [
'base_url' => 'https://service.rest/v1',
'commands' => [
'getMovie' => [
'verb' => 'get',
'url' => "/movies/{:?}",
'shouldReturn' => [
'id' => 1
'name' => 'static name',
'genre' => 'drama',
'length' => 97
]
],
]
];
...
$movie = Lingo::awesomeApi()->command('getMovie',1)->send();
echo $movie->name; // static name
$movie = Lingo::awesomeApi()->command('getMovie',1)->withMockup(true)->send();
echo $movie->name; // static name
protected $sync = [
'base_url' => 'https://service.rest/v1',
'commands' => [
'getMovie' => [
'verb' => 'get',
'url' => "/movies/{:?}",
'mockup' => 'function',
'shouldReturn' => 'makeMovie'
],
]
];
...
protected function makeMovie($bindings)
{
$faker = \Faker\Factory::create();
return (object)[
'id' => $bindings[0],
'name' => $faker->name,
'length' => $faker->numberBetween(90,180)
];
}
...
$movie = Lingo::awesomeApi()->command('getMovie',1)->send();
echo $movie->name; // name generated by faker
protected $async = [
'queue' => 'myqueue',
'commands' => [
'sendEmail' => [
'action' => 'SendEmail'
]
]
];
Lingo::awesomeApi()->command('sendEmail')
->withData($data)
->async()
->send();
[
'action' => 'sendEmail',
'data' => $data
]
php artisan make:lingo AwesomeApi --base_url=https://awesome.api/v1