Skip to content

Commit

Permalink
Use namespaces from apiclient 2.8 (#57)
Browse files Browse the repository at this point in the history
* PHP8 version bumps
Bump min google/apiclient for php 8 support
Drops support for Laravel below 6.0
Update date travis coverage

* Use Namespaced Google Services over underscore

* StyleCi

* Readme updates
  • Loading branch information
dpslwk committed Feb 16, 2022
1 parent 5662f12 commit 36b8faa
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
36 changes: 24 additions & 12 deletions .travis.yml
Expand Up @@ -7,18 +7,6 @@ cache:
matrix:
fast_finish: true
include:
- php: 7.2
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.2
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.3
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.3
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.4
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.4
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.2
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.2
Expand All @@ -31,6 +19,10 @@ matrix:
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.4
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-stable'
- php: 8.0
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 8.0
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.2
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.2
Expand All @@ -43,6 +35,26 @@ matrix:
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.4
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-stable'
- php: 8.0
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 8.0
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.2
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.2
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.3
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.3
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
- php: 7.4
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 7.4
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
- php: 8.0
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
- php: 8.0
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'

before_install:
- travis_retry composer self-update
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -41,7 +41,7 @@ Finally run `php artisan vendor:publish --provider="PulkitJalan\Google\GoogleSer

#### Using an older version of PHP / Laravel?

If you are on a PHP version below 7.2 or a Laravel version below 5.8 just use an older version of this package.
If you are on a PHP version below 7.2 or a Laravel version below 6.0 just use an older version of this package.

## Usage

Expand Down Expand Up @@ -114,7 +114,7 @@ From [Google's upgrading document](https://github.com/google/google-api-php-clie
> Note: P12s are deprecated in favor of service account JSON, which can be generated in the Credentials section of Google Developer Console.

Get `Google_Client`
Get `Google\Client`
```php
$client = new PulkitJalan\Google\Client($config);
$googleClient = $client->getClient();
Expand All @@ -129,7 +129,7 @@ Get a service
```php
$client = new PulkitJalan\Google\Client($config);

// returns instance of \Google_Service_Storage
// returns instance of \Google\Service\Storage
$storage = $client->make('storage');

// list buckets example
Expand All @@ -141,7 +141,7 @@ $storage->objects->get('bucket', 'object');

Laravel Example:
```php
// returns instance of \Google_Service_Storage
// returns instance of \Google\Service\Storage
$storage = Google::make('storage');

// list buckets example
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -15,11 +15,11 @@
],
"require": {
"php": "^7.2|^8.0",
"illuminate/support": "^5.8|^6.0|^7.0|^8.0",
"google/apiclient": "^2.4"
"illuminate/support": "^6.0|^7.0|^8.0",
"google/apiclient": "^2.9"
},
"require-dev": {
"phpunit/phpunit": "^8.3",
"phpunit/phpunit": "^9.3",
"mockery/mockery": "^1.2.3"
},
"autoload": {
Expand Down
32 changes: 15 additions & 17 deletions src/Client.php
Expand Up @@ -2,8 +2,8 @@

namespace PulkitJalan\Google;

use Google_Client;
use Illuminate\Support\Arr;
use Google\Client as GoogleClient;
use PulkitJalan\Google\Exceptions\UnknownServiceException;

class Client
Expand All @@ -14,20 +14,20 @@ class Client
protected $config;

/**
* @var \Google_Client
* @var Google\Client
*/
protected $client;

/**
* @param array $config
* @param string $userEmail
* @param array $config
* @param string $userEmail
*/
public function __construct(array $config, $userEmail = '')
{
$this->config = $config;

// create an instance of the google client for OAuth2
$this->client = new Google_Client(Arr::get($config, 'config', []));
$this->client = new GoogleClient(Arr::get($config, 'config', []));

// set application name
$this->client->setApplicationName(Arr::get($config, 'application_name', ''));
Expand All @@ -52,7 +52,7 @@ public function __construct(array $config, $userEmail = '')
/**
* Getter for the google client.
*
* @return \Google_Client
* @return Google\Client
*/
public function getClient()
{
Expand All @@ -62,11 +62,10 @@ public function getClient()
/**
* Setter for the google client.
*
* @param string $client
*
* @param string $client
* @return self
*/
public function setClient(Google_Client $client)
public function setClient(GoogleClient $client)
{
$this->client = $client;

Expand All @@ -76,15 +75,14 @@ public function setClient(Google_Client $client)
/**
* Getter for the google service.
*
* @param string $service
* @param string $service
* @return \Google_Service
*
* @throws \Exception
*
* @return \Google_Service
*/
public function make($service)
{
$service = 'Google_Service_'.ucfirst($service);
$service = 'Google\\Service\\'.ucfirst($service);

if (class_exists($service)) {
$class = new \ReflectionClass($service);
Expand Down Expand Up @@ -114,6 +112,7 @@ protected function auth($userEmail = '')

/**
* Determine and use credentials if user has set them.
*
* @param $userEmail
* @return bool used or not
*/
Expand All @@ -137,12 +136,11 @@ protected function useAssertCredentials($userEmail = '')
/**
* Magic call method.
*
* @param string $method
* @param array $parameters
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*
* @return mixed
*/
public function __call($method, $parameters)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientTest.php
Expand Up @@ -16,7 +16,7 @@ public function testClientGetter()
{
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();

$this->assertInstanceOf('Google_Client', $client->getClient());
$this->assertInstanceOf('Google\Client', $client->getClient());
}

public function testClientGetterWithAdditionalConfig()
Expand All @@ -34,7 +34,7 @@ public function testServiceMake()
{
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();

$this->assertInstanceOf('Google_Service_Storage', $client->make('storage'));
$this->assertInstanceOf('Google\Service\Storage', $client->make('storage'));
}

public function testServiceMakeException()
Expand Down

0 comments on commit 36b8faa

Please sign in to comment.