Google Apps Login - Version 2.8

Version Description

Session mismatch (could be a problem setting cookies) should now occur less frequently. Service Account can have no admin email (for gmail.com accounts).

Download this release

Release Info

Developer danlester
Plugin Icon 128x128 Google Apps Login
Version 2.8
Comparing to
See all releases

Code changes from version 2.7 to 2.8

Files changed (45) hide show
  1. autoload.php +34 -0
  2. core/Google/Auth/Abstract.php +2 -7
  3. core/Google/Auth/AppIdentity.php +105 -0
  4. core/Google/Auth/AssertionCredentials.php +4 -4
  5. core/Google/Auth/Exception.php +1 -1
  6. core/Google/Auth/LoginTicket.php +1 -1
  7. core/Google/Auth/OAuth2.php +66 -20
  8. core/Google/Auth/Simple.php +4 -32
  9. core/Google/Cache/Apc.php +43 -5
  10. core/Google/Cache/Exception.php +2 -1
  11. core/Google/Cache/File.php +56 -11
  12. core/Google/Cache/Memcache.php +55 -10
  13. core/Google/Cache/Null.php +1 -2
  14. core/Google/Client.php +113 -35
  15. core/Google/Collection.php +5 -3
  16. core/Google/Config.php +116 -17
  17. core/Google/Http/Batch.php +3 -5
  18. core/Google/Http/CacheParser.php +1 -1
  19. core/Google/Http/MediaFileUpload.php +15 -7
  20. core/Google/Http/REST.php +15 -7
  21. core/Google/Http/Request.php +1 -1
  22. core/Google/IO/Abstract.php +22 -15
  23. core/Google/IO/Curl.php +27 -5
  24. core/Google/IO/Exception.php +1 -1
  25. core/Google/IO/Stream.php +57 -11
  26. core/Google/Logger/Abstract.php +406 -0
  27. core/Google/Logger/Exception.php +22 -0
  28. core/Google/Logger/File.php +156 -0
  29. core/Google/Logger/Null.php +41 -0
  30. core/Google/Logger/Psr.php +91 -0
  31. core/Google/Model.php +33 -2
  32. core/Google/Service/AdExchangeBuyer.php +811 -204
  33. core/Google/Service/AdExchangeSeller.php +308 -592
  34. core/Google/Service/AdSense.php +326 -511
  35. core/Google/Service/AdSenseHost.php +194 -310
  36. core/Google/Service/Admin.php +8 -22
  37. core/Google/Service/Analytics.php +3198 -1520
  38. core/Google/Service/AndroidPublisher.php +3233 -122
  39. core/Google/Service/AppState.php +33 -39
  40. core/Google/Service/Appsactivity.php +566 -0
  41. core/Google/Service/Audit.php +41 -63
  42. core/Google/Service/Autoscaler.php +1400 -0
  43. core/Google/Service/Bigquery.php +317 -493
  44. core/Google/Service/Blogger.php +476 -514
  45. core/Google/Service/Books.php +610 -823
autoload.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Copyright 2014 Google Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ function google_api_php_client_autoload($className) {
19
+ $classPath = explode('_', $className);
20
+ if ($classPath[0] != 'GoogleGAL') { // Was Google
21
+ return;
22
+ }
23
+ if (count($classPath) > 3) {
24
+ // Maximum class file path depth in this project is 3.
25
+ $classPath = array_slice($classPath, 0, 3);
26
+ }
27
+ $classPath = str_replace('GoogleGAL', 'Google', $classPath); // Adjust back to Google's path
28
+ $filePath = dirname(__FILE__) . '/core/' . implode('/', $classPath) . '.php'; // was src -> now core
29
+ if (file_exists($filePath)) {
30
+ require_once($filePath);
31
+ }
32
+ }
33
+
34
+ spl_autoload_register('google_api_php_client_autoload');
core/Google/Auth/Abstract.php CHANGED
@@ -14,7 +14,8 @@
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
  */
17
- require_once "Google/Http/Request.php";
 
18
 
19
  /**
20
  * Abstract class for the Authentication in the API client
@@ -31,11 +32,5 @@ abstract class GoogleGAL_Auth_Abstract
31
  * @return GoogleGAL_Http_Request $request
32
  */
33
  abstract public function authenticatedRequest(GoogleGAL_Http_Request $request);
34
-
35
- abstract public function authenticate($code);
36
  abstract public function sign(GoogleGAL_Http_Request $request);
37
- abstract public function createAuthUrl($scope);
38
-
39
- abstract public function refreshToken($refreshToken);
40
- abstract public function revokeToken();
41
  }
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
  */
17
+
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
19
 
20
  /**
21
  * Abstract class for the Authentication in the API client
32
  * @return GoogleGAL_Http_Request $request
33
  */
34
  abstract public function authenticatedRequest(GoogleGAL_Http_Request $request);
 
 
35
  abstract public function sign(GoogleGAL_Http_Request $request);
 
 
 
 
36
  }
core/Google/Auth/AppIdentity.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Copyright 2014 Google Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*
19
+ * WARNING - this class depends on the Google App Engine PHP library
20
+ * which is 5.3 and above only, so if you include this in a PHP 5.2
21
+ * setup or one without 5.3 things will blow up.
22
+ */
23
+ use google\appengine\api\app_identity\AppIdentityService;
24
+
25
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
26
+
27
+ /**
28
+ * Authentication via the Google App Engine App Identity service.
29
+ */
30
+ class GoogleGAL_Auth_AppIdentity extends GoogleGAL_Auth_Abstract
31
+ {
32
+ const CACHE_PREFIX = "GoogleGAL_Auth_AppIdentity::";
33
+ private $key = null;
34
+ private $client;
35
+ private $token = false;
36
+ private $tokenScopes = false;
37
+
38
+ public function __construct(GoogleGAL_Client $client, $config = null)
39
+ {
40
+ $this->client = $client;
41
+ }
42
+
43
+ /**
44
+ * Retrieve an access token for the scopes supplied.
45
+ */
46
+ public function authenticateForScope($scopes)
47
+ {
48
+ if ($this->token && $this->tokenScopes == $scopes) {
49
+ return $this->token;
50
+ }
51
+
52
+ $cacheKey = self::CACHE_PREFIX;
53
+ if (is_string($scopes)) {
54
+ $cacheKey .= $scopes;
55
+ } else if (is_array($scopes)) {
56
+ $cacheKey .= implode(":", $scopes);
57
+ }
58
+
59
+ $this->token = $this->client->getCache()->get($cacheKey);
60
+ if (!$this->token) {
61
+ $this->token = AppIdentityService::getAccessToken($scopes);
62
+ if ($this->token) {
63
+ $this->client->getCache()->set(
64
+ $cacheKey,
65
+ $this->token
66
+ );
67
+ }
68
+ }
69
+ $this->tokenScopes = $scopes;
70
+ return $this->token;
71
+ }
72
+
73
+ /**
74
+ * Perform an authenticated / signed apiHttpRequest.
75
+ * This function takes the apiHttpRequest, calls apiAuth->sign on it
76
+ * (which can modify the request in what ever way fits the auth mechanism)
77
+ * and then calls apiCurlIO::makeRequest on the signed request
78
+ *
79
+ * @param GoogleGAL_Http_Request $request
80
+ * @return GoogleGAL_Http_Request The resulting HTTP response including the
81
+ * responseHttpCode, responseHeaders and responseBody.
82
+ */
83
+ public function authenticatedRequest(GoogleGAL_Http_Request $request)
84
+ {
85
+ $request = $this->sign($request);
86
+ return $this->client->getIo()->makeRequest($request);
87
+ }
88
+
89
+ public function sign(GoogleGAL_Http_Request $request)
90
+ {
91
+ if (!$this->token) {
92
+ // No token, so nothing to do.
93
+ return $request;
94
+ }
95
+
96
+ $this->client->getLogger()->debug('App Identity authentication');
97
+
98
+ // Add the OAuth2 header to the request
99
+ $request->setRequestHeaders(
100
+ array('Authorization' => 'Bearer ' . $this->token['access_token'])
101
+ );
102
+
103
+ return $request;
104
+ }
105
+ }
core/Google/Auth/AssertionCredentials.php CHANGED
@@ -13,12 +13,12 @@
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
 
 
 
16
  */
17
 
18
- require_once "Google/Auth/OAuth2.php";
19
- require_once "Google/Signer/P12.php";
20
- require_once "Google/Signer/PEM.php";
21
- require_once "Google/Utils.php";
22
 
23
  /**
24
  * Credentials object used for OAuth 2.0 Signed JWT assertion grants.
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
+ *
17
+ * Updated by Dan Lester 2014
18
+ *
19
  */
20
 
21
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
 
 
22
 
23
  /**
24
  * Credentials object used for OAuth 2.0 Signed JWT assertion grants.
core/Google/Auth/Exception.php CHANGED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Exception.php";
19
 
20
  class GoogleGAL_Auth_Exception extends GoogleGAL_Exception
21
  {
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
19
 
20
  class GoogleGAL_Auth_Exception extends GoogleGAL_Exception
21
  {
core/Google/Auth/LoginTicket.php CHANGED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Auth/Exception.php";
19
 
20
  /**
21
  * Class to hold information about an authenticated login.
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
19
 
20
  /**
21
  * Class to hold information about an authenticated login.
core/Google/Auth/OAuth2.php CHANGED
@@ -15,14 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Auth/Abstract.php";
19
- require_once "Google/Auth/AssertionCredentials.php";
20
- require_once "Google/Auth/Exception.php";
21
- require_once "Google/Auth/LoginTicket.php";
22
- require_once "Google/Client.php";
23
- require_once "Google/Http/Request.php";
24
- require_once "Google/Utils.php";
25
- require_once "Google/Verifier/Pem.php";
26
 
27
  /**
28
  * Authentication class that deals with the OAuth 2 web-server authentication flow
@@ -119,12 +112,15 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
119
  } else {
120
  $decodedResponse = json_decode($response->getResponseBody(), true);
121
  if ($decodedResponse != null && $decodedResponse['error']) {
122
- $decodedResponse = $decodedResponse['error'];
 
 
 
123
  }
124
  throw new GoogleGAL_Auth_Exception(
125
  sprintf(
126
  "Error fetching OAuth2 access token, message: '%s'",
127
- $decodedResponse
128
  ),
129
  $response->getResponseHttpCode()
130
  );
@@ -146,9 +142,19 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
146
  'client_id' => $this->client->getClassConfig($this, 'client_id'),
147
  'scope' => $scope,
148
  'access_type' => $this->client->getClassConfig($this, 'access_type'),
149
- 'approval_prompt' => $this->client->getClassConfig($this, 'approval_prompt'),
150
  );
151
 
 
 
 
 
 
 
 
 
 
 
 
152
  // If the list of scopes contains plus.login, add request_visible_actions
153
  // to auth URL.
154
  $rva = $this->client->getClassConfig($this, 'request_visible_actions');
@@ -184,6 +190,15 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
184
  return json_encode($this->token);
185
  }
186
 
 
 
 
 
 
 
 
 
 
187
  public function setState($state)
188
  {
189
  $this->state = $state;
@@ -218,17 +233,21 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
218
  if ($this->assertionCredentials) {
219
  $this->refreshTokenWithAssertion();
220
  } else {
 
221
  if (! array_key_exists('refresh_token', $this->token)) {
222
- throw new GoogleGAL_Auth_Exception(
223
- "The OAuth 2.0 access token has expired,"
224
- ." and a refresh token is not available. Refresh tokens"
225
- ." are not returned for responses that were auto-approved."
226
- );
 
227
  }
228
  $this->refreshToken($this->token['refresh_token']);
229
  }
230
  }
231
 
 
 
232
  // Add the OAuth2 header to the request
233
  $request->setRequestHeaders(
234
  array('Authorization' => 'Bearer ' . $this->token['access_token'])
@@ -280,6 +299,7 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
280
  }
281
  }
282
 
 
283
  $this->refreshTokenRequest(
284
  array(
285
  'grant_type' => 'assertion',
@@ -299,6 +319,14 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
299
 
300
  private function refreshTokenRequest($params)
301
  {
 
 
 
 
 
 
 
 
302
  $http = new GoogleGAL_Http_Request(
303
  self::OAUTH2_TOKEN_URI,
304
  'POST',
@@ -320,6 +348,9 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
320
  throw new GoogleGAL_Auth_Exception("Invalid token format");
321
  }
322
 
 
 
 
323
  $this->token['access_token'] = $token['access_token'];
324
  $this->token['expires_in'] = $token['expires_in'];
325
  $this->token['created'] = time();
@@ -393,7 +424,9 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
393
 
394
  /**
395
  * Retrieve and cache a certificates file.
396
- * @param $url location
 
 
397
  * @return array certificates
398
  */
399
  public function retrieveCertsFromLocation($url)
@@ -456,12 +489,13 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
456
  /**
457
  * Verifies the id token, returns the verified token contents.
458
  *
459
- * @param $jwt the token
460
  * @param $certs array of certificates
461
- * @param $required_audience the expected consumer of the token
462
  * @param [$issuer] the expected issues, defaults to Google
463
  * @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
464
- * @return token information if valid, false if not
 
465
  */
466
  public function verifySignedJwtWithCerts(
467
  $jwt,
@@ -584,4 +618,16 @@ class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
584
  // All good.
585
  return new GoogleGAL_Auth_LoginTicket($envelope, $payload);
586
  }
 
 
 
 
 
 
 
 
 
 
 
 
587
  }
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
 
 
 
 
 
 
19
 
20
  /**
21
  * Authentication class that deals with the OAuth 2 web-server authentication flow
112
  } else {
113
  $decodedResponse = json_decode($response->getResponseBody(), true);
114
  if ($decodedResponse != null && $decodedResponse['error']) {
115
+ $errorText = $decodedResponse['error'];
116
+ if (isset($decodedResponse['error_description'])) {
117
+ $errorText .= ": " . $decodedResponse['error_description'];
118
+ }
119
  }
120
  throw new GoogleGAL_Auth_Exception(
121
  sprintf(
122
  "Error fetching OAuth2 access token, message: '%s'",
123
+ $errorText
124
  ),
125
  $response->getResponseHttpCode()
126
  );
142
  'client_id' => $this->client->getClassConfig($this, 'client_id'),
143
  'scope' => $scope,
144
  'access_type' => $this->client->getClassConfig($this, 'access_type'),
 
145
  );
146
 
147
+ // Prefer prompt to approval prompt.
148
+ if ($this->client->getClassConfig($this, 'prompt')) {
149
+ $params = $this->maybeAddParam($params, 'prompt');
150
+ } else {
151
+ $params = $this->maybeAddParam($params, 'approval_prompt');
152
+ }
153
+ $params = $this->maybeAddParam($params, 'login_hint');
154
+ $params = $this->maybeAddParam($params, 'hd');
155
+ $params = $this->maybeAddParam($params, 'openid.realm');
156
+ $params = $this->maybeAddParam($params, 'include_granted_scopes');
157
+
158
  // If the list of scopes contains plus.login, add request_visible_actions
159
  // to auth URL.
160
  $rva = $this->client->getClassConfig($this, 'request_visible_actions');
190
  return json_encode($this->token);
191
  }
192
 
193
+ public function getRefreshToken()
194
+ {
195
+ if (array_key_exists('refresh_token', $this->token)) {
196
+ return $this->token['refresh_token'];
197
+ } else {
198
+ return null;
199
+ }
200
+ }
201
+
202
  public function setState($state)
203
  {
204
  $this->state = $state;
233
  if ($this->assertionCredentials) {
234
  $this->refreshTokenWithAssertion();
235
  } else {
236
+ $this->client->getLogger()->debug('OAuth2 access token expired');
237
  if (! array_key_exists('refresh_token', $this->token)) {
238
+ $error = "The OAuth 2.0 access token has expired,"
239
+ ." and a refresh token is not available. Refresh tokens"
240
+ ." are not returned for responses that were auto-approved.";
241
+
242
+ $this->client->getLogger()->error($error);
243
+ throw new GoogleGAL_Auth_Exception($error);
244
  }
245
  $this->refreshToken($this->token['refresh_token']);
246
  }
247
  }
248
 
249
+ $this->client->getLogger()->debug('OAuth2 authentication');
250
+
251
  // Add the OAuth2 header to the request
252
  $request->setRequestHeaders(
253
  array('Authorization' => 'Bearer ' . $this->token['access_token'])
299
  }
300
  }
301
 
302
+ $this->client->getLogger()->debug('OAuth2 access token expired');
303
  $this->refreshTokenRequest(
304
  array(
305
  'grant_type' => 'assertion',
319
 
320
  private function refreshTokenRequest($params)
321
  {
322
+ if (isset($params['assertion'])) {
323
+ $this->client->getLogger()->info(
324
+ 'OAuth2 access token refresh with Signed JWT assertion grants.'
325
+ );
326
+ } else {
327
+ $this->client->getLogger()->info('OAuth2 access token refresh');
328
+ }
329
+
330
  $http = new GoogleGAL_Http_Request(
331
  self::OAUTH2_TOKEN_URI,
332
  'POST',
348
  throw new GoogleGAL_Auth_Exception("Invalid token format");
349
  }
350
 
351
+ if (isset($token['id_token'])) {
352
+ $this->token['id_token'] = $token['id_token'];
353
+ }
354
  $this->token['access_token'] = $token['access_token'];
355
  $this->token['expires_in'] = $token['expires_in'];
356
  $this->token['created'] = time();
424
 
425
  /**
426
  * Retrieve and cache a certificates file.
427
+ *
428
+ * @param $url string location
429
+ * @throws GoogleGAL_Auth_Exception
430
  * @return array certificates
431
  */
432
  public function retrieveCertsFromLocation($url)
489
  /**
490
  * Verifies the id token, returns the verified token contents.
491
  *
492
+ * @param $jwt string the token
493
  * @param $certs array of certificates
494
+ * @param $required_audience string the expected consumer of the token
495
  * @param [$issuer] the expected issues, defaults to Google
496
  * @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
497
+ * @throws GoogleGAL_Auth_Exception
498
+ * @return mixed token information if valid, false if not
499
  */
500
  public function verifySignedJwtWithCerts(
501
  $jwt,
618
  // All good.
619
  return new GoogleGAL_Auth_LoginTicket($envelope, $payload);
620
  }
621
+
622
+ /**
623
+ * Add a parameter to the auth params if not empty string.
624
+ */
625
+ private function maybeAddParam($params, $name)
626
+ {
627
+ $param = $this->client->getClassConfig($this, $name);
628
+ if ($param != '') {
629
+ $params[$name] = $param;
630
+ }
631
+ return $params;
632
+ }
633
  }
core/Google/Auth/Simple.php CHANGED
@@ -15,8 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Auth/Abstract.php";
19
- require_once "Google/Http/Request.php";
20
 
21
  /**
22
  * Simple API access implementation. Can either be used to make requests
@@ -51,40 +50,13 @@ class GoogleGAL_Auth_Simple extends GoogleGAL_Auth_Abstract
51
  return $this->io->makeRequest($request);
52
  }
53
 
54
- public function authenticate($code)
55
- {
56
- throw new GoogleGAL_Auth_Exception("Simple auth does not exchange tokens.");
57
- }
58
-
59
- public function setAccessToken($accessToken)
60
- {
61
- /* noop*/
62
- }
63
-
64
- public function getAccessToken()
65
- {
66
- return null;
67
- }
68
-
69
- public function createAuthUrl($scope)
70
- {
71
- return null;
72
- }
73
-
74
- public function refreshToken($refreshToken)
75
- {
76
- /* noop*/
77
- }
78
-
79
- public function revokeToken()
80
- {
81
- /* noop*/
82
- }
83
-
84
  public function sign(GoogleGAL_Http_Request $request)
85
  {
86
  $key = $this->client->getClassConfig($this, 'developer_key');
87
  if ($key) {
 
 
 
88
  $request->setQueryParam('key', $key);
89
  }
90
  return $request;
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
19
 
20
  /**
21
  * Simple API access implementation. Can either be used to make requests
50
  return $this->io->makeRequest($request);
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  public function sign(GoogleGAL_Http_Request $request)
54
  {
55
  $key = $this->client->getClassConfig($this, 'developer_key');
56
  if ($key) {
57
+ $this->client->getLogger()->debug(
58
+ 'Simple API Access developer key authentication'
59
+ );
60
  $request->setQueryParam('key', $key);
61
  }
62
  return $request;
core/Google/Cache/Apc.php CHANGED
@@ -14,9 +14,8 @@
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
  */
17
-
18
- require_once "Google/Cache/Abstract.php";
19
- require_once "Google/Cache/Exception.php";
20
 
21
  /**
22
  * A persistent storage class based on the APC cache, which is not
@@ -28,11 +27,21 @@ require_once "Google/Cache/Exception.php";
28
  */
29
  class GoogleGAL_Cache_Apc extends GoogleGAL_Cache_Abstract
30
  {
 
 
 
 
 
31
  public function __construct(GoogleGAL_Client $client)
32
  {
33
  if (! function_exists('apc_add') ) {
34
- throw new GoogleGAL_Cache_Exception("Apc functions not available");
 
 
 
35
  }
 
 
36
  }
37
 
38
  /**
@@ -42,12 +51,26 @@ class GoogleGAL_Cache_Apc extends GoogleGAL_Cache_Abstract
42
  {
43
  $ret = apc_fetch($key);
44
  if ($ret === false) {
 
 
 
 
45
  return false;
46
  }
47
  if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) {
 
 
 
 
48
  $this->delete($key);
49
  return false;
50
  }
 
 
 
 
 
 
51
  return $ret['data'];
52
  }
53
 
@@ -56,10 +79,21 @@ class GoogleGAL_Cache_Apc extends GoogleGAL_Cache_Abstract
56
  */
57
  public function set($key, $value)
58
  {
59
- $rc = apc_store($key, array('time' => time(), 'data' => $value));
 
 
60
  if ($rc == false) {
 
 
 
 
61
  throw new GoogleGAL_Cache_Exception("Couldn't store data");
62
  }
 
 
 
 
 
63
  }
64
 
65
  /**
@@ -68,6 +102,10 @@ class GoogleGAL_Cache_Apc extends GoogleGAL_Cache_Abstract
68
  */
69
  public function delete($key)
70
  {
 
 
 
 
71
  apc_delete($key);
72
  }
73
  }
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
  */
17
+
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
19
 
20
  /**
21
  * A persistent storage class based on the APC cache, which is not
27
  */
28
  class GoogleGAL_Cache_Apc extends GoogleGAL_Cache_Abstract
29
  {
30
+ /**
31
+ * @var GoogleGAL_Client the current client
32
+ */
33
+ private $client;
34
+
35
  public function __construct(GoogleGAL_Client $client)
36
  {
37
  if (! function_exists('apc_add') ) {
38
+ $error = "Apc functions not available";
39
+
40
+ $client->getLogger()->error($error);
41
+ throw new GoogleGAL_Cache_Exception($error);
42
  }
43
+
44
+ $this->client = $client;
45
  }
46
 
47
  /**
51
  {
52
  $ret = apc_fetch($key);
53
  if ($ret === false) {
54
+ $this->client->getLogger()->debug(
55
+ 'APC cache miss',
56
+ array('key' => $key)
57
+ );
58
  return false;
59
  }
60
  if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) {
61
+ $this->client->getLogger()->debug(
62
+ 'APC cache miss (expired)',
63
+ array('key' => $key, 'var' => $ret)
64
+ );
65
  $this->delete($key);
66
  return false;
67
  }
68
+
69
+ $this->client->getLogger()->debug(
70
+ 'APC cache hit',
71
+ array('key' => $key, 'var' => $ret)
72
+ );
73
+
74
  return $ret['data'];
75
  }
76
 
79
  */
80
  public function set($key, $value)
81
  {
82
+ $var = array('time' => time(), 'data' => $value);
83
+ $rc = apc_store($key, $var);
84
+
85
  if ($rc == false) {
86
+ $this->client->getLogger()->error(
87
+ 'APC cache set failed',
88
+ array('key' => $key, 'var' => $var)
89
+ );
90
  throw new GoogleGAL_Cache_Exception("Couldn't store data");
91
  }
92
+
93
+ $this->client->getLogger()->debug(
94
+ 'APC cache set',
95
+ array('key' => $key, 'var' => $var)
96
+ );
97
  }
98
 
99
  /**
102
  */
103
  public function delete($key)
104
  {
105
+ $this->client->getLogger()->debug(
106
+ 'APC cache delete',
107
+ array('key' => $key)
108
+ );
109
  apc_delete($key);
110
  }
111
  }
core/Google/Cache/Exception.php CHANGED
@@ -14,7 +14,8 @@
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
  */
17
- require_once "Google/Exception.php";
 
18
 
19
  class GoogleGAL_Cache_Exception extends GoogleGAL_Exception
20
  {
14
  * See the License for the specific language governing permissions and
15
  * limitations under the License.
16
  */
17
+
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
19
 
20
  class GoogleGAL_Cache_Exception extends GoogleGAL_Exception
21
  {
core/Google/Cache/File.php CHANGED
@@ -15,8 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Cache/Abstract.php";
19
- require_once "Google/Cache/Exception.php";
20
 
21
  /*
22
  * This class implements a basic on disk storage. While that does
@@ -32,23 +31,37 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
32
  private $path;
33
  private $fh;
34
 
 
 
 
 
 
35
  public function __construct(GoogleGAL_Client $client)
36
  {
37
- $this->path = $client->getClassConfig($this, 'directory');
 
38
  }
39
-
40
  public function get($key, $expiration = false)
41
  {
42
  $storageFile = $this->getCacheFile($key);
43
  $data = false;
44
-
45
  if (!file_exists($storageFile)) {
 
 
 
 
46
  return false;
47
  }
48
 
49
  if ($expiration) {
50
  $mtime = filemtime($storageFile);
51
  if ((time() - $mtime) >= $expiration) {
 
 
 
 
52
  $this->delete($key);
53
  return false;
54
  }
@@ -60,6 +73,11 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
60
  $this->unlock($storageFile);
61
  }
62
 
 
 
 
 
 
63
  return $data;
64
  }
65
 
@@ -72,6 +90,16 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
72
  $data = serialize($value);
73
  $result = fwrite($this->fh, $data);
74
  $this->unlock($storageFile);
 
 
 
 
 
 
 
 
 
 
75
  }
76
  }
77
 
@@ -79,10 +107,19 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
79
  {
80
  $file = $this->getCacheFile($key);
81
  if (file_exists($file) && !unlink($file)) {
 
 
 
 
82
  throw new GoogleGAL_Cache_Exception("Cache file could not be deleted");
83
  }
 
 
 
 
 
84
  }
85
-
86
  private function getWriteableCacheFile($file)
87
  {
88
  return $this->getCacheFile($file, true);
@@ -92,7 +129,7 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
92
  {
93
  return $this->getCacheDir($file, $forWrite) . '/' . md5($file);
94
  }
95
-
96
  private function getCacheDir($file, $forWrite)
97
  {
98
  // use the first 2 characters of the hash as a directory prefix
@@ -101,26 +138,34 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
101
  $storageDir = $this->path . '/' . substr(md5($file), 0, 2);
102
  if ($forWrite && ! is_dir($storageDir)) {
103
  if (! mkdir($storageDir, 0755, true)) {
 
 
 
 
104
  throw new GoogleGAL_Cache_Exception("Could not create storage directory: $storageDir");
105
  }
106
  }
107
  return $storageDir;
108
  }
109
-
110
  private function acquireReadLock($storageFile)
111
  {
112
  return $this->acquireLock(LOCK_SH, $storageFile);
113
  }
114
-
115
  private function acquireWriteLock($storageFile)
116
  {
117
  $rc = $this->acquireLock(LOCK_EX, $storageFile);
118
  if (!$rc) {
 
 
 
 
119
  $this->delete($storageFile);
120
  }
121
  return $rc;
122
  }
123
-
124
  private function acquireLock($type, $storageFile)
125
  {
126
  $mode = $type == LOCK_EX ? "w" : "r";
@@ -135,7 +180,7 @@ class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
135
  }
136
  return true;
137
  }
138
-
139
  public function unlock($storageFile)
140
  {
141
  if ($this->fh) {
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
19
 
20
  /*
21
  * This class implements a basic on disk storage. While that does
31
  private $path;
32
  private $fh;
33
 
34
+ /**
35
+ * @var GoogleGAL_Client the current client
36
+ */
37
+ private $client;
38
+
39
  public function __construct(GoogleGAL_Client $client)
40
  {
41
+ $this->client = $client;
42
+ $this->path = $this->client->getClassConfig($this, 'directory');
43
  }
44
+
45
  public function get($key, $expiration = false)
46
  {
47
  $storageFile = $this->getCacheFile($key);
48
  $data = false;
49
+
50
  if (!file_exists($storageFile)) {
51
+ $this->client->getLogger()->debug(
52
+ 'File cache miss',
53
+ array('key' => $key, 'file' => $storageFile)
54
+ );
55
  return false;
56
  }
57
 
58
  if ($expiration) {
59
  $mtime = filemtime($storageFile);
60
  if ((time() - $mtime) >= $expiration) {
61
+ $this->client->getLogger()->debug(
62
+ 'File cache miss (expired)',
63
+ array('key' => $key, 'file' => $storageFile)
64
+ );
65
  $this->delete($key);
66
  return false;
67
  }
73
  $this->unlock($storageFile);
74
  }
75
 
76
+ $this->client->getLogger()->debug(
77
+ 'File cache hit',
78
+ array('key' => $key, 'file' => $storageFile, 'var' => $data)
79
+ );
80
+
81
  return $data;
82
  }
83
 
90
  $data = serialize($value);
91
  $result = fwrite($this->fh, $data);
92
  $this->unlock($storageFile);
93
+
94
+ $this->client->getLogger()->debug(
95
+ 'File cache set',
96
+ array('key' => $key, 'file' => $storageFile, 'var' => $value)
97
+ );
98
+ } else {
99
+ $this->client->getLogger()->notice(
100
+ 'File cache set failed',
101
+ array('key' => $key, 'file' => $storageFile)
102
+ );
103
  }
104
  }
105
 
107
  {
108
  $file = $this->getCacheFile($key);
109
  if (file_exists($file) && !unlink($file)) {
110
+ $this->client->getLogger()->error(
111
+ 'File cache delete failed',
112
+ array('key' => $key, 'file' => $file)
113
+ );
114
  throw new GoogleGAL_Cache_Exception("Cache file could not be deleted");
115
  }
116
+
117
+ $this->client->getLogger()->debug(
118
+ 'File cache delete',
119
+ array('key' => $key, 'file' => $file)
120
+ );
121
  }
122
+
123
  private function getWriteableCacheFile($file)
124
  {
125
  return $this->getCacheFile($file, true);
129
  {
130
  return $this->getCacheDir($file, $forWrite) . '/' . md5($file);
131
  }
132
+
133
  private function getCacheDir($file, $forWrite)
134
  {
135
  // use the first 2 characters of the hash as a directory prefix
138
  $storageDir = $this->path . '/' . substr(md5($file), 0, 2);
139
  if ($forWrite && ! is_dir($storageDir)) {
140
  if (! mkdir($storageDir, 0755, true)) {
141
+ $this->client->getLogger()->error(
142
+ 'File cache creation failed',
143
+ array('dir' => $storageDir)
144
+ );
145
  throw new GoogleGAL_Cache_Exception("Could not create storage directory: $storageDir");
146
  }
147
  }
148
  return $storageDir;
149
  }
150
+
151
  private function acquireReadLock($storageFile)
152
  {
153
  return $this->acquireLock(LOCK_SH, $storageFile);
154
  }
155
+
156
  private function acquireWriteLock($storageFile)
157
  {
158
  $rc = $this->acquireLock(LOCK_EX, $storageFile);
159
  if (!$rc) {
160
+ $this->client->getLogger()->notice(
161
+ 'File cache write lock failed',
162
+ array('file' => $storageFile)
163
+ );
164
  $this->delete($storageFile);
165
  }
166
  return $rc;
167
  }
168
+
169
  private function acquireLock($type, $storageFile)
170
  {
171
  $mode = $type == LOCK_EX ? "w" : "r";
180
  }
181
  return true;
182
  }
183
+
184
  public function unlock($storageFile)
185
  {
186
  if ($this->fh) {
core/Google/Cache/Memcache.php CHANGED
@@ -15,8 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Cache/Abstract.php";
19
- require_once "Google/Cache/Exception.php";
20
 
21
  /**
22
  * A persistent storage class based on the memcache, which is not
@@ -35,11 +34,22 @@ class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
35
  private $host;
36
  private $port;
37
 
 
 
 
 
 
38
  public function __construct(GoogleGAL_Client $client)
39
  {
40
  if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
41
- throw new GoogleGAL_Cache_Exception("Memcache functions not available");
 
 
 
42
  }
 
 
 
43
  if ($client->isAppEngine()) {
44
  // No credentials needed for GAE.
45
  $this->mc = new Memcached();
@@ -47,12 +57,15 @@ class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
47
  } else {
48
  $this->host = $client->getClassConfig($this, 'host');
49
  $this->port = $client->getClassConfig($this, 'port');
50
- if (empty($this->host) || empty($this->port)) {
51
- throw new GoogleGAL_Cache_Exception("You need to supply a valid memcache host and port");
 
 
 
52
  }
53
  }
54
  }
55
-
56
  /**
57
  * @inheritDoc
58
  */
@@ -66,12 +79,26 @@ class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
66
  $ret = memcache_get($this->connection, $key);
67
  }
68
  if ($ret === false) {
 
 
 
 
69
  return false;
70
  }
71
  if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) {
 
 
 
 
72
  $this->delete($key);
73
  return false;
74
  }
 
 
 
 
 
 
75
  return $ret['data'];
76
  }
77
 
@@ -94,8 +121,18 @@ class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
94
  $rc = memcache_set($this->connection, $key, $data, false);
95
  }
96
  if ($rc == false) {
 
 
 
 
 
97
  throw new GoogleGAL_Cache_Exception("Couldn't store data in cache");
98
  }
 
 
 
 
 
99
  }
100
 
101
  /**
@@ -110,11 +147,16 @@ class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
110
  } else {
111
  memcache_delete($this->connection, $key, 0);
112
  }
 
 
 
 
 
113
  }
114
 
115
  /**
116
- * Lazy initialiser for memcache connection. Uses pconnect for to take
117
- * advantage of the persistence pool where possible.
118
  */
119
  private function connect()
120
  {
@@ -129,9 +171,12 @@ class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
129
  } else {
130
  $this->connection = memcache_pconnect($this->host, $this->port);
131
  }
132
-
133
  if (! $this->connection) {
134
- throw new GoogleGAL_Cache_Exception("Couldn't connect to memcache server");
 
 
 
135
  }
136
  }
137
  }
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
19
 
20
  /**
21
  * A persistent storage class based on the memcache, which is not
34
  private $host;
35
  private $port;
36
 
37
+ /**
38
+ * @var GoogleGAL_Client the current client
39
+ */
40
+ private $client;
41
+
42
  public function __construct(GoogleGAL_Client $client)
43
  {
44
  if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
45
+ $error = "Memcache functions not available";
46
+
47
+ $client->getLogger()->error($error);
48
+ throw new GoogleGAL_Cache_Exception($error);
49
  }
50
+
51
+ $this->client = $client;
52
+
53
  if ($client->isAppEngine()) {
54
  // No credentials needed for GAE.
55
  $this->mc = new Memcached();
57
  } else {
58
  $this->host = $client->getClassConfig($this, 'host');
59
  $this->port = $client->getClassConfig($this, 'port');
60
+ if (empty($this->host) || (empty($this->port) && (string) $this->port != "0")) {
61
+ $error = "You need to supply a valid memcache host and port";
62
+
63
+ $client->getLogger()->error($error);
64
+ throw new GoogleGAL_Cache_Exception($error);
65
  }
66
  }
67
  }
68
+
69
  /**
70
  * @inheritDoc
71
  */
79
  $ret = memcache_get($this->connection, $key);
80
  }
81
  if ($ret === false) {
82
+ $this->client->getLogger()->debug(
83
+ 'Memcache cache miss',
84
+ array('key' => $key)
85
+ );
86
  return false;
87
  }
88
  if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) {
89
+ $this->client->getLogger()->debug(
90
+ 'Memcache cache miss (expired)',
91
+ array('key' => $key, 'var' => $ret)
92
+ );
93
  $this->delete($key);
94
  return false;
95
  }
96
+
97
+ $this->client->getLogger()->debug(
98
+ 'Memcache cache hit',
99
+ array('key' => $key, 'var' => $ret)
100
+ );
101
+
102
  return $ret['data'];
103
  }
104
 
121
  $rc = memcache_set($this->connection, $key, $data, false);
122
  }
123
  if ($rc == false) {
124
+ $this->client->getLogger()->error(
125
+ 'Memcache cache set failed',
126
+ array('key' => $key, 'var' => $data)
127
+ );
128
+
129
  throw new GoogleGAL_Cache_Exception("Couldn't store data in cache");
130
  }
131
+
132
+ $this->client->getLogger()->debug(
133
+ 'Memcache cache set',
134
+ array('key' => $key, 'var' => $data)
135
+ );
136
  }
137
 
138
  /**
147
  } else {
148
  memcache_delete($this->connection, $key, 0);
149
  }
150
+
151
+ $this->client->getLogger()->debug(
152
+ 'Memcache cache delete',
153
+ array('key' => $key)
154
+ );
155
  }
156
 
157
  /**
158
+ * Lazy initialiser for memcache connection. Uses pconnect for to take
159
+ * advantage of the persistence pool where possible.
160
  */
161
  private function connect()
162
  {
171
  } else {
172
  $this->connection = memcache_pconnect($this->host, $this->port);
173
  }
174
+
175
  if (! $this->connection) {
176
+ $error = "Couldn't connect to memcache server";
177
+
178
+ $this->client->getLogger()->error($error);
179
+ throw new GoogleGAL_Cache_Exception($error);
180
  }
181
  }
182
  }
core/Google/Cache/Null.php CHANGED
@@ -15,8 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once "Google/Cache/Abstract.php";
19
- require_once "Google/Cache/Exception.php";
20
 
21
  /**
22
  * A blank storage class, for cases where caching is not
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
19
 
20
  /**
21
  * A blank storage class, for cases where caching is not
core/Google/Client.php CHANGED
@@ -15,17 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once 'Google/Auth/AssertionCredentials.php';
19
- require_once 'Google/Cache/File.php';
20
- require_once 'Google/Cache/Memcache.php';
21
- require_once 'Google/Config.php';
22
- require_once 'Google/Collection.php';
23
- require_once 'Google/Exception.php';
24
- require_once 'Google/IO/Curl.php';
25
- require_once 'Google/IO/Stream.php';
26
- require_once 'Google/Model.php';
27
- require_once 'Google/Service.php';
28
- require_once 'Google/Service/Resource.php';
29
 
30
  /**
31
  * The Google API Client
@@ -36,7 +26,7 @@ require_once 'Google/Service/Resource.php';
36
  */
37
  class GoogleGAL_Client
38
  {
39
- const LIBVER = "1.0.5-beta";
40
  const USER_AGENT_SUFFIX = "google-api-php-client/";
41
  /**
42
  * @var GoogleGAL_Auth_Abstract $auth
@@ -58,6 +48,11 @@ class GoogleGAL_Client
58
  */
59
  private $config;
60
 
 
 
 
 
 
61
  /**
62
  * @var boolean $deferExecution
63
  */
@@ -80,11 +75,6 @@ class GoogleGAL_Client
80
  */
81
  public function __construct($config = null)
82
  {
83
- if (! ini_get('date.timezone') &&
84
- function_exists('date_default_timezone_set')) {
85
- date_default_timezone_set('UTC');
86
- }
87
-
88
  if (is_string($config) && strlen($config)) {
89
  $config = new GoogleGAL_Config($config);
90
  } else if ( !($config instanceof GoogleGAL_Config)) {
@@ -100,9 +90,10 @@ class GoogleGAL_Client
100
  $config->setClassConfig('GoogleGAL_Http_Request', 'disable_gzip', true);
101
  }
102
  }
103
-
104
  if ($config->getIoClass() == GoogleGAL_Config::USE_AUTO_IO_SELECTION) {
105
- if (function_exists('curl_version') && function_exists('curl_exec')) {
 
106
  $config->setIoClass("GoogleGAL_IO_Curl");
107
  } else {
108
  $config->setIoClass("GoogleGAL_IO_Stream");
@@ -141,6 +132,7 @@ class GoogleGAL_Client
141
  * the "Download JSON" button on in the Google Developer
142
  * Console.
143
  * @param string $json the configuration json
 
144
  */
145
  public function setAuthConfig($json)
146
  {
@@ -169,6 +161,7 @@ class GoogleGAL_Client
169
  }
170
 
171
  /**
 
172
  * @return array
173
  * @visible For Testing
174
  */
@@ -210,9 +203,9 @@ class GoogleGAL_Client
210
 
211
  /**
212
  * Set the IO object
213
- * @param GoogleGAL_Io_Abstract $auth
214
  */
215
- public function setIo(GoogleGAL_Io_Abstract $io)
216
  {
217
  $this->config->setIoClass(get_class($io));
218
  $this->io = $io;
@@ -220,7 +213,7 @@ class GoogleGAL_Client
220
 
221
  /**
222
  * Set the Cache object
223
- * @param GoogleGAL_Cache_Abstract $auth
224
  */
225
  public function setCache(GoogleGAL_Cache_Abstract $cache)
226
  {
@@ -228,6 +221,16 @@ class GoogleGAL_Client
228
  $this->cache = $cache;
229
  }
230
 
 
 
 
 
 
 
 
 
 
 
231
  /**
232
  * Construct the OAuth 2.0 authorization request URI.
233
  * @return string
@@ -253,6 +256,15 @@ class GoogleGAL_Client
253
  return (null == $token || 'null' == $token || '[]' == $token) ? null : $token;
254
  }
255
 
 
 
 
 
 
 
 
 
 
256
  /**
257
  * Returns if the access_token is expired.
258
  * @return bool Returns True if the access_token is expired.
@@ -292,6 +304,15 @@ class GoogleGAL_Client
292
  $this->config->setApprovalPrompt($approvalPrompt);
293
  }
294
 
 
 
 
 
 
 
 
 
 
295
  /**
296
  * Set the application name, this is included in the User-Agent HTTP header.
297
  * @param string $applicationName
@@ -354,14 +375,57 @@ class GoogleGAL_Client
354
  $this->config->setDeveloperKey($developerKey);
355
  }
356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  /**
358
  * Fetches a fresh OAuth 2.0 access token with the given refresh token.
359
  * @param string $refreshToken
360
- * @return void
361
  */
362
  public function refreshToken($refreshToken)
363
  {
364
- return $this->getAuth()->refreshToken($refreshToken);
365
  }
366
 
367
  /**
@@ -392,12 +456,12 @@ class GoogleGAL_Client
392
  /**
393
  * Verify a JWT that was signed with your own certificates.
394
  *
395
- * @param $jwt the token
396
- * @param $certs array of certificates
397
- * @param $required_audience the expected consumer of the token
398
- * @param [$issuer] the expected issues, defaults to Google
399
  * @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
400
- * @return token information if valid, false if not
401
  */
402
  public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)
403
  {
@@ -407,8 +471,7 @@ class GoogleGAL_Client
407
  }
408
 
409
  /**
410
- * @param GoogleGAL_Auth_AssertionCredentials $creds
411
- * @return void
412
  */
413
  public function setAssertionCredentials(GoogleGAL_Auth_AssertionCredentials $creds)
414
  {
@@ -482,7 +545,9 @@ class GoogleGAL_Client
482
  /**
483
  * Helper method to execute deferred HTTP requests.
484
  *
485
- * @returns object of the type of the expected class or array.
 
 
486
  */
487
  public function execute($request)
488
  {
@@ -549,10 +614,23 @@ class GoogleGAL_Client
549
  return $this->cache;
550
  }
551
 
 
 
 
 
 
 
 
 
 
 
 
 
552
  /**
553
  * Retrieve custom configuration for a specific class.
554
  * @param $class string|object - class or instance of class to retrieve
555
  * @param $key string optional - key to retrieve
 
556
  */
557
  public function getClassConfig($class, $key = null)
558
  {
@@ -566,9 +644,9 @@ class GoogleGAL_Client
566
  * Set configuration specific to a given class.
567
  * $config->setClassConfig('GoogleGAL_Cache_File',
568
  * array('directory' => '/tmp/cache'));
569
- * @param $class The class name for the configuration
570
  * @param $config string key or an array of configuration values
571
- * @param $value optional - if $config is a key, the value
572
  *
573
  */
574
  public function setClassConfig($class, $config, $value = null)
@@ -576,7 +654,7 @@ class GoogleGAL_Client
576
  if (!is_string($class)) {
577
  $class = get_class($class);
578
  }
579
- return $this->config->setClassConfig($class, $config, $value);
580
 
581
  }
582
 
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../autoload.php');
 
 
 
 
 
 
 
 
 
 
19
 
20
  /**
21
  * The Google API Client
26
  */
27
  class GoogleGAL_Client
28
  {
29
+ const LIBVER = "1.1.1";
30
  const USER_AGENT_SUFFIX = "google-api-php-client/";
31
  /**
32
  * @var GoogleGAL_Auth_Abstract $auth
48
  */
49
  private $config;
50
 
51
+ /**
52
+ * @var GoogleGAL_Logger_Abstract $logger
53
+ */
54
+ private $logger;
55
+
56
  /**
57
  * @var boolean $deferExecution
58
  */
75
  */
76
  public function __construct($config = null)
77
  {
 
 
 
 
 
78
  if (is_string($config) && strlen($config)) {
79
  $config = new GoogleGAL_Config($config);
80
  } else if ( !($config instanceof GoogleGAL_Config)) {
90
  $config->setClassConfig('GoogleGAL_Http_Request', 'disable_gzip', true);
91
  }
92
  }
93
+
94
  if ($config->getIoClass() == GoogleGAL_Config::USE_AUTO_IO_SELECTION) {
95
+ if (function_exists('curl_version') && function_exists('curl_exec')
96
+ && !$this->isAppEngine()) {
97
  $config->setIoClass("GoogleGAL_IO_Curl");
98
  } else {
99
  $config->setIoClass("GoogleGAL_IO_Stream");
132
  * the "Download JSON" button on in the Google Developer
133
  * Console.
134
  * @param string $json the configuration json
135
+ * @throws GoogleGAL_Exception
136
  */
137
  public function setAuthConfig($json)
138
  {
161
  }
162
 
163
  /**
164
+ * @throws GoogleGAL_Auth_Exception
165
  * @return array
166
  * @visible For Testing
167
  */
203
 
204
  /**
205
  * Set the IO object
206
+ * @param GoogleGAL_IO_Abstract $io
207
  */
208
+ public function setIo(GoogleGAL_IO_Abstract $io)
209
  {
210
  $this->config->setIoClass(get_class($io));
211
  $this->io = $io;
213
 
214
  /**
215
  * Set the Cache object
216
+ * @param GoogleGAL_Cache_Abstract $cache
217
  */
218
  public function setCache(GoogleGAL_Cache_Abstract $cache)
219
  {
221
  $this->cache = $cache;
222
  }
223
 
224
+ /**
225
+ * Set the Logger object
226
+ * @param GoogleGAL_Logger_Abstract $logger
227
+ */
228
+ public function setLogger(GoogleGAL_Logger_Abstract $logger)
229
+ {
230
+ $this->config->setLoggerClass(get_class($logger));
231
+ $this->logger = $logger;
232
+ }
233
+
234
  /**
235
  * Construct the OAuth 2.0 authorization request URI.
236
  * @return string
256
  return (null == $token || 'null' == $token || '[]' == $token) ? null : $token;
257
  }
258
 
259
+ /**
260
+ * Get the OAuth 2.0 refresh token.
261
+ * @return string $refreshToken refresh token or null if not available
262
+ */
263
+ public function getRefreshToken()
264
+ {
265
+ return $this->getAuth()->getRefreshToken();
266
+ }
267
+
268
  /**
269
  * Returns if the access_token is expired.
270
  * @return bool Returns True if the access_token is expired.
304
  $this->config->setApprovalPrompt($approvalPrompt);
305
  }
306
 
307
+ /**
308
+ * Set the login hint, email address or sub id.
309
+ * @param string $loginHint
310
+ */
311
+ public function setLoginHint($loginHint)
312
+ {
313
+ $this->config->setLoginHint($loginHint);
314
+ }
315
+
316
  /**
317
  * Set the application name, this is included in the User-Agent HTTP header.
318
  * @param string $applicationName
375
  $this->config->setDeveloperKey($developerKey);
376
  }
377
 
378
+ /**
379
+ * Set the hd (hosted domain) parameter streamlines the login process for
380
+ * Google Apps hosted accounts. By including the domain of the user, you
381
+ * restrict sign-in to accounts at that domain.
382
+ * @param $hd string - the domain to use.
383
+ */
384
+ public function setHostedDomain($hd)
385
+ {
386
+ $this->config->setHostedDomain($hd);
387
+ }
388
+
389
+ /**
390
+ * Set the prompt hint. Valid values are none, consent and select_account.
391
+ * If no value is specified and the user has not previously authorized
392
+ * access, then the user is shown a consent screen.
393
+ * @param $prompt string
394
+ */
395
+ public function setPrompt($prompt)
396
+ {
397
+ $this->config->setPrompt($prompt);
398
+ }
399
+
400
+ /**
401
+ * openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth
402
+ * 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which
403
+ * an authentication request is valid.
404
+ * @param $realm string - the URL-space to use.
405
+ */
406
+ public function setOpenidRealm($realm)
407
+ {
408
+ $this->config->setOpenidRealm($realm);
409
+ }
410
+
411
+ /**
412
+ * If this is provided with the value true, and the authorization request is
413
+ * granted, the authorization will include any previous authorizations
414
+ * granted to this user/application combination for other scopes.
415
+ * @param $include boolean - the URL-space to use.
416
+ */
417
+ public function setIncludeGrantedScopes($include)
418
+ {
419
+ $this->config->setIncludeGrantedScopes($include);
420
+ }
421
+
422
  /**
423
  * Fetches a fresh OAuth 2.0 access token with the given refresh token.
424
  * @param string $refreshToken
 
425
  */
426
  public function refreshToken($refreshToken)
427
  {
428
+ $this->getAuth()->refreshToken($refreshToken);
429
  }
430
 
431
  /**
456
  /**
457
  * Verify a JWT that was signed with your own certificates.
458
  *
459
+ * @param $id_token string The JWT token
460
+ * @param $cert_location array of certificates
461
+ * @param $audience string the expected consumer of the token
462
+ * @param $issuer string the expected issuer, defaults to Google
463
  * @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
464
+ * @return mixed token information if valid, false if not
465
  */
466
  public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)
467
  {
471
  }
472
 
473
  /**
474
+ * @param $creds GoogleGAL_Auth_AssertionCredentials
 
475
  */
476
  public function setAssertionCredentials(GoogleGAL_Auth_AssertionCredentials $creds)
477
  {
545
  /**
546
  * Helper method to execute deferred HTTP requests.
547
  *
548
+ * @param $request GoogleGAL_Http_Request|GoogleGAL_Http_Batch
549
+ * @throws GoogleGAL_Exception
550
+ * @return object of the type of the expected class or array.
551
  */
552
  public function execute($request)
553
  {
614
  return $this->cache;
615
  }
616
 
617
+ /**
618
+ * @return GoogleGAL_Logger_Abstract Logger implementation
619
+ */
620
+ public function getLogger()
621
+ {
622
+ if (!isset($this->logger)) {
623
+ $class = $this->config->getLoggerClass();
624
+ $this->logger = new $class($this);
625
+ }
626
+ return $this->logger;
627
+ }
628
+
629
  /**
630
  * Retrieve custom configuration for a specific class.
631
  * @param $class string|object - class or instance of class to retrieve
632
  * @param $key string optional - key to retrieve
633
+ * @return array
634
  */
635
  public function getClassConfig($class, $key = null)
636
  {
644
  * Set configuration specific to a given class.
645
  * $config->setClassConfig('GoogleGAL_Cache_File',
646
  * array('directory' => '/tmp/cache'));
647
+ * @param $class string|object - The class name for the configuration
648
  * @param $config string key or an array of configuration values
649
+ * @param $value string optional - if $config is a key, the value
650
  *
651
  */
652
  public function setClassConfig($class, $config, $value = null)
654
  if (!is_string($class)) {
655
  $class = get_class($class);
656
  }
657
+ $this->config->setClassConfig($class, $config, $value);
658
 
659
  }
660
 
core/Google/Collection.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- require_once "Google/Model.php";
4
 
5
  /**
6
  * Extension to the regular GoogleGAL_Model that automatically
@@ -13,7 +13,8 @@ class GoogleGAL_Collection extends GoogleGAL_Model implements Iterator, Countabl
13
 
14
  public function rewind()
15
  {
16
- if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) {
 
17
  reset($this->modelData[$this->collection_key]);
18
  }
19
  }
@@ -28,7 +29,8 @@ class GoogleGAL_Collection extends GoogleGAL_Model implements Iterator, Countabl
28
 
29
  public function key()
30
  {
31
- if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) {
 
32
  return key($this->modelData[$this->collection_key]);
33
  }
34
  }
1
  <?php
2
 
3
+ require_once realpath(dirname(__FILE__) . '/../../autoload.php');
4
 
5
  /**
6
  * Extension to the regular GoogleGAL_Model that automatically
13
 
14
  public function rewind()
15
  {
16
+ if (isset($this->modelData[$this->collection_key])
17
+ && is_array($this->modelData[$this->collection_key])) {
18
  reset($this->modelData[$this->collection_key]);
19
  }
20
  }
29
 
30
  public function key()
31
  {
32
+ if (isset($this->modelData[$this->collection_key])
33
+ && is_array($this->modelData[$this->collection_key])) {
34
  return key($this->modelData[$this->collection_key]);
35
  }
36
  }
core/Google/Config.php CHANGED
@@ -25,12 +25,12 @@ class GoogleGAL_Config
25
  const GZIP_UPLOADS_ENABLED = true;
26
  const GZIP_UPLOADS_DISABLED = false;
27
  const USE_AUTO_IO_SELECTION = "auto";
28
- private $configuration;
29
 
30
  /**
31
  * Create a new GoogleGAL_Config. Can accept an ini file location with the
32
  * local configuration. For example:
33
- * application_name: "My App";
34
  *
35
  * @param [$ini_file_location] - optional - The location of the ini file to load
36
  */
@@ -44,6 +44,7 @@ class GoogleGAL_Config
44
  'auth_class' => 'GoogleGAL_Auth_OAuth2',
45
  'io_class' => self::USE_AUTO_IO_SELECTION,
46
  'cache_class' => 'GoogleGAL_Cache_File',
 
47
 
48
  // Don't change these unless you're working against a special development
49
  // or testing environment.
@@ -54,6 +55,17 @@ class GoogleGAL_Config
54
  'GoogleGAL_IO_Abstract' => array(
55
  'request_timeout_seconds' => 100,
56
  ),
 
 
 
 
 
 
 
 
 
 
 
57
  'GoogleGAL_Http_Request' => array(
58
  // Disable the use of gzip on calls if set to true. Defaults to false.
59
  'disable_gzip' => self::GZIP_ENABLED,
@@ -78,9 +90,14 @@ class GoogleGAL_Config
78
  'developer_key' => '',
79
 
80
  // Other parameters.
 
 
 
 
 
 
81
  'access_type' => 'online',
82
  'approval_prompt' => 'auto',
83
- 'request_visible_actions' => '',
84
  'federated_signon_certs_url' =>
85
  'https://www.googleapis.com/oauth2/v1/certs',
86
  ),
@@ -89,16 +106,15 @@ class GoogleGAL_Config
89
  'directory' => sys_get_temp_dir() . '/GoogleGAL_Client'
90
  )
91
  ),
92
-
93
- // Definition of service specific values like scopes, oauth token URLs,
94
- // etc. Example:
95
- 'services' => array(
96
- ),
97
  );
98
  if ($ini_file_location) {
99
  $ini = parse_ini_file($ini_file_location, true);
100
  if (is_array($ini) && count($ini)) {
101
- $this->configuration = array_merge($this->configuration, $ini);
 
 
 
 
102
  }
103
  }
104
  }
@@ -107,9 +123,9 @@ class GoogleGAL_Config
107
  * Set configuration specific to a given class.
108
  * $config->setClassConfig('GoogleGAL_Cache_File',
109
  * array('directory' => '/tmp/cache'));
110
- * @param $class The class name for the configuration
111
  * @param $config string key or an array of configuration values
112
- * @param $value optional - if $config is a key, the value
113
  */
114
  public function setClassConfig($class, $config, $value = null)
115
  {
@@ -144,6 +160,15 @@ class GoogleGAL_Config
144
  return $this->configuration['cache_class'];
145
  }
146
 
 
 
 
 
 
 
 
 
 
147
  /**
148
  * Return the configured Auth class.
149
  * @return string
@@ -156,7 +181,7 @@ class GoogleGAL_Config
156
  /**
157
  * Set the auth class.
158
  *
159
- * @param $class the class name to set
160
  */
161
  public function setAuthClass($class)
162
  {
@@ -172,7 +197,7 @@ class GoogleGAL_Config
172
  /**
173
  * Set the IO class.
174
  *
175
- * @param $class the class name to set
176
  */
177
  public function setIoClass($class)
178
  {
@@ -188,7 +213,7 @@ class GoogleGAL_Config
188
  /**
189
  * Set the cache class.
190
  *
191
- * @param $class the class name to set
192
  */
193
  public function setCacheClass($class)
194
  {
@@ -201,8 +226,25 @@ class GoogleGAL_Config
201
  $this->configuration['cache_class'] = $class;
202
  }
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  /**
205
  * Return the configured IO class.
 
206
  * @return string
207
  */
208
  public function getIoClass()
@@ -229,7 +271,7 @@ class GoogleGAL_Config
229
 
230
  /**
231
  * Set the client ID for the auth class.
232
- * @param $key string - the API console client ID
233
  */
234
  public function setClientId($clientId)
235
  {
@@ -238,7 +280,7 @@ class GoogleGAL_Config
238
 
239
  /**
240
  * Set the client secret for the auth class.
241
- * @param $key string - the API console client secret
242
  */
243
  public function setClientSecret($secret)
244
  {
@@ -248,7 +290,8 @@ class GoogleGAL_Config
248
  /**
249
  * Set the redirect uri for the auth class. Note that if using the
250
  * Javascript based sign in flow, this should be the string 'postmessage'.
251
- * @param $key string - the URI that users should be redirected to
 
252
  */
253
  public function setRedirectUri($uri)
254
  {
@@ -282,6 +325,15 @@ class GoogleGAL_Config
282
  $this->setAuthConfig('approval_prompt', $approval);
283
  }
284
 
 
 
 
 
 
 
 
 
 
285
  /**
286
  * Set the developer key for the auth class. Note that this is separate value
287
  * from the client ID - if it looks like a URL, its a client ID!
@@ -292,6 +344,53 @@ class GoogleGAL_Config
292
  $this->setAuthConfig('developer_key', $key);
293
  }
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  /**
296
  * @return string the base URL to use for API calls
297
  */
25
  const GZIP_UPLOADS_ENABLED = true;
26
  const GZIP_UPLOADS_DISABLED = false;
27
  const USE_AUTO_IO_SELECTION = "auto";
28
+ protected $configuration;
29
 
30
  /**
31
  * Create a new GoogleGAL_Config. Can accept an ini file location with the
32
  * local configuration. For example:
33
+ * application_name="My App"
34
  *
35
  * @param [$ini_file_location] - optional - The location of the ini file to load
36
  */
44
  'auth_class' => 'GoogleGAL_Auth_OAuth2',
45
  'io_class' => self::USE_AUTO_IO_SELECTION,
46
  'cache_class' => 'GoogleGAL_Cache_File',
47
+ 'logger_class' => 'GoogleGAL_Logger_Null',
48
 
49
  // Don't change these unless you're working against a special development
50
  // or testing environment.
55
  'GoogleGAL_IO_Abstract' => array(
56
  'request_timeout_seconds' => 100,
57
  ),
58
+ 'GoogleGAL_Logger_Abstract' => array(
59
+ 'level' => 'debug',
60
+ 'log_format' => "[%datetime%] %level%: %message% %context%\n",
61
+ 'date_format' => 'd/M/Y:H:i:s O',
62
+ 'allow_newlines' => true
63
+ ),
64
+ 'GoogleGAL_Logger_File' => array(
65
+ 'file' => 'php://stdout',
66
+ 'mode' => 0640,
67
+ 'lock' => false,
68
+ ),
69
  'GoogleGAL_Http_Request' => array(
70
  // Disable the use of gzip on calls if set to true. Defaults to false.
71
  'disable_gzip' => self::GZIP_ENABLED,
90
  'developer_key' => '',
91
 
92
  // Other parameters.
93
+ 'hd' => '',
94
+ 'prompt' => '',
95
+ 'openid.realm' => '',
96
+ 'include_granted_scopes' => '',
97
+ 'login_hint' => '',
98
+ 'request_visible_actions' => '',
99
  'access_type' => 'online',
100
  'approval_prompt' => 'auto',
 
101
  'federated_signon_certs_url' =>
102
  'https://www.googleapis.com/oauth2/v1/certs',
103
  ),
106
  'directory' => sys_get_temp_dir() . '/GoogleGAL_Client'
107
  )
108
  ),
 
 
 
 
 
109
  );
110
  if ($ini_file_location) {
111
  $ini = parse_ini_file($ini_file_location, true);
112
  if (is_array($ini) && count($ini)) {
113
+ $merged_configuration = $ini + $this->configuration;
114
+ if (isset($ini['classes']) && isset($this->configuration['classes'])) {
115
+ $merged_configuration['classes'] = $ini['classes'] + $this->configuration['classes'];
116
+ }
117
+ $this->configuration = $merged_configuration;
118
  }
119
  }
120
  }
123
  * Set configuration specific to a given class.
124
  * $config->setClassConfig('GoogleGAL_Cache_File',
125
  * array('directory' => '/tmp/cache'));
126
+ * @param $class string The class name for the configuration
127
  * @param $config string key or an array of configuration values
128
+ * @param $value string optional - if $config is a key, the value
129
  */
130
  public function setClassConfig($class, $config, $value = null)
131
  {
160
  return $this->configuration['cache_class'];
161
  }
162
 
163
+ /**
164
+ * Return the configured logger class.
165
+ * @return string
166
+ */
167
+ public function getLoggerClass()
168
+ {
169
+ return $this->configuration['logger_class'];
170
+ }
171
+
172
  /**
173
  * Return the configured Auth class.
174
  * @return string
181
  /**
182
  * Set the auth class.
183
  *
184
+ * @param $class string the class name to set
185
  */
186
  public function setAuthClass($class)
187
  {
197
  /**
198
  * Set the IO class.
199
  *
200
+ * @param $class string the class name to set
201
  */
202
  public function setIoClass($class)
203
  {
213
  /**
214
  * Set the cache class.
215
  *
216
+ * @param $class string the class name to set
217
  */
218
  public function setCacheClass($class)
219
  {
226
  $this->configuration['cache_class'] = $class;
227
  }
228
 
229
+ /**
230
+ * Set the logger class.
231
+ *
232
+ * @param $class string the class name to set
233
+ */
234
+ public function setLoggerClass($class)
235
+ {
236
+ $prev = $this->configuration['logger_class'];
237
+ if (!isset($this->configuration['classes'][$class]) &&
238
+ isset($this->configuration['classes'][$prev])) {
239
+ $this->configuration['classes'][$class] =
240
+ $this->configuration['classes'][$prev];
241
+ }
242
+ $this->configuration['logger_class'] = $class;
243
+ }
244
+
245
  /**
246
  * Return the configured IO class.
247
+ *
248
  * @return string
249
  */
250
  public function getIoClass()
271
 
272
  /**
273
  * Set the client ID for the auth class.
274
+ * @param $clientId string - the API console client ID
275
  */
276
  public function setClientId($clientId)
277
  {
280
 
281
  /**
282
  * Set the client secret for the auth class.
283
+ * @param $secret string - the API console client secret
284
  */
285
  public function setClientSecret($secret)
286
  {
290
  /**
291
  * Set the redirect uri for the auth class. Note that if using the
292
  * Javascript based sign in flow, this should be the string 'postmessage'.
293
+ *
294
+ * @param $uri string - the URI that users should be redirected to
295
  */
296
  public function setRedirectUri($uri)
297
  {
325
  $this->setAuthConfig('approval_prompt', $approval);
326
  }
327
 
328
+ /**
329
+ * Set the login hint (email address or sub identifier)
330
+ * @param $hint string
331
+ */
332
+ public function setLoginHint($hint)
333
+ {
334
+ $this->setAuthConfig('login_hint', $hint);
335
+ }
336
+
337
  /**
338
  * Set the developer key for the auth class. Note that this is separate value
339
  * from the client ID - if it looks like a URL, its a client ID!
344
  $this->setAuthConfig('developer_key', $key);
345
  }
346
 
347
+ /**
348
+ * Set the hd (hosted domain) parameter streamlines the login process for
349
+ * Google Apps hosted accounts. By including the domain of the user, you
350
+ * restrict sign-in to accounts at that domain.
351
+ * @param $hd string - the domain to use.
352
+ */
353
+ public function setHostedDomain($hd)
354
+ {
355
+ $this->setAuthConfig('hd', $hd);
356
+ }
357
+
358
+ /**
359
+ * Set the prompt hint. Valid values are none, consent and select_account.
360
+ * If no value is specified and the user has not previously authorized
361
+ * access, then the user is shown a consent screen.
362
+ * @param $prompt string
363
+ */
364
+ public function setPrompt($prompt)
365
+ {
366
+ $this->setAuthConfig('prompt', $prompt);
367
+ }
368
+
369
+ /**
370
+ * openid.realm is a parameter from the OpenID 2.0 protocol, not from OAuth
371
+ * 2.0. It is used in OpenID 2.0 requests to signify the URL-space for which
372
+ * an authentication request is valid.
373
+ * @param $realm string - the URL-space to use.
374
+ */
375
+ public function setOpenidRealm($realm)
376
+ {
377
+ $this->setAuthConfig('openid.realm', $realm);
378
+ }
379
+
380
+ /**
381
+ * If this is provided with the value true, and the authorization request is
382
+ * granted, the authorization will include any previous authorizations
383
+ * granted to this user/application combination for other scopes.
384
+ * @param $include boolean - the URL-space to use.
385
+ */
386
+ public function setIncludeGrantedScopes($include)
387
+ {
388
+ $this->setAuthConfig(
389
+ 'include_granted_scopes',
390
+ $include ? "true" : "false"
391
+ );
392
+ }
393
+
394
  /**
395
  * @return string the base URL to use for API calls
396
  */
core/Google/Http/Batch.php CHANGED
@@ -15,9 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once 'Google/Client.php';
19
- require_once 'Google/Http/Request.php';
20
- require_once 'Google/Http/REST.php';
21
 
22
  /**
23
  * @author Chirag Shah <chirags@google.com>
@@ -125,10 +123,10 @@ class GoogleGAL_Http_Batch
125
  }
126
 
127
  try {
128
- $response = GoogleGAL_Http_REST::decodeHttpResponse($response);
129
  $responses[$key] = $response;
130
  } catch (GoogleGAL_Service_Exception $e) {
131
- // Store the exception as the response, so succesful responses
132
  // can be processed.
133
  $responses[$key] = $e;
134
  }
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
 
19
 
20
  /**
21
  * @author Chirag Shah <chirags@google.com>
123
  }
124
 
125
  try {
126
+ $response = GoogleGAL_Http_REST::decodeHttpResponse($response, $this->client);
127
  $responses[$key] = $response;
128
  } catch (GoogleGAL_Service_Exception $e) {
129
+ // Store the exception as the response, so successful responses
130
  // can be processed.
131
  $responses[$key] = $e;
132
  }
core/Google/Http/CacheParser.php CHANGED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once 'Google/Http/Request.php';
19
 
20
  /**
21
  * Implement the caching directives specified in rfc2616. This
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
19
 
20
  /**
21
  * Implement the caching directives specified in rfc2616. This
core/Google/Http/MediaFileUpload.php CHANGED
@@ -15,11 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once 'Google/Client.php';
19
- require_once 'Google/Exception.php';
20
- require_once 'Google/Http/Request.php';
21
- require_once 'Google/Http/REST.php';
22
- require_once 'Google/Utils.php';
23
 
24
  /**
25
  * @author Chirag Shah <chirags@google.com>
@@ -182,7 +178,7 @@ class GoogleGAL_Http_MediaFileUpload
182
  // No problems, but upload not complete.
183
  return false;
184
  } else {
185
- return GoogleGAL_Http_REST::decodeHttpResponse($response);
186
  }
187
  }
188
 
@@ -287,6 +283,18 @@ class GoogleGAL_Http_MediaFileUpload
287
  if (200 == $code && true == $location) {
288
  return $location;
289
  }
290
- throw new GoogleGAL_Exception("Failed to start the resumable upload");
 
 
 
 
 
 
 
 
 
 
 
 
291
  }
292
  }
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
 
 
 
19
 
20
  /**
21
  * @author Chirag Shah <chirags@google.com>
178
  // No problems, but upload not complete.
179
  return false;
180
  } else {
181
+ return GoogleGAL_Http_REST::decodeHttpResponse($response, $this->client);
182
  }
183
  }
184
 
283
  if (200 == $code && true == $location) {
284
  return $location;
285
  }
286
+ $message = $code;
287
+ $body = @json_decode($response->getResponseBody());
288
+ if (!empty( $body->error->errors ) ) {
289
+ $message .= ': ';
290
+ foreach ($body->error->errors as $error) {
291
+ $message .= "{$error->domain}, {$error->message};";
292
+ }
293
+ $message = rtrim($message, ';');
294
+ }
295
+
296
+ $error = "Failed to start the resumable upload (HTTP {$message})";
297
+ $this->client->getLogger()->error($error);
298
+ throw new GoogleGAL_Exception($error);
299
  }
300
  }
core/Google/Http/REST.php CHANGED
@@ -15,10 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- require_once 'Google/Client.php';
19
- require_once 'Google/Http/Request.php';
20
- require_once 'Google/Service/Exception.php';
21
- require_once 'Google/Utils/URITemplate.php';
22
 
23
  /**
24
  * This class implements the RESTful transport of apiServiceRequest()'s
@@ -41,7 +38,7 @@ class GoogleGAL_Http_REST
41
  {
42
  $httpRequest = $client->getIo()->makeRequest($req);
43
  $httpRequest->setExpectedClass($req->getExpectedClass());
44
- return self::decodeHttpResponse($httpRequest);
45
  }
46
 
47
  /**
@@ -49,9 +46,10 @@ class GoogleGAL_Http_REST
49
  * @static
50
  * @throws GoogleGAL_Service_Exception
51
  * @param GoogleGAL_Http_Request $response The http response to be decoded.
 
52
  * @return mixed|null
53
  */
54
- public static function decodeHttpResponse($response)
55
  {
56
  $code = $response->getResponseHttpCode();
57
  $body = $response->getResponseBody();
@@ -76,6 +74,12 @@ class GoogleGAL_Http_REST
76
  $errors = $decoded['error']['errors'];
77
  }
78
 
 
 
 
 
 
 
79
  throw new GoogleGAL_Service_Exception($err, $code, null, $errors);
80
  }
81
 
@@ -83,7 +87,11 @@ class GoogleGAL_Http_REST
83
  if ($code != '204') {
84
  $decoded = json_decode($body, true);
85
  if ($decoded === null || $decoded === "") {
86
- throw new GoogleGAL_Service_Exception("Invalid json in service response: $body");
 
 
 
 
87
  }
88
 
89
  if ($response->getExpectedClass()) {
15
  * limitations under the License.
16
  */
17
 
18
+ require_once realpath(dirname(__FILE__) . '/../../../autoload.php');
 
 
 
19
 
20
  /**
21
  * This class implements the RESTful transport of apiServiceRequest()'s
38
  {
39
  $httpRequest = $client->getIo()->makeRequest($req);
40
  $httpRequest->setExpectedClass($req->getExpectedClass());
41
+ return self::decodeHttpResponse($httpRequest, $client);
42
  }
43
 
44
  /**
46
  * @static
47
  * @throws GoogleGAL_Service_Exception
48
  * @param GoogleGAL_Http_Request $response The http response to be decoded.
49
+ * @param GoogleGAL_Client $client
50
  * @return mixed|null
51
  */
52
+ public static function decodeHttpResponse($response, GoogleGAL_Cl