Skip to content

Commit

Permalink
Tidy use statements. Fix typos in param names. Fix Exception usage an…
Browse files Browse the repository at this point in the history
…d don't throw an abstract Exception class. Use parameters passed in to ::sendRequest.
  • Loading branch information
Daniel committed Nov 27, 2016
1 parent d2d5f9e commit 76944eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/core/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class HttpClient {
protected $responseHttpStatusCode = 0;

/**
* @var \GuzzleHttp\Client The Guzzle client
* @var Client The Guzzle client
*/
protected $guzzleClient;

/**
* @param \GuzzleHttp\Client|null The Guzzle client
* @param Client|null The Guzzle client
*/
public function __construct($guzzleClient) {
$this->guzzleClient = $guzzleClient;
Expand Down Expand Up @@ -71,9 +71,9 @@ public function getResponseHttpStatusCode() {
* @param string $method The request method
* @param array $bodyParameters The key value pairs to be sent in the body
*
* @return response from the server
* @return object - response from the server
*
* @throws \Viagogo\ViagogoException
* @throws \Viagogo\Exceptions\ViagogoException
*/
public function send($url, $method = 'GET', $queryParameters = array(), $bodyParameters = array()) {
$options = array();
Expand Down
16 changes: 6 additions & 10 deletions src/core/OAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Viagogo\Core;

use GuzzleHttp\Client;
use Viagogo\Exceptions\ViagogoException;

/**
*
Expand All @@ -26,32 +25,29 @@ public function getClientAccessToken($scopes = "") {
return $this->sendRequest($this->url, "POST", $params);
}

public function getPasswordAccessToken($login, $passowrd, $scopes) {
public function getPasswordAccessToken($login, $password, $scopes) {
$params = [
'grant_type' => 'password',
'username' => $login,
'password' => $passowrd,
'password' => $password,
'scope' => $scopes,
];

$token = $this->httpClient->send($this->url, "POST", null, $params);

return $this->sendRequest($this->url, "POST", $params);
}

public function getRefreshToken($refeshToken = "") {
public function getRefreshToken($refreshToken = "") {
$params = [
'grant_type' => 'refresh_token',
'refresh_token' => $refeshToken,
'refresh_token' => $refreshToken,
];

return $this->sendRequest($this->url, "POST", $params);
}

private function sendRequest($url, $method, $params) {
$token = $this->httpClient->send($this->url, "POST", null, $params);
$token = $this->httpClient->send($url, $method, null, $params);
if (isset($token->error)) {
throw new ViagogoException($token->error . "\n" . $token->error_description, 1);
throw new \Exception($token->error . "\n" . $token->error, 1);
}

return new OAuthToken($token);
Expand Down

0 comments on commit 76944eb

Please sign in to comment.