Skip to content

Commit 34261c8

Browse files
pulkitpulkitjalan
authored andcommitted
added client for google client and support compute engine auth
1 parent d710c6e commit 34261c8

File tree

14 files changed

+650
-5
lines changed

14 files changed

+650
-5
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/bootstrap/compiled.php
2-
.env.*.php
3-
.env.php
1+
/vendor
2+
composer.lock
3+
.DS_Store
4+
/build

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sudo: false
2+
language: php
3+
4+
php:
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- travis_retry composer self-update
12+
- travis_retry composer install --no-interaction --prefer-source --dev
13+
14+
script:
15+
- phpunit --coverage-text --coverage-clover=coverage.clover
16+
17+
after_script:
18+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi;'
19+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi;'

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Pulkit Jalan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,141 @@
1-
# laravel-google-api-client
2-
(WIP) Laravel wrapper for the Google api php client
1+
Google Api Client Wrapper
2+
=========
3+
4+
> Google api php client wrapper with Cloud Platform and Laravel support
5+
6+
[![Build Status](http://img.shields.io/travis/pulkitjalan/google-apiclient.svg?style=flat-square)](https://travis-ci.org/pulkitjalan/google-apiclient)
7+
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/pulkitjalan/google-apiclient/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/pulkitjalan/google-apiclient/)
8+
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/pulkitjalan/google-apiclient/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/pulkitjalan/google-apiclient/code-structure/master)
9+
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://www.opensource.org/licenses/MIT)
10+
[![Latest Version](http://img.shields.io/packagist/v/pulkitjalan/google-apiclient.svg?style=flat-square)](https://packagist.org/packages/pulkitjalan/google-apiclient)
11+
[![Total Downloads](https://img.shields.io/packagist/dt/pulkitjalan/google-apiclient.svg?style=flat-square)](https://packagist.org/packages/pulkitjalan/google-apiclient)
12+
13+
## Requirements
14+
15+
This package requires PHP >=5.4
16+
17+
## Installation
18+
19+
Install via composer - edit your `composer.json` to require the package.
20+
21+
```js
22+
"require": {
23+
"pulkitjalan/google-apiclient": "dev-master"
24+
}
25+
```
26+
27+
Then run `composer update` in your terminal to pull it in.
28+
29+
## Laravel
30+
31+
To use in laravel add the following to the `providers` array in your `config/app.php`
32+
33+
```php
34+
'PulkitJalan\Google\GoogleServiceProvider'
35+
```
36+
37+
Next add the following to the `aliases` array in your `config/app.php`
38+
39+
```php
40+
'Google' => 'PulkitJalan\Google\Facades\Google'
41+
```
42+
43+
Finally run `php artisan config:publish pulkitjalan/google-apiclient` to publish the config file.
44+
45+
## Usage
46+
47+
The `Client` class takes an array as the first parameter, see example of config file below:
48+
49+
```php
50+
return [
51+
/*
52+
|----------------------------------------------------------------------------
53+
| Google application name
54+
|----------------------------------------------------------------------------
55+
*/
56+
'application_name' => '',
57+
58+
/*
59+
|----------------------------------------------------------------------------
60+
| Google OAuth 2.0 access
61+
|----------------------------------------------------------------------------
62+
|
63+
| Keys for OAuth 2.0 access, see the API console at
64+
| https://developers.google.com/console
65+
|
66+
*/
67+
'client_id' => '',
68+
'client_secret' => '',
69+
'redirect_uri' => '',
70+
'scopes' => [],
71+
'access_type' => 'online',
72+
'approval_prompt' => 'auto',
73+
74+
/*
75+
|----------------------------------------------------------------------------
76+
| Google developer key
77+
|----------------------------------------------------------------------------
78+
|
79+
| Simple API access key, also from the API console. Ensure you get
80+
| a Server key, and not a Browser key.
81+
|
82+
*/
83+
'developer_key' => '',
84+
85+
/*
86+
|----------------------------------------------------------------------------
87+
| Google service account
88+
|----------------------------------------------------------------------------
89+
|
90+
| Set the information below to use assert credentials
91+
| Leave blank to use app engine or compute engine.
92+
|
93+
*/
94+
'service' => [
95+
/*
96+
97+
*/
98+
'account' => '',
99+
100+
/*
101+
| Example ['https://www.googleapis.com/auth/cloud-platform']
102+
*/
103+
'scopes' => [],
104+
105+
/*
106+
| Path to key file
107+
| Example storage_path().'/key/google.p12'
108+
*/
109+
'key' => '',
110+
]
111+
];
112+
```
113+
114+
To use the Google Cloud Platform Services you can either set the information in the config file under `service`, or if running under compute engine (or app engine) leave it blank.
115+
116+
`NOTE: service => ['account'] is the service Email Address and not the Client ID!`
117+
118+
Get `Google_Client`
119+
```php
120+
$client = new PulkitJalan\Google\Client($config);
121+
$googleClient = $client->getClient();
122+
```
123+
124+
Laravel Example:
125+
```php
126+
$googleClient = Google::getClient();
127+
```
128+
129+
Get a service
130+
```php
131+
$client = new PulkitJalan\Google\Client($config);
132+
133+
// returns instance of \Google_Service_Storage
134+
$storage = $client->make('storage');
135+
136+
// list buckets example
137+
$storage->buckets->listBuckets('project id');
138+
139+
// get object example
140+
$storage->objects->get('bucket', 'object');
141+
```

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "pulkitjalan/google-apiclient",
3+
"description": "Google api php client wrapper with Cloud Platform and Laravel support",
4+
"homepage": "https://github.com/pulkitjalan/google-apiclient",
5+
"keywords": ["laravel", "google", "cloud platform"],
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Pulkit Jalan"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.4.0",
14+
"illuminate/support": "~4|~5",
15+
"google/apiclient": "dev-master"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "4.*",
19+
"mockery/mockery": "0.9.*"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"PulkitJalan\\Google\\": "src/"
24+
}
25+
},
26+
"minimum-stability": "dev",
27+
"prefer-stable": true
28+
}

phpunit.xml.dist

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Google Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
<exclude>
21+
<file>src/Laravel/GoogleServiceProvider.php</file>
22+
<directory suffix=".php">src/Laravel/config/</directory>
23+
<directory suffix=".php">src/Laravel/Facades/</directory>
24+
</exclude>
25+
</whitelist>
26+
</filter>
27+
<logging>
28+
<log type="tap" target="build/report.tap"/>
29+
<log type="junit" target="build/report.junit.xml"/>
30+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
31+
<log type="coverage-text" target="build/coverage.txt"/>
32+
<log type="coverage-clover" target="build/logs/clover.xml"/>
33+
</logging>
34+
</phpunit>

scrutinizer.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
checks:
4+
php:
5+
code_rating: true
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true
19+
tools:
20+
external_code_coverage:
21+
timeout: 1800
22+
runs: 3
23+
php_code_coverage: false
24+
php_code_sniffer:
25+
config:
26+
standard: PSR2
27+
filter:
28+
paths: ['src']
29+
php_loc:
30+
enabled: true
31+
excluded_dirs: [vendor, tests]
32+
php_cpd:
33+
enabled: true
34+
excluded_dirs: [vendor, tests]

0 commit comments

Comments
 (0)