Skip to content

Commit fa0f331

Browse files
committed
improve documentation + add response helper
1 parent 9bd550e commit fa0f331

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ php artisan vendor:publish --tag="odds-api-config"
3434
```
3535

3636
### Example Usages
37-
You can simply create a new Client, passing in your api key and thats it!
37+
You can simply create a new Client, passing in your api key and that's it! You can decide to bind the class in
38+
your `AppServiceProvider`, but if not, the client can easily be initialised in any `__invoke` or `__construct`
3839
```php
3940
$client = new OddsClient(config('odds-api.api_key'));
4041

@@ -45,9 +46,8 @@ $response = $client->setRegion('us')
4546
return $response->json();
4647
```
4748

48-
This package is setup in a way that all the params you may need are functions which can be chained together on one
49-
line, as they all return `$this`. Once you call one of the API endpoints which return a response, you can no longer call
50-
these functions.
49+
This package is set up in a way that all the params you need can be built using chainable function helpers, as they all return `$this`.
50+
Once you call one of the API endpoints which return a response, you can no longer call these function helpers.
5151

5252
**Another way to define your Client Class**
5353

@@ -60,12 +60,14 @@ $this->app->bind(OddsClient::class, function () {
6060
```
6161
then your class may look like
6262
```php
63+
use HandlesOddsResponse;
64+
6365
public function __invoke(OddsClient $client): Response
6466
{
6567
$response = $client->setRegion('us')
6668
->getOddsForSport(SportsEnum::RUGBYLEAGUE_NRL);
6769

68-
return $response->json();
70+
return $this->extractJsonFromResponse($response);
6971
}
7072
```
7173

src/Traits/HandlesOddsResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace SethSharp\OddsApi\Traits;
4+
5+
use GuzzleHttp\Psr7\Response;
6+
7+
trait HandlesOddsResponse
8+
{
9+
protected function extractJsonFromResponse(Response $response): mixed
10+
{
11+
return json_decode($response->getBody(), true);
12+
}
13+
}

0 commit comments

Comments
 (0)