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 deleted file mode 100644 index 7e576d6..0000000 Binary files a/src/Console/Command/.AuthLoginCommand.php.swp and /dev/null differ 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; - } - } - } -}