From 2016a31c341f35957bc6e1ffdf876cd350571fa2 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 10 Feb 2015 02:21:03 +0100 Subject: [PATCH] Client token --- app/config.yml | 3 -- src/Api/Client.php | 31 ++++++++++--- src/Console/Command/.AuthLoginCommand.php.swp | Bin 12288 -> 0 bytes src/Console/Command/AuthCommand.php | 41 ------------------ 4 files changed, 25 insertions(+), 50 deletions(-) delete mode 100644 app/config.yml delete mode 100644 src/Console/Command/.AuthLoginCommand.php.swp delete mode 100644 src/Console/Command/AuthCommand.php diff --git a/app/config.yml b/app/config.yml deleted file mode 100644 index 21229e7..0000000 --- a/app/config.yml +++ /dev/null @@ -1,3 +0,0 @@ -auth: - uid: - token: diff --git a/src/Api/Client.php b/src/Api/Client.php index e7be74e..7431dcf 100644 --- a/src/Api/Client.php +++ b/src/Api/Client.php @@ -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) { diff --git a/src/Console/Command/.AuthLoginCommand.php.swp b/src/Console/Command/.AuthLoginCommand.php.swp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aav!L!a8bAtX~>KBQl diff --git a/src/Console/Command/AuthCommand.php b/src/Console/Command/AuthCommand.php deleted file mode 100644 index b8d8990..0000000 --- a/src/Console/Command/AuthCommand.php +++ /dev/null @@ -1,41 +0,0 @@ -setName('auth:login') - ->setDescription('Login on t411') - ->setHelp("The %command.name% "); - } - - 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; - } - } - } -}