Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow caching of authorization request #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Client
*/
public function __construct($accountId, $applicationKey, array $options = [])
{

$this->accountId = $accountId;
$this->applicationKey = $applicationKey;

Expand All @@ -34,8 +35,15 @@ public function __construct($accountId, $applicationKey, array $options = [])
} else {
$this->client = new HttpClient(['exceptions' => false]);
}

if(!empty($options['authorization'])){
$this->authToken = $options['authorization']['authToken'];
$this->apiUrl = $options['authorization']['apiUrl'];
$this->downloadUrl = $options['authorization']['downloadUrl'];
} else {
$this->authorizeAccount();
}

$this->authorizeAccount();
}

/**
Expand Down Expand Up @@ -399,6 +407,22 @@ public function deleteFile(array $options)

return true;
}

/**
* Retrieve authorization details from connection
*
* @return array
*/
public function getAuthorization()
{

return [
'authToken' => $this->authToken,
'apiUrl' => $this->apiUrl,
'downloadUrl' => $this->downloadUrl
];

}

/**
* Authorize the B2 account in order to get an auth token and API/download URLs.
Expand Down