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; + } + } + } +}