Skip to content

Commit

Permalink
allow additional config to be passed through to client
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkitjalan committed Apr 23, 2017
1 parent 0e71c68 commit 36a3484
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(array $config, $userEmail = '')
$this->config = $config;

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

// set application name
$this->client->setApplicationName(array_get($config, 'application_name', ''));
Expand Down Expand Up @@ -62,7 +62,7 @@ public function getClient()
* Setter for the google client.
*
* @param string $client
*
*
* @return self
*/
public function setClient(Google_Client $client)
Expand Down Expand Up @@ -126,7 +126,7 @@ protected function useAssertCredentials($userEmail = '')

$this->client->setAuthConfig($serviceJsonUrl);

if ($userEmail) {
if (! empty($userEmail)) {
$this->client->setSubject($userEmail);
}

Expand Down
14 changes: 14 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@
*/
'file' => env('GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION', '')
],

/*
|----------------------------------------------------------------------------
| Additional config for the Google Client
|----------------------------------------------------------------------------
|
| Set any additional config variables supported by the Google Client
| Details can be found here:
| https://github.com/google/google-api-php-client/blob/master/src/Google/Client.php
|
| NOTE: If client id is specified here, it will get over written by the one above.
|
*/
'config' => [],
];
11 changes: 11 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public function testClientGetter()
$this->assertInstanceOf('Google_Client', $client->getClient());
}

public function testClientGetterWithAdditionalConfig()
{
$client = Mockery::mock('PulkitJalan\Google\Client', [[
'config' => [
'subject' => 'test',
],
]])->makePartial();

$this->assertEquals($client->getClient()->getConfig('subject'), 'test');
}

public function testServiceMake()
{
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();
Expand Down

0 comments on commit 36a3484

Please sign in to comment.