From 1fba889f6d5ab8320a25855448a4135d3cd9004b Mon Sep 17 00:00:00 2001 From: David Regimbal Date: Tue, 9 May 2023 22:51:58 -0400 Subject: [PATCH] add support for auth claims. --- README.md | 15 ++++++++++++ src/Auth.php | 46 +++++++++++++++++++++++++++++++++++ src/HttpService.php | 2 +- src/Models/ClaimsResponse.php | 21 ++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/Auth.php create mode 100644 src/Models/ClaimsResponse.php diff --git a/README.md b/README.md index 94d24a4..c0ec1c8 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,21 @@ print_r($client->get('account')); ?> ``` +Making a Claims Request +---------- + +```php +claim('CODE_VALUE'); +?> +``` + Optional Parameters ---------- ```php diff --git a/src/Auth.php b/src/Auth.php new file mode 100644 index 0000000..d7525aa --- /dev/null +++ b/src/Auth.php @@ -0,0 +1,46 @@ +publicKey = $publicKey; + parent::__construct([ + 'base_uri' => $this->baseUrl, + ]); + } + + /** + * @throws GuzzleException + */ + public function claim(string $code): ClaimsResponse + { + $options = [ + 'headers' => [ + 'Accept' => 'application/json', + ], + 'json' => [ + 'code' => $code, + 'app_key' => $this->publicKey, + ], + ]; + + $request = $this->request('POST', 'claim', $options); + + return new ClaimsResponse((string) $request->getBody()); + } + + public function getLoginUrl(): string + { + return "https://xbl.io/app/auth/{$this->publicKey}"; + } +} diff --git a/src/HttpService.php b/src/HttpService.php index 8be0957..7269e7e 100644 --- a/src/HttpService.php +++ b/src/HttpService.php @@ -73,6 +73,6 @@ protected function request(): ?string $request = $this->client->request($this->method, $this->endpoint, $options); - return $request->getBody()->getContents(); + return (string) $request->getBody(); } } diff --git a/src/Models/ClaimsResponse.php b/src/Models/ClaimsResponse.php new file mode 100644 index 0000000..7d486ff --- /dev/null +++ b/src/Models/ClaimsResponse.php @@ -0,0 +1,21 @@ + $value) { + if (property_exists(__CLASS__, $key)) { + $this->$key = $value; + } + } + } +}