Skip to content

Commit

Permalink
feat: Added Google Books GoogleApi accessor with get and list volumes…
Browse files Browse the repository at this point in the history
… methods.
  • Loading branch information
tomshaw committed Apr 18, 2024
1 parent f8d3d1f commit 82e926b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
'service_scopes' => [
Google\Service\Calendar::CALENDAR,
Google\Service\Gmail::GMAIL_SEND,
Google\Service\Books::BOOKS,
],
];
10 changes: 8 additions & 2 deletions src/GoogleApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace TomShaw\GoogleApi;

use TomShaw\GoogleApi\Api\GoogleCalendar;
use TomShaw\GoogleApi\Api\GoogleMail;
use TomShaw\GoogleApi\Resources\GoogleBooks;
use TomShaw\GoogleApi\Resources\GoogleCalendar;
use TomShaw\GoogleApi\Resources\GoogleMail;

class GoogleApiManager
{
public function books(): GoogleBooks
{
return new GoogleBooks(app(GoogleClient::class));
}

public function gmail(): GoogleMail
{
return new GoogleMail(app(GoogleClient::class));
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Google\Client;
use Illuminate\Support\Facades\Validator;
use TomShaw\GoogleApi\Exceptions\GoogleClientException;
use TomShaw\GoogleApi\Http\Resources\AccessTokenResource;
use TomShaw\GoogleApi\Models\StorageCollection;
use TomShaw\GoogleApi\Resources\AccessTokenResource;
use TomShaw\GoogleApi\Storage\StorageAdapterInterface;

class GoogleClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TomShaw\GoogleApi\Resources;
namespace TomShaw\GoogleApi\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
Expand Down
28 changes: 28 additions & 0 deletions src/Resources/GoogleBooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace TomShaw\GoogleApi\Resources;

use Google\Service\Books;
use Google\Service\Books\Volume;
use Google\Service\Books\Volumes;
use TomShaw\GoogleApi\GoogleClient;

final class GoogleBooks
{
protected Books $service;

public function __construct(protected GoogleClient $client)
{
$this->service = new Books($client());
}

public function get(string $volumeId, array $optParams = []): Volume
{
return $this->service->volumes->get($volumeId, $optParams);
}

public function listVolumes(string $query, array $optParams = []): Volumes
{
return $this->service->volumes->listVolumes($query, $optParams);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TomShaw\GoogleApi\Api;
namespace TomShaw\GoogleApi\Resources;

use Carbon\Carbon;
use Google\Service\Calendar;
Expand Down
5 changes: 1 addition & 4 deletions src/Api/GoogleMail.php → src/Resources/GoogleMail.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TomShaw\GoogleApi\Api;
namespace TomShaw\GoogleApi\Resources;

use Google\Service\Gmail;
use Google\Service\Gmail\Message;
Expand All @@ -9,9 +9,6 @@
use TomShaw\GoogleApi\Exceptions\GoogleApiException;
use TomShaw\GoogleApi\GoogleClient;

/**
* Class GoogleMail
*/
final class GoogleMail
{
protected Gmail $service;
Expand Down
4 changes: 2 additions & 2 deletions tests/GoogleApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use Google\Client;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use TomShaw\GoogleApi\Api\GoogleCalendar;
use TomShaw\GoogleApi\Api\GoogleMail;
use TomShaw\GoogleApi\Resources\GoogleCalendar;
use TomShaw\GoogleApi\Resources\GoogleMail;
use TomShaw\GoogleApi\GoogleApi;
use TomShaw\GoogleApi\GoogleClient;
use TomShaw\GoogleApi\Storage\SessionStorageAdapter;
Expand Down

0 comments on commit 82e926b

Please sign in to comment.