Skip to content

Commit

Permalink
Merge pull request #1 from Shipu/master
Browse files Browse the repository at this point in the history
Fixed Misspelling Variable Name, Error Response Handling and Personal Token Support
  • Loading branch information
nahid authored Mar 30, 2017
2 parents 5bf4627 + c030903 commit 65e4125
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions config/envato.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
'client_secret' => 'envato_app_client_secret',

'redirect_uri' => 'redirect_uri',

'use_personal_token' => false,

'personal_token' => 'envato_personal_token',

/*
* you can set any name for this purpose.
Expand Down
22 changes: 16 additions & 6 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ abstract class AbstractApi
protected $config;
protected $clientId;
protected $clientSecret;
//protected $personalToken;
protected $personalToken;
protected $enablePersonalToken;
protected $redirectUri;
private $requestMethods = [
'GET',
Expand All @@ -32,8 +33,9 @@ function __construct()
{
$this->clientId = $this->config['client_id'];
$this->clientSecret = $this->config['client_secret'];
//$this->personalToken = $this->config['personal_token'];
$this->personalToken = $this->config['personal_token'];
$this->redirectUri = $this->config['redirect_uri'];
$this->enablePersonalToken = $this->config['use_personal_token'];

$this->client = new RequestHandler();
$this->session = new SessionInstance($this->config['app_name']);
Expand Down Expand Up @@ -86,7 +88,7 @@ public function makeMethodRequest($method, $uri)
$this->parameters['timeout'] = 60;
$defaultHeaders = [
'User-Agent'=>$_SERVER['HTTP_USER_AGENT'],
'Authorization'=> 'Bearer ' . $this->session->get('access_token')
'Authorization'=> 'Bearer ' . ($this->enablePersonalToken ? $this->personalToken : $this->session->get('access_token'))
];

if ($method == 'GET') {
Expand All @@ -99,9 +101,17 @@ public function makeMethodRequest($method, $uri)
}


$response = new Response($this->client->http->request($method, $uri, $this->parameters));

return $response;
try {
return $response = new Response($this->client->http->request($method, $uri, $this->parameters));
} catch (RequestException $e) {
return $e->getResponse();
} catch (ClientException $e) {
return $e->getResponse();
} catch (BadResponseException $e) {
return $e->getResponse();
} catch (ServerException $e) {
return $e->getResponse();
}
}

}
2 changes: 1 addition & 1 deletion src/Api/Me.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function buyerPurchase($code)
public function statements($page=1, $fromDate=null, $toDate=null, $type=null, $site=null)
{
$args = 'page=' . $page;
$args .= !is_null($fromDate)?'&from_date=' . $from_date:'';
$args .= !is_null($fromDate)?'&from_date=' . $fromDate:'';
$args .= !is_null($toDate)?'&to_date=' . $toDate:'';
$args .= !is_null($type)?'&type=' . $type:'';
$args .= !is_null($site)?'&site=' . $site:'';
Expand Down

0 comments on commit 65e4125

Please sign in to comment.