Client token

This commit is contained in:
Simon Vieille 2015-02-10 02:21:03 +01:00
parent 553e8e871c
commit 2016a31c34
4 changed files with 25 additions and 50 deletions

View file

@ -1,3 +0,0 @@
auth:
uid:
token:

View file

@ -9,6 +9,8 @@ class Client
{
protected $client;
protected $token;
public function __construct()
{
$this->client = new GuzzleClient(array('base_url' => 'https://api.t411.me'));
@ -17,6 +19,7 @@ class Client
public function getAuthorization($username, $password)
{
return $this->post(
false,
'/auth',
array(
'body' => array(
@ -27,23 +30,39 @@ class Client
);
}
public function setAuthorization($token)
{
$this->token = $token;
}
public function getCategoriesTree()
{
return $this->get('/categories/tree');
return $this->get(true, '/categories/tree');
}
public function get($uri, array $options = array())
public function get($needAuthorization, $uri, array $options = array())
{
return $this->send('get', $uri, $options);
return $this->send($needAuthorization, 'get', $uri, $options);
}
public function post($uri, array $options = array())
public function post($needAuthorization, $uri, array $options = array())
{
return $this->send('post', $uri, $options);
return $this->send($needAuthorization, 'post', $uri, $options);
}
protected function send($method, $uri, $options)
protected function send($needAuthorization, $method, $uri, $options)
{
if ($needAuthorization) {
$options = array_merge(
$options,
array(
'headers' => array(
'Authorization' => $this->token,
),
)
);
}
try {
return new ClientResponse($this->client->{$method}($uri, $options));
} catch (RequestException $e) {

View file

@ -1,41 +0,0 @@
<?php
namespace Console\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
class AuthCommand extends Command
{
protected function configure()
{
$this
->setName('auth:login')
->setDescription('Login on t411')
->setHelp("The <info>%command.name%</info> ");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$configLoader = new ConfigLoader();
if ($configLoader->configExists()) {
$continue = $dialog->askConfirmation(
$output,
$dialog->getQuestion(
'The configuration file already exists. Do you want to continue',
'yes',
'?'
),
true
);
if (!$continue) {
$output->writeln('Aborded.');
return;
}
}
}
}