Skip to content

Instantly share code, notes, and snippets.

@sr2ds
Created April 10, 2019 12:30
Show Gist options
  • Save sr2ds/a55e55c59286ccf13d5ae46b6b4a9e12 to your computer and use it in GitHub Desktop.
Save sr2ds/a55e55c59286ccf13d5ae46b6b4a9e12 to your computer and use it in GitHub Desktop.
Manage BlackList Mercado Livre with Laravel 4.2 Command
<?php
namespace \Commands\MercadoLivre;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* MLBlackListCommand
* @author David Silva <https://github.com/sr2ds>
* --------------------------------------------------------------------------
*
* @example artisan mercadolivre:blacklist
*
**/
class MLBlackListCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'mercadolivre:blacklist {customer_id?} ';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Return blacklist users, insert cust_id to block one user';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
// Depend: https://github.com/mercadolibre/php-sdk/blob/master/Meli/meli.php
$ml = new \MercadoLivreService();
$customer_id = $this->argument('customer_id');
if (isset($customer_id)) {
$response = $order_blacklist = $ml->post('users/{your_cust_id}/order_blacklist',
['user_id' => $customer_id],
['access_token' => \MercadoLivre::first()->access_token]
);
} else {
$response = $ml->get('users/{your_cust_id}/order_blacklist', [
'access_token' => \MercadoLivre::first()->access_token,
]);
}
$this->info(json_encode($response));
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['customer_id', InputArgument::OPTIONAL, 'cust_id for block user'],
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment