Version Description
Fixed conflicts with some other plugins such as Google Analyticator which use similar Google client libraries.
Download this release
Release Info
Developer | danlester |
Plugin | Google Apps Login |
Version | 2.3.1 |
Comparing to | |
See all releases |
Code changes from version 2.3 to 2.3.1
- core/Google/Auth/Abstract.php +5 -5
- core/Google/Auth/AssertionCredentials.php +6 -6
- core/Google/Auth/Exception.php +1 -1
- core/Google/Auth/LoginTicket.php +3 -3
- core/Google/Auth/OAuth2.php +47 -47
- core/Google/Auth/Simple.php +7 -7
- core/Google/Cache/Abstract.php +2 -2
- core/Google/Cache/Apc.php +4 -4
- core/Google/Cache/Exception.php +1 -1
- core/Google/Cache/File.php +4 -4
- core/Google/Cache/Memcache.php +7 -7
- core/Google/Cache/Null.php +2 -2
- core/Google/Client.php +38 -38
- core/Google/Collection.php +2 -2
- core/Google/Config.php +10 -10
- core/Google/Exception.php +1 -1
- core/Google/Http/Batch.php +10 -10
- core/Google/Http/CacheParser.php +10 -10
- core/Google/Http/MediaFileUpload.php +10 -10
- core/Google/Http/REST.php +11 -11
- core/Google/Http/Request.php +3 -3
- core/Google/IO/Abstract.php +27 -27
- core/Google/IO/Curl.php +8 -8
- core/Google/IO/Exception.php +1 -1
- core/Google/IO/Stream.php +7 -7
- core/Google/Model.php +5 -5
- core/Google/README.md +3 -3
- core/Google/Service.php +4 -4
- core/Google/Service/AdExchangeBuyer.php +64 -64
- core/Google/Service/AdExchangeSeller.php +109 -109
- core/Google/Service/AdSense.php +213 -213
- core/Google/Service/AdSenseHost.php +134 -134
- core/Google/Service/Admin.php +9 -9
- core/Google/Service/Analytics.php +341 -341
- core/Google/Service/AndroidPublisher.php +15 -15
- core/Google/Service/AppState.php +21 -21
- core/Google/Service/Audit.php +21 -21
- core/Google/Service/Bigquery.php +201 -201
- core/Google/Service/Blogger.php +184 -184
- core/Google/Service/Books.php +325 -325
- core/Google/Service/Calendar.php +185 -185
- core/Google/Service/CivicInfo.php +81 -81
- core/Google/Service/Compute.php +498 -498
- core/Google/Service/Coordinate.php +81 -81
- core/Google/Service/Customsearch.php +39 -39
- core/Google/Service/Datastore.php +146 -146
- core/Google/Service/Dfareporting.php +195 -195
- core/Google/Service/Directory.php +242 -242
- core/Google/Service/Dns.php +50 -50
- core/Google/Service/DoubleClickBidManager.php +73 -73
- core/Google/Service/Doubleclicksearch.php +73 -73
- core/Google/Service/Drive.php +64 -64
core/Google/Auth/Abstract.php
CHANGED
@@ -21,19 +21,19 @@ require_once "Google/Http/Request.php";
|
|
21 |
* @author Chris Chabot <chabotc@google.com>
|
22 |
*
|
23 |
*/
|
24 |
-
abstract class
|
25 |
{
|
26 |
/**
|
27 |
* An utility function that first calls $this->auth->sign($request) and then
|
28 |
* executes makeRequest() on that signed request. Used for when a request
|
29 |
* should be authenticated
|
30 |
-
* @param
|
31 |
-
* @return
|
32 |
*/
|
33 |
-
abstract public function authenticatedRequest(
|
34 |
|
35 |
abstract public function authenticate($code);
|
36 |
-
abstract public function sign(
|
37 |
abstract public function createAuthUrl($scope);
|
38 |
|
39 |
abstract public function refreshToken($refreshToken);
|
21 |
* @author Chris Chabot <chabotc@google.com>
|
22 |
*
|
23 |
*/
|
24 |
+
abstract class GoogleGAL_Auth_Abstract
|
25 |
{
|
26 |
/**
|
27 |
* An utility function that first calls $this->auth->sign($request) and then
|
28 |
* executes makeRequest() on that signed request. Used for when a request
|
29 |
* should be authenticated
|
30 |
+
* @param GoogleGAL_Http_Request $request
|
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);
|
core/Google/Auth/AssertionCredentials.php
CHANGED
@@ -24,7 +24,7 @@ require_once "Google/Utils.php";
|
|
24 |
*
|
25 |
* @author Chirag Shah <chirags@google.com>
|
26 |
*/
|
27 |
-
class
|
28 |
{
|
29 |
const MAX_TOKEN_LIFETIME_SECS = 3600;
|
30 |
|
@@ -93,7 +93,7 @@ class Google_Auth_AssertionCredentials
|
|
93 |
$now = time();
|
94 |
|
95 |
$jwtParams = array(
|
96 |
-
'aud' =>
|
97 |
'scope' => $this->scopes,
|
98 |
'iat' => $now,
|
99 |
'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
|
@@ -119,14 +119,14 @@ class Google_Auth_AssertionCredentials
|
|
119 |
$header = array('typ' => 'JWT', 'alg' => 'RS256');
|
120 |
|
121 |
$segments = array(
|
122 |
-
|
123 |
-
|
124 |
);
|
125 |
|
126 |
$signingInput = implode('.', $segments);
|
127 |
-
$signer = new
|
128 |
$signature = $signer->sign($signingInput);
|
129 |
-
$segments[] =
|
130 |
|
131 |
return implode(".", $segments);
|
132 |
}
|
24 |
*
|
25 |
* @author Chirag Shah <chirags@google.com>
|
26 |
*/
|
27 |
+
class GoogleGAL_Auth_AssertionCredentials
|
28 |
{
|
29 |
const MAX_TOKEN_LIFETIME_SECS = 3600;
|
30 |
|
93 |
$now = time();
|
94 |
|
95 |
$jwtParams = array(
|
96 |
+
'aud' => GoogleGAL_Auth_OAuth2::OAUTH2_TOKEN_URI,
|
97 |
'scope' => $this->scopes,
|
98 |
'iat' => $now,
|
99 |
'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
|
119 |
$header = array('typ' => 'JWT', 'alg' => 'RS256');
|
120 |
|
121 |
$segments = array(
|
122 |
+
GoogleGAL_Utils::urlSafeB64Encode(json_encode($header)),
|
123 |
+
GoogleGAL_Utils::urlSafeB64Encode(json_encode($payload))
|
124 |
);
|
125 |
|
126 |
$signingInput = implode('.', $segments);
|
127 |
+
$signer = new GoogleGAL_Signer_P12($this->privateKey, $this->privateKeyPassword);
|
128 |
$signature = $signer->sign($signingInput);
|
129 |
+
$segments[] = GoogleGAL_Utils::urlSafeB64Encode($signature);
|
130 |
|
131 |
return implode(".", $segments);
|
132 |
}
|
core/Google/Auth/Exception.php
CHANGED
@@ -17,6 +17,6 @@
|
|
17 |
|
18 |
require_once "Google/Exception.php";
|
19 |
|
20 |
-
class
|
21 |
{
|
22 |
}
|
17 |
|
18 |
require_once "Google/Exception.php";
|
19 |
|
20 |
+
class GoogleGAL_Auth_Exception extends GoogleGAL_Exception
|
21 |
{
|
22 |
}
|
core/Google/Auth/LoginTicket.php
CHANGED
@@ -22,7 +22,7 @@ require_once "Google/Auth/Exception.php";
|
|
22 |
*
|
23 |
* @author Brian Eaton <beaton@google.com>
|
24 |
*/
|
25 |
-
class
|
26 |
{
|
27 |
const USER_ATTR = "sub";
|
28 |
|
@@ -46,7 +46,7 @@ class Google_Auth_LoginTicket
|
|
46 |
|
47 |
/**
|
48 |
* Returns the numeric identifier for the user.
|
49 |
-
* @throws
|
50 |
* @return
|
51 |
*/
|
52 |
public function getUserId()
|
@@ -54,7 +54,7 @@ class Google_Auth_LoginTicket
|
|
54 |
if (array_key_exists(self::USER_ATTR, $this->payload)) {
|
55 |
return $this->payload[self::USER_ATTR];
|
56 |
}
|
57 |
-
throw new
|
58 |
}
|
59 |
|
60 |
/**
|
22 |
*
|
23 |
* @author Brian Eaton <beaton@google.com>
|
24 |
*/
|
25 |
+
class GoogleGAL_Auth_LoginTicket
|
26 |
{
|
27 |
const USER_ATTR = "sub";
|
28 |
|
46 |
|
47 |
/**
|
48 |
* Returns the numeric identifier for the user.
|
49 |
+
* @throws GoogleGAL_Auth_Exception
|
50 |
* @return
|
51 |
*/
|
52 |
public function getUserId()
|
54 |
if (array_key_exists(self::USER_ATTR, $this->payload)) {
|
55 |
return $this->payload[self::USER_ATTR];
|
56 |
}
|
57 |
+
throw new GoogleGAL_Auth_Exception("No user_id in token");
|
58 |
}
|
59 |
|
60 |
/**
|
core/Google/Auth/OAuth2.php
CHANGED
@@ -31,7 +31,7 @@ require_once "Google/Verifier/Pem.php";
|
|
31 |
* @author Chirag Shah <chirags@google.com>
|
32 |
*
|
33 |
*/
|
34 |
-
class
|
35 |
{
|
36 |
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
|
37 |
const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
|
@@ -41,7 +41,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
41 |
const MAX_TOKEN_LIFETIME_SECS = 86400; // one day in seconds
|
42 |
const OAUTH2_ISSUER = 'accounts.google.com';
|
43 |
|
44 |
-
/** @var
|
45 |
private $assertionCredentials;
|
46 |
|
47 |
/**
|
@@ -55,7 +55,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
55 |
private $token = array();
|
56 |
|
57 |
/**
|
58 |
-
* @var
|
59 |
*/
|
60 |
private $client;
|
61 |
|
@@ -63,7 +63,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
63 |
* Instantiates the class, but does not initiate the login flow, leaving it
|
64 |
* to the discretion of the caller.
|
65 |
*/
|
66 |
-
public function __construct(
|
67 |
{
|
68 |
$this->client = $client;
|
69 |
}
|
@@ -74,11 +74,11 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
74 |
* (which can modify the request in what ever way fits the auth mechanism)
|
75 |
* and then calls apiCurlIO::makeRequest on the signed request
|
76 |
*
|
77 |
-
* @param
|
78 |
-
* @return
|
79 |
* responseHttpCode, responseHeaders and responseBody.
|
80 |
*/
|
81 |
-
public function authenticatedRequest(
|
82 |
{
|
83 |
$request = $this->sign($request);
|
84 |
return $this->client->getIo()->makeRequest($request);
|
@@ -86,18 +86,18 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
86 |
|
87 |
/**
|
88 |
* @param string $code
|
89 |
-
* @throws
|
90 |
* @return string
|
91 |
*/
|
92 |
public function authenticate($code)
|
93 |
{
|
94 |
if (strlen($code) == 0) {
|
95 |
-
throw new
|
96 |
}
|
97 |
|
98 |
// We got here from the redirect from a successful authorization grant,
|
99 |
// fetch the access token
|
100 |
-
$request = new
|
101 |
self::OAUTH2_TOKEN_URI,
|
102 |
'POST',
|
103 |
array(),
|
@@ -121,7 +121,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
121 |
if ($decodedResponse != null && $decodedResponse['error']) {
|
122 |
$decodedResponse = $decodedResponse['error'];
|
123 |
}
|
124 |
-
throw new
|
125 |
sprintf(
|
126 |
"Error fetching OAuth2 access token, message: '%s'",
|
127 |
$decodedResponse
|
@@ -165,16 +165,16 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
165 |
|
166 |
/**
|
167 |
* @param string $token
|
168 |
-
* @throws
|
169 |
*/
|
170 |
public function setAccessToken($token)
|
171 |
{
|
172 |
$token = json_decode($token, true);
|
173 |
if ($token == null) {
|
174 |
-
throw new
|
175 |
}
|
176 |
if (! isset($token['access_token'])) {
|
177 |
-
throw new
|
178 |
}
|
179 |
$this->token = $token;
|
180 |
}
|
@@ -189,18 +189,18 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
189 |
$this->state = $state;
|
190 |
}
|
191 |
|
192 |
-
public function setAssertionCredentials(
|
193 |
{
|
194 |
$this->assertionCredentials = $creds;
|
195 |
}
|
196 |
|
197 |
/**
|
198 |
* Include an accessToken in a given apiHttpRequest.
|
199 |
-
* @param
|
200 |
-
* @return
|
201 |
-
* @throws
|
202 |
*/
|
203 |
-
public function sign(
|
204 |
{
|
205 |
// add the developer key to the request before signing it
|
206 |
if ($this->client->getClassConfig($this, 'developer_key')) {
|
@@ -219,7 +219,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
219 |
$this->refreshTokenWithAssertion();
|
220 |
} else {
|
221 |
if (! array_key_exists('refresh_token', $this->token)) {
|
222 |
-
throw new
|
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."
|
@@ -256,7 +256,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
256 |
|
257 |
/**
|
258 |
* Fetches a fresh access token with a given assertion token.
|
259 |
-
* @param
|
260 |
* @return void
|
261 |
*/
|
262 |
public function refreshTokenWithAssertion($assertionCredentials = null)
|
@@ -299,7 +299,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
299 |
|
300 |
private function refreshTokenRequest($params)
|
301 |
{
|
302 |
-
$http = new
|
303 |
self::OAUTH2_TOKEN_URI,
|
304 |
'POST',
|
305 |
array(),
|
@@ -313,25 +313,25 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
313 |
if (200 == $code) {
|
314 |
$token = json_decode($body, true);
|
315 |
if ($token == null) {
|
316 |
-
throw new
|
317 |
}
|
318 |
|
319 |
if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
|
320 |
-
throw new
|
321 |
}
|
322 |
|
323 |
$this->token['access_token'] = $token['access_token'];
|
324 |
$this->token['expires_in'] = $token['expires_in'];
|
325 |
$this->token['created'] = time();
|
326 |
} else {
|
327 |
-
throw new
|
328 |
}
|
329 |
}
|
330 |
|
331 |
/**
|
332 |
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
333 |
* token, if a token isn't provided.
|
334 |
-
* @throws
|
335 |
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
336 |
* @return boolean Returns True if the revocation was successful, otherwise False.
|
337 |
*/
|
@@ -347,7 +347,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
347 |
$token = $this->token['access_token'];
|
348 |
}
|
349 |
}
|
350 |
-
$request = new
|
351 |
self::OAUTH2_REVOKE_URI,
|
352 |
'POST',
|
353 |
array(),
|
@@ -404,7 +404,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
404 |
if ($file) {
|
405 |
return json_decode($file, true);
|
406 |
} else {
|
407 |
-
throw new
|
408 |
"Failed to retrieve verification certificates: '" .
|
409 |
$url . "'."
|
410 |
);
|
@@ -413,7 +413,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
413 |
|
414 |
// This relies on makeRequest caching certificate responses.
|
415 |
$request = $this->client->getIo()->makeRequest(
|
416 |
-
new
|
417 |
$url
|
418 |
)
|
419 |
);
|
@@ -423,7 +423,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
423 |
return $certs;
|
424 |
}
|
425 |
}
|
426 |
-
throw new
|
427 |
"Failed to retrieve verification certificates: '" .
|
428 |
$request->getResponseBody() . "'.",
|
429 |
$request->getResponseHttpCode()
|
@@ -438,7 +438,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
438 |
*
|
439 |
* @param $id_token
|
440 |
* @param $audience
|
441 |
-
* @return
|
442 |
*/
|
443 |
public function verifyIdToken($id_token = null, $audience = null)
|
444 |
{
|
@@ -477,28 +477,28 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
477 |
|
478 |
$segments = explode(".", $jwt);
|
479 |
if (count($segments) != 3) {
|
480 |
-
throw new
|
481 |
}
|
482 |
$signed = $segments[0] . "." . $segments[1];
|
483 |
-
$signature =
|
484 |
|
485 |
// Parse envelope.
|
486 |
-
$envelope = json_decode(
|
487 |
if (!$envelope) {
|
488 |
-
throw new
|
489 |
}
|
490 |
|
491 |
// Parse token
|
492 |
-
$json_body =
|
493 |
$payload = json_decode($json_body, true);
|
494 |
if (!$payload) {
|
495 |
-
throw new
|
496 |
}
|
497 |
|
498 |
// Check signature
|
499 |
$verified = false;
|
500 |
foreach ($certs as $keyName => $pem) {
|
501 |
-
$public_key = new
|
502 |
if ($public_key->verify($signed, $signature)) {
|
503 |
$verified = true;
|
504 |
break;
|
@@ -506,7 +506,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
506 |
}
|
507 |
|
508 |
if (!$verified) {
|
509 |
-
throw new
|
510 |
}
|
511 |
|
512 |
// Check issued-at timestamp
|
@@ -515,7 +515,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
515 |
$iat = $payload["iat"];
|
516 |
}
|
517 |
if (!$iat) {
|
518 |
-
throw new
|
519 |
}
|
520 |
$earliest = $iat - self::CLOCK_SKEW_SECS;
|
521 |
|
@@ -526,17 +526,17 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
526 |
$exp = $payload["exp"];
|
527 |
}
|
528 |
if (!$exp) {
|
529 |
-
throw new
|
530 |
}
|
531 |
if ($exp >= $now + $max_expiry) {
|
532 |
-
throw new
|
533 |
sprintf("Expiration time too far in future: %s", $json_body)
|
534 |
);
|
535 |
}
|
536 |
|
537 |
$latest = $exp + self::CLOCK_SKEW_SECS;
|
538 |
if ($now < $earliest) {
|
539 |
-
throw new
|
540 |
sprintf(
|
541 |
"Token used too early, %s < %s: %s",
|
542 |
$now,
|
@@ -546,7 +546,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
546 |
);
|
547 |
}
|
548 |
if ($now > $latest) {
|
549 |
-
throw new
|
550 |
sprintf(
|
551 |
"Token used too late, %s > %s: %s",
|
552 |
$now,
|
@@ -558,7 +558,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
558 |
|
559 |
$iss = $payload['iss'];
|
560 |
if ($issuer && $iss != $issuer) {
|
561 |
-
throw new
|
562 |
sprintf(
|
563 |
"Invalid issuer, %s != %s: %s",
|
564 |
$iss,
|
@@ -571,7 +571,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
571 |
// Check audience
|
572 |
$aud = $payload["aud"];
|
573 |
if ($aud != $required_audience) {
|
574 |
-
throw new
|
575 |
sprintf(
|
576 |
"Wrong recipient, %s != %s:",
|
577 |
$aud,
|
@@ -582,6 +582,6 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
|
|
582 |
}
|
583 |
|
584 |
// All good.
|
585 |
-
return new
|
586 |
}
|
587 |
}
|
31 |
* @author Chirag Shah <chirags@google.com>
|
32 |
*
|
33 |
*/
|
34 |
+
class GoogleGAL_Auth_OAuth2 extends GoogleGAL_Auth_Abstract
|
35 |
{
|
36 |
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
|
37 |
const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
|
41 |
const MAX_TOKEN_LIFETIME_SECS = 86400; // one day in seconds
|
42 |
const OAUTH2_ISSUER = 'accounts.google.com';
|
43 |
|
44 |
+
/** @var GoogleGAL_Auth_AssertionCredentials $assertionCredentials */
|
45 |
private $assertionCredentials;
|
46 |
|
47 |
/**
|
55 |
private $token = array();
|
56 |
|
57 |
/**
|
58 |
+
* @var GoogleGAL_Client the base client
|
59 |
*/
|
60 |
private $client;
|
61 |
|
63 |
* Instantiates the class, but does not initiate the login flow, leaving it
|
64 |
* to the discretion of the caller.
|
65 |
*/
|
66 |
+
public function __construct(GoogleGAL_Client $client)
|
67 |
{
|
68 |
$this->client = $client;
|
69 |
}
|
74 |
* (which can modify the request in what ever way fits the auth mechanism)
|
75 |
* and then calls apiCurlIO::makeRequest on the signed request
|
76 |
*
|
77 |
+
* @param GoogleGAL_Http_Request $request
|
78 |
+
* @return GoogleGAL_Http_Request The resulting HTTP response including the
|
79 |
* responseHttpCode, responseHeaders and responseBody.
|
80 |
*/
|
81 |
+
public function authenticatedRequest(GoogleGAL_Http_Request $request)
|
82 |
{
|
83 |
$request = $this->sign($request);
|
84 |
return $this->client->getIo()->makeRequest($request);
|
86 |
|
87 |
/**
|
88 |
* @param string $code
|
89 |
+
* @throws GoogleGAL_Auth_Exception
|
90 |
* @return string
|
91 |
*/
|
92 |
public function authenticate($code)
|
93 |
{
|
94 |
if (strlen($code) == 0) {
|
95 |
+
throw new GoogleGAL_Auth_Exception("Invalid code");
|
96 |
}
|
97 |
|
98 |
// We got here from the redirect from a successful authorization grant,
|
99 |
// fetch the access token
|
100 |
+
$request = new GoogleGAL_Http_Request(
|
101 |
self::OAUTH2_TOKEN_URI,
|
102 |
'POST',
|
103 |
array(),
|
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
|
165 |
|
166 |
/**
|
167 |
* @param string $token
|
168 |
+
* @throws GoogleGAL_Auth_Exception
|
169 |
*/
|
170 |
public function setAccessToken($token)
|
171 |
{
|
172 |
$token = json_decode($token, true);
|
173 |
if ($token == null) {
|
174 |
+
throw new GoogleGAL_Auth_Exception('Could not json decode the token');
|
175 |
}
|
176 |
if (! isset($token['access_token'])) {
|
177 |
+
throw new GoogleGAL_Auth_Exception("Invalid token format");
|
178 |
}
|
179 |
$this->token = $token;
|
180 |
}
|
189 |
$this->state = $state;
|
190 |
}
|
191 |
|
192 |
+
public function setAssertionCredentials(GoogleGAL_Auth_AssertionCredentials $creds)
|
193 |
{
|
194 |
$this->assertionCredentials = $creds;
|
195 |
}
|
196 |
|
197 |
/**
|
198 |
* Include an accessToken in a given apiHttpRequest.
|
199 |
+
* @param GoogleGAL_Http_Request $request
|
200 |
+
* @return GoogleGAL_Http_Request
|
201 |
+
* @throws GoogleGAL_Auth_Exception
|
202 |
*/
|
203 |
+
public function sign(GoogleGAL_Http_Request $request)
|
204 |
{
|
205 |
// add the developer key to the request before signing it
|
206 |
if ($this->client->getClassConfig($this, 'developer_key')) {
|
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."
|
256 |
|
257 |
/**
|
258 |
* Fetches a fresh access token with a given assertion token.
|
259 |
+
* @param GoogleGAL_Auth_AssertionCredentials $assertionCredentials optional.
|
260 |
* @return void
|
261 |
*/
|
262 |
public function refreshTokenWithAssertion($assertionCredentials = null)
|
299 |
|
300 |
private function refreshTokenRequest($params)
|
301 |
{
|
302 |
+
$http = new GoogleGAL_Http_Request(
|
303 |
self::OAUTH2_TOKEN_URI,
|
304 |
'POST',
|
305 |
array(),
|
313 |
if (200 == $code) {
|
314 |
$token = json_decode($body, true);
|
315 |
if ($token == null) {
|
316 |
+
throw new GoogleGAL_Auth_Exception("Could not json decode the access token");
|
317 |
}
|
318 |
|
319 |
if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
|
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();
|
326 |
} else {
|
327 |
+
throw new GoogleGAL_Auth_Exception("Error refreshing the OAuth2 token, message: '$body'", $code);
|
328 |
}
|
329 |
}
|
330 |
|
331 |
/**
|
332 |
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
333 |
* token, if a token isn't provided.
|
334 |
+
* @throws GoogleGAL_Auth_Exception
|
335 |
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
336 |
* @return boolean Returns True if the revocation was successful, otherwise False.
|
337 |
*/
|
347 |
$token = $this->token['access_token'];
|
348 |
}
|
349 |
}
|
350 |
+
$request = new GoogleGAL_Http_Request(
|
351 |
self::OAUTH2_REVOKE_URI,
|
352 |
'POST',
|
353 |
array(),
|
404 |
if ($file) {
|
405 |
return json_decode($file, true);
|
406 |
} else {
|
407 |
+
throw new GoogleGAL_Auth_Exception(
|
408 |
"Failed to retrieve verification certificates: '" .
|
409 |
$url . "'."
|
410 |
);
|
413 |
|
414 |
// This relies on makeRequest caching certificate responses.
|
415 |
$request = $this->client->getIo()->makeRequest(
|
416 |
+
new GoogleGAL_Http_Request(
|
417 |
$url
|
418 |
)
|
419 |
);
|
423 |
return $certs;
|
424 |
}
|
425 |
}
|
426 |
+
throw new GoogleGAL_Auth_Exception(
|
427 |
"Failed to retrieve verification certificates: '" .
|
428 |
$request->getResponseBody() . "'.",
|
429 |
$request->getResponseHttpCode()
|
438 |
*
|
439 |
* @param $id_token
|
440 |
* @param $audience
|
441 |
+
* @return GoogleGAL_Auth_LoginTicket
|
442 |
*/
|
443 |
public function verifyIdToken($id_token = null, $audience = null)
|
444 |
{
|
477 |
|
478 |
$segments = explode(".", $jwt);
|
479 |
if (count($segments) != 3) {
|
480 |
+
throw new GoogleGAL_Auth_Exception("Wrong number of segments in token: $jwt");
|
481 |
}
|
482 |
$signed = $segments[0] . "." . $segments[1];
|
483 |
+
$signature = GoogleGAL_Utils::urlSafeB64Decode($segments[2]);
|
484 |
|
485 |
// Parse envelope.
|
486 |
+
$envelope = json_decode(GoogleGAL_Utils::urlSafeB64Decode($segments[0]), true);
|
487 |
if (!$envelope) {
|
488 |
+
throw new GoogleGAL_Auth_Exception("Can't parse token envelope: " . $segments[0]);
|
489 |
}
|
490 |
|
491 |
// Parse token
|
492 |
+
$json_body = GoogleGAL_Utils::urlSafeB64Decode($segments[1]);
|
493 |
$payload = json_decode($json_body, true);
|
494 |
if (!$payload) {
|
495 |
+
throw new GoogleGAL_Auth_Exception("Can't parse token payload: " . $segments[1]);
|
496 |
}
|
497 |
|
498 |
// Check signature
|
499 |
$verified = false;
|
500 |
foreach ($certs as $keyName => $pem) {
|
501 |
+
$public_key = new GoogleGAL_Verifier_Pem($pem);
|
502 |
if ($public_key->verify($signed, $signature)) {
|
503 |
$verified = true;
|
504 |
break;
|
506 |
}
|
507 |
|
508 |
if (!$verified) {
|
509 |
+
throw new GoogleGAL_Auth_Exception("Invalid token signature: $jwt");
|
510 |
}
|
511 |
|
512 |
// Check issued-at timestamp
|
515 |
$iat = $payload["iat"];
|
516 |
}
|
517 |
if (!$iat) {
|
518 |
+
throw new GoogleGAL_Auth_Exception("No issue time in token: $json_body");
|
519 |
}
|
520 |
$earliest = $iat - self::CLOCK_SKEW_SECS;
|
521 |
|
526 |
$exp = $payload["exp"];
|
527 |
}
|
528 |
if (!$exp) {
|
529 |
+
throw new GoogleGAL_Auth_Exception("No expiration time in token: $json_body");
|
530 |
}
|
531 |
if ($exp >= $now + $max_expiry) {
|
532 |
+
throw new GoogleGAL_Auth_Exception(
|
533 |
sprintf("Expiration time too far in future: %s", $json_body)
|
534 |
);
|
535 |
}
|
536 |
|
537 |
$latest = $exp + self::CLOCK_SKEW_SECS;
|
538 |
if ($now < $earliest) {
|
539 |
+
throw new GoogleGAL_Auth_Exception(
|
540 |
sprintf(
|
541 |
"Token used too early, %s < %s: %s",
|
542 |
$now,
|
546 |
);
|
547 |
}
|
548 |
if ($now > $latest) {
|
549 |
+
throw new GoogleGAL_Auth_Exception(
|
550 |
sprintf(
|
551 |
"Token used too late, %s > %s: %s",
|
552 |
$now,
|
558 |
|
559 |
$iss = $payload['iss'];
|
560 |
if ($issuer && $iss != $issuer) {
|
561 |
+
throw new GoogleGAL_Auth_Exception(
|
562 |
sprintf(
|
563 |
"Invalid issuer, %s != %s: %s",
|
564 |
$iss,
|
571 |
// Check audience
|
572 |
$aud = $payload["aud"];
|
573 |
if ($aud != $required_audience) {
|
574 |
+
throw new GoogleGAL_Auth_Exception(
|
575 |
sprintf(
|
576 |
"Wrong recipient, %s != %s:",
|
577 |
$aud,
|
582 |
}
|
583 |
|
584 |
// All good.
|
585 |
+
return new GoogleGAL_Auth_LoginTicket($envelope, $payload);
|
586 |
}
|
587 |
}
|
core/Google/Auth/Simple.php
CHANGED
@@ -25,12 +25,12 @@ require_once "Google/Http/Request.php";
|
|
25 |
* @author Chris Chabot <chabotc@google.com>
|
26 |
* @author Chirag Shah <chirags@google.com>
|
27 |
*/
|
28 |
-
class
|
29 |
{
|
30 |
private $key = null;
|
31 |
private $client;
|
32 |
|
33 |
-
public function __construct(
|
34 |
{
|
35 |
$this->client = $client;
|
36 |
}
|
@@ -41,11 +41,11 @@ class Google_Auth_Simple extends Google_Auth_Abstract
|
|
41 |
* (which can modify the request in what ever way fits the auth mechanism)
|
42 |
* and then calls apiCurlIO::makeRequest on the signed request
|
43 |
*
|
44 |
-
* @param
|
45 |
-
* @return
|
46 |
* responseHttpCode, responseHeaders and responseBody.
|
47 |
*/
|
48 |
-
public function authenticatedRequest(
|
49 |
{
|
50 |
$request = $this->sign($request);
|
51 |
return $this->io->makeRequest($request);
|
@@ -53,7 +53,7 @@ class Google_Auth_Simple extends Google_Auth_Abstract
|
|
53 |
|
54 |
public function authenticate($code)
|
55 |
{
|
56 |
-
throw new
|
57 |
}
|
58 |
|
59 |
public function setAccessToken($accessToken)
|
@@ -81,7 +81,7 @@ class Google_Auth_Simple extends Google_Auth_Abstract
|
|
81 |
/* noop*/
|
82 |
}
|
83 |
|
84 |
-
public function sign(
|
85 |
{
|
86 |
$key = $this->client->getClassConfig($this, 'developer_key');
|
87 |
if ($key) {
|
25 |
* @author Chris Chabot <chabotc@google.com>
|
26 |
* @author Chirag Shah <chirags@google.com>
|
27 |
*/
|
28 |
+
class GoogleGAL_Auth_Simple extends GoogleGAL_Auth_Abstract
|
29 |
{
|
30 |
private $key = null;
|
31 |
private $client;
|
32 |
|
33 |
+
public function __construct(GoogleGAL_Client $client, $config = null)
|
34 |
{
|
35 |
$this->client = $client;
|
36 |
}
|
41 |
* (which can modify the request in what ever way fits the auth mechanism)
|
42 |
* and then calls apiCurlIO::makeRequest on the signed request
|
43 |
*
|
44 |
+
* @param GoogleGAL_Http_Request $request
|
45 |
+
* @return GoogleGAL_Http_Request The resulting HTTP response including the
|
46 |
* responseHttpCode, responseHeaders and responseBody.
|
47 |
*/
|
48 |
+
public function authenticatedRequest(GoogleGAL_Http_Request $request)
|
49 |
{
|
50 |
$request = $this->sign($request);
|
51 |
return $this->io->makeRequest($request);
|
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)
|
81 |
/* noop*/
|
82 |
}
|
83 |
|
84 |
+
public function sign(GoogleGAL_Http_Request $request)
|
85 |
{
|
86 |
$key = $this->client->getClassConfig($this, 'developer_key');
|
87 |
if ($key) {
|
core/Google/Cache/Abstract.php
CHANGED
@@ -20,10 +20,10 @@
|
|
20 |
*
|
21 |
* @author Chris Chabot <chabotc@google.com>
|
22 |
*/
|
23 |
-
abstract class
|
24 |
{
|
25 |
|
26 |
-
abstract public function __construct(
|
27 |
|
28 |
/**
|
29 |
* Retrieves the data for the given key, or false if they
|
20 |
*
|
21 |
* @author Chris Chabot <chabotc@google.com>
|
22 |
*/
|
23 |
+
abstract class GoogleGAL_Cache_Abstract
|
24 |
{
|
25 |
|
26 |
+
abstract public function __construct(GoogleGAL_Client $client);
|
27 |
|
28 |
/**
|
29 |
* Retrieves the data for the given key, or false if they
|
core/Google/Cache/Apc.php
CHANGED
@@ -26,12 +26,12 @@ require_once "Google/Cache/Exception.php";
|
|
26 |
*
|
27 |
* @author Chris Chabot <chabotc@google.com>
|
28 |
*/
|
29 |
-
class
|
30 |
{
|
31 |
-
public function __construct(
|
32 |
{
|
33 |
if (! function_exists('apc_add') ) {
|
34 |
-
throw new
|
35 |
}
|
36 |
}
|
37 |
|
@@ -58,7 +58,7 @@ class Google_Cache_Apc extends Google_Cache_Abstract
|
|
58 |
{
|
59 |
$rc = apc_store($key, array('time' => time(), 'data' => $value));
|
60 |
if ($rc == false) {
|
61 |
-
throw new
|
62 |
}
|
63 |
}
|
64 |
|
26 |
*
|
27 |
* @author Chris Chabot <chabotc@google.com>
|
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 |
|
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 |
|
core/Google/Cache/Exception.php
CHANGED
@@ -16,6 +16,6 @@
|
|
16 |
*/
|
17 |
require_once "Google/Exception.php";
|
18 |
|
19 |
-
class
|
20 |
{
|
21 |
}
|
16 |
*/
|
17 |
require_once "Google/Exception.php";
|
18 |
|
19 |
+
class GoogleGAL_Cache_Exception extends GoogleGAL_Exception
|
20 |
{
|
21 |
}
|
core/Google/Cache/File.php
CHANGED
@@ -26,13 +26,13 @@ require_once "Google/Cache/Exception.php";
|
|
26 |
*
|
27 |
* @author Chris Chabot <chabotc@google.com>
|
28 |
*/
|
29 |
-
class
|
30 |
{
|
31 |
const MAX_LOCK_RETRIES = 10;
|
32 |
private $path;
|
33 |
private $fh;
|
34 |
|
35 |
-
public function __construct(
|
36 |
{
|
37 |
$this->path = $client->getClassConfig($this, 'directory');
|
38 |
}
|
@@ -79,7 +79,7 @@ class Google_Cache_File extends Google_Cache_Abstract
|
|
79 |
{
|
80 |
$file = $this->getCacheFile($key);
|
81 |
if (file_exists($file) && !unlink($file)) {
|
82 |
-
throw new
|
83 |
}
|
84 |
}
|
85 |
|
@@ -101,7 +101,7 @@ class Google_Cache_File extends Google_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
|
105 |
}
|
106 |
}
|
107 |
return $storageDir;
|
26 |
*
|
27 |
* @author Chris Chabot <chabotc@google.com>
|
28 |
*/
|
29 |
+
class GoogleGAL_Cache_File extends GoogleGAL_Cache_Abstract
|
30 |
{
|
31 |
const MAX_LOCK_RETRIES = 10;
|
32 |
private $path;
|
33 |
private $fh;
|
34 |
|
35 |
+
public function __construct(GoogleGAL_Client $client)
|
36 |
{
|
37 |
$this->path = $client->getClassConfig($this, 'directory');
|
38 |
}
|
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 |
|
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;
|
core/Google/Cache/Memcache.php
CHANGED
@@ -28,17 +28,17 @@ require_once "Google/Cache/Exception.php";
|
|
28 |
*
|
29 |
* @author Chris Chabot <chabotc@google.com>
|
30 |
*/
|
31 |
-
class
|
32 |
{
|
33 |
private $connection = false;
|
34 |
private $mc = false;
|
35 |
private $host;
|
36 |
private $port;
|
37 |
|
38 |
-
public function __construct(
|
39 |
{
|
40 |
if (!function_exists('memcache_connect') && !class_exists("Memcached")) {
|
41 |
-
throw new
|
42 |
}
|
43 |
if ($client->isAppEngine()) {
|
44 |
// No credentials needed for GAE.
|
@@ -48,7 +48,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
|
|
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
|
52 |
}
|
53 |
}
|
54 |
}
|
@@ -79,7 +79,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
|
|
79 |
* @inheritDoc
|
80 |
* @param string $key
|
81 |
* @param string $value
|
82 |
-
* @throws
|
83 |
*/
|
84 |
public function set($key, $value)
|
85 |
{
|
@@ -94,7 +94,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
|
|
94 |
$rc = memcache_set($this->connection, $key, $data, false);
|
95 |
}
|
96 |
if ($rc == false) {
|
97 |
-
throw new
|
98 |
}
|
99 |
}
|
100 |
|
@@ -131,7 +131,7 @@ class Google_Cache_Memcache extends Google_Cache_Abstract
|
|
131 |
}
|
132 |
|
133 |
if (! $this->connection) {
|
134 |
-
throw new
|
135 |
}
|
136 |
}
|
137 |
}
|
28 |
*
|
29 |
* @author Chris Chabot <chabotc@google.com>
|
30 |
*/
|
31 |
+
class GoogleGAL_Cache_Memcache extends GoogleGAL_Cache_Abstract
|
32 |
{
|
33 |
private $connection = false;
|
34 |
private $mc = false;
|
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.
|
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 |
}
|
79 |
* @inheritDoc
|
80 |
* @param string $key
|
81 |
* @param string $value
|
82 |
+
* @throws GoogleGAL_Cache_Exception
|
83 |
*/
|
84 |
public function set($key, $value)
|
85 |
{
|
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 |
|
131 |
}
|
132 |
|
133 |
if (! $this->connection) {
|
134 |
+
throw new GoogleGAL_Cache_Exception("Couldn't connect to memcache server");
|
135 |
}
|
136 |
}
|
137 |
}
|
core/Google/Cache/Null.php
CHANGED
@@ -22,9 +22,9 @@ require_once "Google/Cache/Exception.php";
|
|
22 |
* A blank storage class, for cases where caching is not
|
23 |
* required.
|
24 |
*/
|
25 |
-
class
|
26 |
{
|
27 |
-
public function __construct(
|
28 |
{
|
29 |
|
30 |
}
|
22 |
* A blank storage class, for cases where caching is not
|
23 |
* required.
|
24 |
*/
|
25 |
+
class GoogleGAL_Cache_Null extends GoogleGAL_Cache_Abstract
|
26 |
{
|
27 |
+
public function __construct(GoogleGAL_Client $client)
|
28 |
{
|
29 |
|
30 |
}
|
core/Google/Client.php
CHANGED
@@ -34,27 +34,27 @@ require_once 'Google/Service/Resource.php';
|
|
34 |
* @author Chris Chabot <chabotc@google.com>
|
35 |
* @author Chirag Shah <chirags@google.com>
|
36 |
*/
|
37 |
-
class
|
38 |
{
|
39 |
const LIBVER = "1.0.5-beta";
|
40 |
const USER_AGENT_SUFFIX = "google-api-php-client/";
|
41 |
/**
|
42 |
-
* @var
|
43 |
*/
|
44 |
private $auth;
|
45 |
|
46 |
/**
|
47 |
-
* @var
|
48 |
*/
|
49 |
private $io;
|
50 |
|
51 |
/**
|
52 |
-
* @var
|
53 |
*/
|
54 |
private $cache;
|
55 |
|
56 |
/**
|
57 |
-
* @var
|
58 |
*/
|
59 |
private $config;
|
60 |
|
@@ -76,7 +76,7 @@ class Google_Client
|
|
76 |
/**
|
77 |
* Construct the Google Client.
|
78 |
*
|
79 |
-
* @param $config
|
80 |
*/
|
81 |
public function __construct($config = null)
|
82 |
{
|
@@ -86,26 +86,26 @@ class Google_Client
|
|
86 |
}
|
87 |
|
88 |
if (is_string($config) && strlen($config)) {
|
89 |
-
$config = new
|
90 |
-
} else if ( !($config instanceof
|
91 |
-
$config = new
|
92 |
|
93 |
if ($this->isAppEngine()) {
|
94 |
// Automatically use Memcache if we're in AppEngine.
|
95 |
-
$config->setCacheClass('
|
96 |
}
|
97 |
|
98 |
if (version_compare(phpversion(), "5.3.4", "<=") || $this->isAppEngine()) {
|
99 |
// Automatically disable compress.zlib, as currently unsupported.
|
100 |
-
$config->setClassConfig('
|
101 |
}
|
102 |
}
|
103 |
|
104 |
-
if ($config->getIoClass() ==
|
105 |
if (function_exists('curl_version')) {
|
106 |
-
$config->setIoClass("
|
107 |
} else {
|
108 |
-
$config->setIoClass("
|
109 |
}
|
110 |
}
|
111 |
|
@@ -147,7 +147,7 @@ class Google_Client
|
|
147 |
$data = json_decode($json);
|
148 |
$key = isset($data->installed) ? 'installed' : 'web';
|
149 |
if (!isset($data->$key)) {
|
150 |
-
throw new
|
151 |
}
|
152 |
$this->setClientId($data->$key->client_id);
|
153 |
$this->setClientSecret($data->$key->client_secret);
|
@@ -175,7 +175,7 @@ class Google_Client
|
|
175 |
public function prepareScopes()
|
176 |
{
|
177 |
if (empty($this->requestedScopes)) {
|
178 |
-
throw new
|
179 |
}
|
180 |
$scopes = implode(' ', $this->requestedScopes);
|
181 |
return $scopes;
|
@@ -183,7 +183,7 @@ class Google_Client
|
|
183 |
|
184 |
/**
|
185 |
* Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl()
|
186 |
-
* or
|
187 |
* @param string $accessToken JSON encoded string containing in the following format:
|
188 |
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
|
189 |
* "expires_in":3600, "id_token":"TOKEN", "created":1320790426}
|
@@ -200,9 +200,9 @@ class Google_Client
|
|
200 |
|
201 |
/**
|
202 |
* Set the authenticator object
|
203 |
-
* @param
|
204 |
*/
|
205 |
-
public function setAuth(
|
206 |
{
|
207 |
$this->config->setAuthClass(get_class($auth));
|
208 |
$this->auth = $auth;
|
@@ -210,9 +210,9 @@ class Google_Client
|
|
210 |
|
211 |
/**
|
212 |
* Set the IO object
|
213 |
-
* @param
|
214 |
*/
|
215 |
-
public function setIo(
|
216 |
{
|
217 |
$this->config->setIoClass(get_class($io));
|
218 |
$this->io = $io;
|
@@ -220,9 +220,9 @@ class Google_Client
|
|
220 |
|
221 |
/**
|
222 |
* Set the Cache object
|
223 |
-
* @param
|
224 |
*/
|
225 |
-
public function setCache(
|
226 |
{
|
227 |
$this->config->setCacheClass(get_class($cache));
|
228 |
$this->cache = $cache;
|
@@ -367,7 +367,7 @@ class Google_Client
|
|
367 |
/**
|
368 |
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
369 |
* token, if a token isn't provided.
|
370 |
-
* @throws
|
371 |
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
372 |
* @return boolean Returns True if the revocation was successful, otherwise False.
|
373 |
*/
|
@@ -379,9 +379,9 @@ class Google_Client
|
|
379 |
/**
|
380 |
* Verify an id_token. This method will verify the current id_token, if one
|
381 |
* isn't provided.
|
382 |
-
* @throws
|
383 |
* @param string|null $token The token (id_token) that should be verified.
|
384 |
-
* @return
|
385 |
* successful.
|
386 |
*/
|
387 |
public function verifyIdToken($token = null)
|
@@ -401,16 +401,16 @@ class Google_Client
|
|
401 |
*/
|
402 |
public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)
|
403 |
{
|
404 |
-
$auth = new
|
405 |
$certs = $auth->retrieveCertsFromLocation($cert_location);
|
406 |
return $auth->verifySignedJwtWithCerts($id_token, $certs, $audience, $issuer, $max_expiry);
|
407 |
}
|
408 |
|
409 |
/**
|
410 |
-
* @param
|
411 |
* @return void
|
412 |
*/
|
413 |
-
public function setAssertionCredentials(
|
414 |
{
|
415 |
$this->getAuth()->setAssertionCredentials($creds);
|
416 |
}
|
@@ -486,21 +486,21 @@ class Google_Client
|
|
486 |
*/
|
487 |
public function execute($request)
|
488 |
{
|
489 |
-
if ($request instanceof
|
490 |
$request->setUserAgent(
|
491 |
$this->getApplicationName()
|
492 |
. " " . self::USER_AGENT_SUFFIX
|
493 |
. $this->getLibraryVersion()
|
494 |
);
|
495 |
-
if (!$this->getClassConfig("
|
496 |
$request->enableGzip();
|
497 |
}
|
498 |
$request->maybeMoveParametersToBody();
|
499 |
-
return
|
500 |
-
} else if ($request instanceof
|
501 |
return $request->execute();
|
502 |
} else {
|
503 |
-
throw new
|
504 |
}
|
505 |
}
|
506 |
|
@@ -514,7 +514,7 @@ class Google_Client
|
|
514 |
}
|
515 |
|
516 |
/**
|
517 |
-
* @return
|
518 |
*/
|
519 |
public function getAuth()
|
520 |
{
|
@@ -526,7 +526,7 @@ class Google_Client
|
|
526 |
}
|
527 |
|
528 |
/**
|
529 |
-
* @return
|
530 |
*/
|
531 |
public function getIo()
|
532 |
{
|
@@ -538,7 +538,7 @@ class Google_Client
|
|
538 |
}
|
539 |
|
540 |
/**
|
541 |
-
* @return
|
542 |
*/
|
543 |
public function getCache()
|
544 |
{
|
@@ -564,7 +564,7 @@ class Google_Client
|
|
564 |
|
565 |
/**
|
566 |
* Set configuration specific to a given class.
|
567 |
-
* $config->setClassConfig('
|
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
|
34 |
* @author Chris Chabot <chabotc@google.com>
|
35 |
* @author Chirag Shah <chirags@google.com>
|
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
|
43 |
*/
|
44 |
private $auth;
|
45 |
|
46 |
/**
|
47 |
+
* @var GoogleGAL_IO_Abstract $io
|
48 |
*/
|
49 |
private $io;
|
50 |
|
51 |
/**
|
52 |
+
* @var GoogleGAL_Cache_Abstract $cache
|
53 |
*/
|
54 |
private $cache;
|
55 |
|
56 |
/**
|
57 |
+
* @var GoogleGAL_Config $config
|
58 |
*/
|
59 |
private $config;
|
60 |
|
76 |
/**
|
77 |
* Construct the Google Client.
|
78 |
*
|
79 |
+
* @param $config GoogleGAL_Config or string for the ini file to load
|
80 |
*/
|
81 |
public function __construct($config = null)
|
82 |
{
|
86 |
}
|
87 |
|
88 |
if (is_string($config) && strlen($config)) {
|
89 |
+
$config = new GoogleGAL_Config($config);
|
90 |
+
} else if ( !($config instanceof GoogleGAL_Config)) {
|
91 |
+
$config = new GoogleGAL_Config();
|
92 |
|
93 |
if ($this->isAppEngine()) {
|
94 |
// Automatically use Memcache if we're in AppEngine.
|
95 |
+
$config->setCacheClass('GoogleGAL_Cache_Memcache');
|
96 |
}
|
97 |
|
98 |
if (version_compare(phpversion(), "5.3.4", "<=") || $this->isAppEngine()) {
|
99 |
// Automatically disable compress.zlib, as currently unsupported.
|
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')) {
|
106 |
+
$config->setIoClass("GoogleGAL_Io_Curl");
|
107 |
} else {
|
108 |
+
$config->setIoClass("GoogleGAL_Io_Stream");
|
109 |
}
|
110 |
}
|
111 |
|
147 |
$data = json_decode($json);
|
148 |
$key = isset($data->installed) ? 'installed' : 'web';
|
149 |
if (!isset($data->$key)) {
|
150 |
+
throw new GoogleGAL_Exception("Invalid client secret JSON file.");
|
151 |
}
|
152 |
$this->setClientId($data->$key->client_id);
|
153 |
$this->setClientSecret($data->$key->client_secret);
|
175 |
public function prepareScopes()
|
176 |
{
|
177 |
if (empty($this->requestedScopes)) {
|
178 |
+
throw new GoogleGAL_Auth_Exception("No scopes specified");
|
179 |
}
|
180 |
$scopes = implode(' ', $this->requestedScopes);
|
181 |
return $scopes;
|
183 |
|
184 |
/**
|
185 |
* Set the OAuth 2.0 access token using the string that resulted from calling createAuthUrl()
|
186 |
+
* or GoogleGAL_Client#getAccessToken().
|
187 |
* @param string $accessToken JSON encoded string containing in the following format:
|
188 |
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
|
189 |
* "expires_in":3600, "id_token":"TOKEN", "created":1320790426}
|
200 |
|
201 |
/**
|
202 |
* Set the authenticator object
|
203 |
+
* @param GoogleGAL_Auth_Abstract $auth
|
204 |
*/
|
205 |
+
public function setAuth(GoogleGAL_Auth_Abstract $auth)
|
206 |
{
|
207 |
$this->config->setAuthClass(get_class($auth));
|
208 |
$this->auth = $auth;
|
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 |
|
221 |
/**
|
222 |
* Set the Cache object
|
223 |
+
* @param GoogleGAL_Cache_Abstract $auth
|
224 |
*/
|
225 |
+
public function setCache(GoogleGAL_Cache_Abstract $cache)
|
226 |
{
|
227 |
$this->config->setCacheClass(get_class($cache));
|
228 |
$this->cache = $cache;
|
367 |
/**
|
368 |
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
369 |
* token, if a token isn't provided.
|
370 |
+
* @throws GoogleGAL_Auth_Exception
|
371 |
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
372 |
* @return boolean Returns True if the revocation was successful, otherwise False.
|
373 |
*/
|
379 |
/**
|
380 |
* Verify an id_token. This method will verify the current id_token, if one
|
381 |
* isn't provided.
|
382 |
+
* @throws GoogleGAL_Auth_Exception
|
383 |
* @param string|null $token The token (id_token) that should be verified.
|
384 |
+
* @return GoogleGAL_Auth_LoginTicket Returns an apiLoginTicket if the verification was
|
385 |
* successful.
|
386 |
*/
|
387 |
public function verifyIdToken($token = null)
|
401 |
*/
|
402 |
public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null)
|
403 |
{
|
404 |
+
$auth = new GoogleGAL_Auth_OAuth2($this);
|
405 |
$certs = $auth->retrieveCertsFromLocation($cert_location);
|
406 |
return $auth->verifySignedJwtWithCerts($id_token, $certs, $audience, $issuer, $max_expiry);
|
407 |
}
|
408 |
|
409 |
/**
|
410 |
+
* @param GoogleGAL_Auth_AssertionCredentials $creds
|
411 |
* @return void
|
412 |
*/
|
413 |
+
public function setAssertionCredentials(GoogleGAL_Auth_AssertionCredentials $creds)
|
414 |
{
|
415 |
$this->getAuth()->setAssertionCredentials($creds);
|
416 |
}
|
486 |
*/
|
487 |
public function execute($request)
|
488 |
{
|
489 |
+
if ($request instanceof GoogleGAL_Http_Request) {
|
490 |
$request->setUserAgent(
|
491 |
$this->getApplicationName()
|
492 |
. " " . self::USER_AGENT_SUFFIX
|
493 |
. $this->getLibraryVersion()
|
494 |
);
|
495 |
+
if (!$this->getClassConfig("GoogleGAL_Http_Request", "disable_gzip")) {
|
496 |
$request->enableGzip();
|
497 |
}
|
498 |
$request->maybeMoveParametersToBody();
|
499 |
+
return GoogleGAL_Http_REST::execute($this, $request);
|
500 |
+
} else if ($request instanceof GoogleGAL_Http_Batch) {
|
501 |
return $request->execute();
|
502 |
} else {
|
503 |
+
throw new GoogleGAL_Exception("Do not know how to execute this type of object.");
|
504 |
}
|
505 |
}
|
506 |
|
514 |
}
|
515 |
|
516 |
/**
|
517 |
+
* @return GoogleGAL_Auth_Abstract Authentication implementation
|
518 |
*/
|
519 |
public function getAuth()
|
520 |
{
|
526 |
}
|
527 |
|
528 |
/**
|
529 |
+
* @return GoogleGAL_IO_Abstract IO implementation
|
530 |
*/
|
531 |
public function getIo()
|
532 |
{
|
538 |
}
|
539 |
|
540 |
/**
|
541 |
+
* @return GoogleGAL_Cache_Abstract Cache implementation
|
542 |
*/
|
543 |
public function getCache()
|
544 |
{
|
564 |
|
565 |
/**
|
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
|
core/Google/Collection.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
require_once "Google/Model.php";
|
4 |
|
5 |
/**
|
6 |
-
* Extension to the regular
|
7 |
* exposes the items array for iteration, so you can just
|
8 |
* iterate over the object rather than a reference inside.
|
9 |
*/
|
10 |
-
class
|
11 |
{
|
12 |
protected $collection_key = 'items';
|
13 |
|
3 |
require_once "Google/Model.php";
|
4 |
|
5 |
/**
|
6 |
+
* Extension to the regular GoogleGAL_Model that automatically
|
7 |
* exposes the items array for iteration, so you can just
|
8 |
* iterate over the object rather than a reference inside.
|
9 |
*/
|
10 |
+
class GoogleGAL_Collection extends GoogleGAL_Model implements Iterator, Countable
|
11 |
{
|
12 |
protected $collection_key = 'items';
|
13 |
|
core/Google/Config.php
CHANGED
@@ -18,7 +18,7 @@
|
|
18 |
/**
|
19 |
* A class to contain the library configuration for the Google API client.
|
20 |
*/
|
21 |
-
class
|
22 |
{
|
23 |
const GZIP_DISABLED = true;
|
24 |
const GZIP_ENABLED = false;
|
@@ -28,7 +28,7 @@ class Google_Config
|
|
28 |
private $configuration;
|
29 |
|
30 |
/**
|
31 |
-
* Create a new
|
32 |
* local configuration. For example:
|
33 |
* application_name: "My App";
|
34 |
*
|
@@ -41,9 +41,9 @@ class Google_Config
|
|
41 |
'application_name' => '',
|
42 |
|
43 |
// Which Authentication, Storage and HTTP IO classes to use.
|
44 |
-
'auth_class' => '
|
45 |
'io_class' => self::USE_AUTO_IO_SELECTION,
|
46 |
-
'cache_class' => '
|
47 |
|
48 |
// Don't change these unless you're working against a special development
|
49 |
// or testing environment.
|
@@ -51,10 +51,10 @@ class Google_Config
|
|
51 |
|
52 |
// Definition of class specific values, like file paths and so on.
|
53 |
'classes' => array(
|
54 |
-
'
|
55 |
'request_timeout_seconds' => 100,
|
56 |
),
|
57 |
-
'
|
58 |
// Disable the use of gzip on calls if set to true. Defaults to false.
|
59 |
'disable_gzip' => self::GZIP_ENABLED,
|
60 |
|
@@ -66,7 +66,7 @@ class Google_Config
|
|
66 |
),
|
67 |
// If you want to pass in OAuth 2.0 settings, they will need to be
|
68 |
// structured like this.
|
69 |
-
'
|
70 |
// Keys for OAuth 2.0 access, see the API console at
|
71 |
// https://developers.google.com/console
|
72 |
'client_id' => '',
|
@@ -85,8 +85,8 @@ class Google_Config
|
|
85 |
'https://www.googleapis.com/oauth2/v1/certs',
|
86 |
),
|
87 |
// Set a default directory for the file cache.
|
88 |
-
'
|
89 |
-
'directory' => sys_get_temp_dir() . '/
|
90 |
)
|
91 |
),
|
92 |
|
@@ -105,7 +105,7 @@ class Google_Config
|
|
105 |
|
106 |
/**
|
107 |
* Set configuration specific to a given class.
|
108 |
-
* $config->setClassConfig('
|
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
|
18 |
/**
|
19 |
* A class to contain the library configuration for the Google API client.
|
20 |
*/
|
21 |
+
class GoogleGAL_Config
|
22 |
{
|
23 |
const GZIP_DISABLED = true;
|
24 |
const GZIP_ENABLED = false;
|
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 |
*
|
41 |
'application_name' => '',
|
42 |
|
43 |
// Which Authentication, Storage and HTTP IO classes to use.
|
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.
|
51 |
|
52 |
// Definition of class specific values, like file paths and so on.
|
53 |
'classes' => array(
|
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,
|
60 |
|
66 |
),
|
67 |
// If you want to pass in OAuth 2.0 settings, they will need to be
|
68 |
// structured like this.
|
69 |
+
'GoogleGAL_Auth_OAuth2' => array(
|
70 |
// Keys for OAuth 2.0 access, see the API console at
|
71 |
// https://developers.google.com/console
|
72 |
'client_id' => '',
|
85 |
'https://www.googleapis.com/oauth2/v1/certs',
|
86 |
),
|
87 |
// Set a default directory for the file cache.
|
88 |
+
'GoogleGAL_Cache_File' => array(
|
89 |
+
'directory' => sys_get_temp_dir() . '/GoogleGAL_Client'
|
90 |
)
|
91 |
),
|
92 |
|
105 |
|
106 |
/**
|
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
|
core/Google/Exception.php
CHANGED
@@ -15,6 +15,6 @@
|
|
15 |
* limitations under the License.
|
16 |
*/
|
17 |
|
18 |
-
class
|
19 |
{
|
20 |
}
|
15 |
* limitations under the License.
|
16 |
*/
|
17 |
|
18 |
+
class GoogleGAL_Exception extends Exception
|
19 |
{
|
20 |
}
|
core/Google/Http/Batch.php
CHANGED
@@ -22,7 +22,7 @@ require_once 'Google/Http/REST.php';
|
|
22 |
/**
|
23 |
* @author Chirag Shah <chirags@google.com>
|
24 |
*/
|
25 |
-
class
|
26 |
{
|
27 |
/** @var string Multipart Boundary. */
|
28 |
private $boundary;
|
@@ -30,14 +30,14 @@ class Google_Http_Batch
|
|
30 |
/** @var array service requests to be executed. */
|
31 |
private $requests = array();
|
32 |
|
33 |
-
/** @var
|
34 |
private $client;
|
35 |
|
36 |
private $expected_classes = array();
|
37 |
|
38 |
private $base_path;
|
39 |
|
40 |
-
public function __construct(
|
41 |
{
|
42 |
$this->client = $client;
|
43 |
$this->base_path = $this->client->getBasePath();
|
@@ -46,7 +46,7 @@ class Google_Http_Batch
|
|
46 |
$this->boundary = str_replace('"', '', $boundary);
|
47 |
}
|
48 |
|
49 |
-
public function add(
|
50 |
{
|
51 |
if (false == $key) {
|
52 |
$key = mt_rand();
|
@@ -59,7 +59,7 @@ class Google_Http_Batch
|
|
59 |
{
|
60 |
$body = '';
|
61 |
|
62 |
-
/** @var
|
63 |
foreach ($this->requests as $key => $req) {
|
64 |
$body .= "--{$this->boundary}\n";
|
65 |
$body .= $req->toBatchString($key) . "\n";
|
@@ -70,7 +70,7 @@ class Google_Http_Batch
|
|
70 |
$body .= "\n--{$this->boundary}--";
|
71 |
|
72 |
$url = $this->base_path . '/batch';
|
73 |
-
$httpRequest = new
|
74 |
$httpRequest->setRequestHeaders(
|
75 |
array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
|
76 |
);
|
@@ -81,7 +81,7 @@ class Google_Http_Batch
|
|
81 |
return $this->parseResponse($response);
|
82 |
}
|
83 |
|
84 |
-
public function parseResponse(
|
85 |
{
|
86 |
$contentType = $response->getResponseHeader('content-type');
|
87 |
$contentType = explode(';', $contentType);
|
@@ -110,7 +110,7 @@ class Google_Http_Batch
|
|
110 |
$status = $status[1];
|
111 |
|
112 |
list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
|
113 |
-
$response = new
|
114 |
$response->setResponseHttpCode($status);
|
115 |
$response->setResponseHeaders($partHeaders);
|
116 |
$response->setResponseBody($partBody);
|
@@ -125,9 +125,9 @@ class Google_Http_Batch
|
|
125 |
}
|
126 |
|
127 |
try {
|
128 |
-
$response =
|
129 |
$responses[$key] = $response;
|
130 |
-
} catch (
|
131 |
// Store the exception as the response, so succesful responses
|
132 |
// can be processed.
|
133 |
$responses[$key] = $e;
|
22 |
/**
|
23 |
* @author Chirag Shah <chirags@google.com>
|
24 |
*/
|
25 |
+
class GoogleGAL_Http_Batch
|
26 |
{
|
27 |
/** @var string Multipart Boundary. */
|
28 |
private $boundary;
|
30 |
/** @var array service requests to be executed. */
|
31 |
private $requests = array();
|
32 |
|
33 |
+
/** @var GoogleGAL_Client */
|
34 |
private $client;
|
35 |
|
36 |
private $expected_classes = array();
|
37 |
|
38 |
private $base_path;
|
39 |
|
40 |
+
public function __construct(GoogleGAL_Client $client, $boundary = false)
|
41 |
{
|
42 |
$this->client = $client;
|
43 |
$this->base_path = $this->client->getBasePath();
|
46 |
$this->boundary = str_replace('"', '', $boundary);
|
47 |
}
|
48 |
|
49 |
+
public function add(GoogleGAL_Http_Request $request, $key = false)
|
50 |
{
|
51 |
if (false == $key) {
|
52 |
$key = mt_rand();
|
59 |
{
|
60 |
$body = '';
|
61 |
|
62 |
+
/** @var GoogleGAL_Http_Request $req */
|
63 |
foreach ($this->requests as $key => $req) {
|
64 |
$body .= "--{$this->boundary}\n";
|
65 |
$body .= $req->toBatchString($key) . "\n";
|
70 |
$body .= "\n--{$this->boundary}--";
|
71 |
|
72 |
$url = $this->base_path . '/batch';
|
73 |
+
$httpRequest = new GoogleGAL_Http_Request($url, 'POST');
|
74 |
$httpRequest->setRequestHeaders(
|
75 |
array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
|
76 |
);
|
81 |
return $this->parseResponse($response);
|
82 |
}
|
83 |
|
84 |
+
public function parseResponse(GoogleGAL_Http_Request $response)
|
85 |
{
|
86 |
$contentType = $response->getResponseHeader('content-type');
|
87 |
$contentType = explode(';', $contentType);
|
110 |
$status = $status[1];
|
111 |
|
112 |
list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
|
113 |
+
$response = new GoogleGAL_Http_Request("");
|
114 |
$response->setResponseHttpCode($status);
|
115 |
$response->setResponseHeaders($partHeaders);
|
116 |
$response->setResponseBody($partBody);
|
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;
|
core/Google/Http/CacheParser.php
CHANGED
@@ -22,7 +22,7 @@ require_once 'Google/Http/Request.php';
|
|
22 |
* implementation is guided by the guidance offered in rfc2616-sec13.
|
23 |
* @author Chirag Shah <chirags@google.com>
|
24 |
*/
|
25 |
-
class
|
26 |
{
|
27 |
public static $CACHEABLE_HTTP_METHODS = array('GET', 'HEAD');
|
28 |
public static $CACHEABLE_STATUS_CODES = array('200', '203', '300', '301');
|
@@ -31,11 +31,11 @@ class Google_Http_CacheParser
|
|
31 |
* Check if an HTTP request can be cached by a private local cache.
|
32 |
*
|
33 |
* @static
|
34 |
-
* @param
|
35 |
* @return bool True if the request is cacheable.
|
36 |
* False if the request is uncacheable.
|
37 |
*/
|
38 |
-
public static function isRequestCacheable(
|
39 |
{
|
40 |
$method = $resp->getRequestMethod();
|
41 |
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
|
@@ -57,11 +57,11 @@ class Google_Http_CacheParser
|
|
57 |
* Check if an HTTP response can be cached by a private local cache.
|
58 |
*
|
59 |
* @static
|
60 |
-
* @param
|
61 |
* @return bool True if the response is cacheable.
|
62 |
* False if the response is un-cacheable.
|
63 |
*/
|
64 |
-
public static function isResponseCacheable(
|
65 |
{
|
66 |
// First, check if the HTTP request was cacheable before inspecting the
|
67 |
// HTTP response.
|
@@ -109,11 +109,11 @@ class Google_Http_CacheParser
|
|
109 |
|
110 |
/**
|
111 |
* @static
|
112 |
-
* @param
|
113 |
* @return bool True if the HTTP response is considered to be expired.
|
114 |
* False if it is considered to be fresh.
|
115 |
*/
|
116 |
-
public static function isExpired(
|
117 |
{
|
118 |
// HTTP/1.1 clients and caches MUST treat other invalid date formats,
|
119 |
// especially including the value “0”, as in the past.
|
@@ -148,7 +148,7 @@ class Google_Http_CacheParser
|
|
148 |
// We can't default this to now, as that means future cache reads
|
149 |
// will always pass with the logic below, so we will require a
|
150 |
// date be injected if not supplied.
|
151 |
-
throw new
|
152 |
}
|
153 |
|
154 |
if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
|
@@ -171,10 +171,10 @@ class Google_Http_CacheParser
|
|
171 |
/**
|
172 |
* Determine if a cache entry should be revalidated with by the origin.
|
173 |
*
|
174 |
-
* @param
|
175 |
* @return bool True if the entry is expired, else return false.
|
176 |
*/
|
177 |
-
public static function mustRevalidate(
|
178 |
{
|
179 |
// [13.3] When a cache has a stale entry that it would like to use as a
|
180 |
// response to a client's request, it first has to check with the origin
|
22 |
* implementation is guided by the guidance offered in rfc2616-sec13.
|
23 |
* @author Chirag Shah <chirags@google.com>
|
24 |
*/
|
25 |
+
class GoogleGAL_Http_CacheParser
|
26 |
{
|
27 |
public static $CACHEABLE_HTTP_METHODS = array('GET', 'HEAD');
|
28 |
public static $CACHEABLE_STATUS_CODES = array('200', '203', '300', '301');
|
31 |
* Check if an HTTP request can be cached by a private local cache.
|
32 |
*
|
33 |
* @static
|
34 |
+
* @param GoogleGAL_Http_Request $resp
|
35 |
* @return bool True if the request is cacheable.
|
36 |
* False if the request is uncacheable.
|
37 |
*/
|
38 |
+
public static function isRequestCacheable(GoogleGAL_Http_Request $resp)
|
39 |
{
|
40 |
$method = $resp->getRequestMethod();
|
41 |
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
|
57 |
* Check if an HTTP response can be cached by a private local cache.
|
58 |
*
|
59 |
* @static
|
60 |
+
* @param GoogleGAL_Http_Request $resp
|
61 |
* @return bool True if the response is cacheable.
|
62 |
* False if the response is un-cacheable.
|
63 |
*/
|
64 |
+
public static function isResponseCacheable(GoogleGAL_Http_Request $resp)
|
65 |
{
|
66 |
// First, check if the HTTP request was cacheable before inspecting the
|
67 |
// HTTP response.
|
109 |
|
110 |
/**
|
111 |
* @static
|
112 |
+
* @param GoogleGAL_Http_Request $resp
|
113 |
* @return bool True if the HTTP response is considered to be expired.
|
114 |
* False if it is considered to be fresh.
|
115 |
*/
|
116 |
+
public static function isExpired(GoogleGAL_Http_Request $resp)
|
117 |
{
|
118 |
// HTTP/1.1 clients and caches MUST treat other invalid date formats,
|
119 |
// especially including the value “0”, as in the past.
|
148 |
// We can't default this to now, as that means future cache reads
|
149 |
// will always pass with the logic below, so we will require a
|
150 |
// date be injected if not supplied.
|
151 |
+
throw new GoogleGAL_Exception("All cacheable requests must have creation dates.");
|
152 |
}
|
153 |
|
154 |
if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
|
171 |
/**
|
172 |
* Determine if a cache entry should be revalidated with by the origin.
|
173 |
*
|
174 |
+
* @param GoogleGAL_Http_Request $response
|
175 |
* @return bool True if the entry is expired, else return false.
|
176 |
*/
|
177 |
+
public static function mustRevalidate(GoogleGAL_Http_Request $response)
|
178 |
{
|
179 |
// [13.3] When a cache has a stale entry that it would like to use as a
|
180 |
// response to a client's request, it first has to check with the origin
|
core/Google/Http/MediaFileUpload.php
CHANGED
@@ -25,7 +25,7 @@ require_once 'Google/Utils.php';
|
|
25 |
* @author Chirag Shah <chirags@google.com>
|
26 |
*
|
27 |
*/
|
28 |
-
class
|
29 |
{
|
30 |
const UPLOAD_MEDIA_TYPE = 'media';
|
31 |
const UPLOAD_MULTIPART_TYPE = 'multipart';
|
@@ -52,10 +52,10 @@ class Google_Http_MediaFileUpload
|
|
52 |
/** @var int $progress */
|
53 |
private $progress;
|
54 |
|
55 |
-
/** @var
|
56 |
private $client;
|
57 |
|
58 |
-
/** @var
|
59 |
private $request;
|
60 |
|
61 |
/** @var string */
|
@@ -75,8 +75,8 @@ class Google_Http_MediaFileUpload
|
|
75 |
* only used if resumable=True
|
76 |
*/
|
77 |
public function __construct(
|
78 |
-
|
79 |
-
|
80 |
$mimeType,
|
81 |
$data,
|
82 |
$resumable = false,
|
@@ -150,14 +150,14 @@ class Google_Http_MediaFileUpload
|
|
150 |
'expect' => '',
|
151 |
);
|
152 |
|
153 |
-
$httpRequest = new
|
154 |
$this->resumeUri,
|
155 |
'PUT',
|
156 |
$headers,
|
157 |
$chunk
|
158 |
);
|
159 |
|
160 |
-
if ($this->client->getClassConfig("
|
161 |
$httpRequest->enableGzip();
|
162 |
} else {
|
163 |
$httpRequest->disableGzip();
|
@@ -182,7 +182,7 @@ class Google_Http_MediaFileUpload
|
|
182 |
// No problems, but upload not complete.
|
183 |
return false;
|
184 |
} else {
|
185 |
-
return
|
186 |
}
|
187 |
}
|
188 |
|
@@ -272,7 +272,7 @@ class Google_Http_MediaFileUpload
|
|
272 |
if ($body) {
|
273 |
$headers = array(
|
274 |
'content-type' => 'application/json; charset=UTF-8',
|
275 |
-
'content-length' =>
|
276 |
'x-upload-content-type' => $this->mimeType,
|
277 |
'x-upload-content-length' => $this->size,
|
278 |
'expect' => '',
|
@@ -287,6 +287,6 @@ class Google_Http_MediaFileUpload
|
|
287 |
if (200 == $code && true == $location) {
|
288 |
return $location;
|
289 |
}
|
290 |
-
throw new
|
291 |
}
|
292 |
}
|
25 |
* @author Chirag Shah <chirags@google.com>
|
26 |
*
|
27 |
*/
|
28 |
+
class GoogleGAL_Http_MediaFileUpload
|
29 |
{
|
30 |
const UPLOAD_MEDIA_TYPE = 'media';
|
31 |
const UPLOAD_MULTIPART_TYPE = 'multipart';
|
52 |
/** @var int $progress */
|
53 |
private $progress;
|
54 |
|
55 |
+
/** @var GoogleGAL_Client */
|
56 |
private $client;
|
57 |
|
58 |
+
/** @var GoogleGAL_Http_Request */
|
59 |
private $request;
|
60 |
|
61 |
/** @var string */
|
75 |
* only used if resumable=True
|
76 |
*/
|
77 |
public function __construct(
|
78 |
+
GoogleGAL_Client $client,
|
79 |
+
GoogleGAL_Http_Request $request,
|
80 |
$mimeType,
|
81 |
$data,
|
82 |
$resumable = false,
|
150 |
'expect' => '',
|
151 |
);
|
152 |
|
153 |
+
$httpRequest = new GoogleGAL_Http_Request(
|
154 |
$this->resumeUri,
|
155 |
'PUT',
|
156 |
$headers,
|
157 |
$chunk
|
158 |
);
|
159 |
|
160 |
+
if ($this->client->getClassConfig("GoogleGAL_Http_Request", "enable_gzip_for_uploads")) {
|
161 |
$httpRequest->enableGzip();
|
162 |
} else {
|
163 |
$httpRequest->disableGzip();
|
182 |
// No problems, but upload not complete.
|
183 |
return false;
|
184 |
} else {
|
185 |
+
return GoogleGAL_Http_REST::decodeHttpResponse($response);
|
186 |
}
|
187 |
}
|
188 |
|
272 |
if ($body) {
|
273 |
$headers = array(
|
274 |
'content-type' => 'application/json; charset=UTF-8',
|
275 |
+
'content-length' => GoogleGAL_Utils::getStrLen($body),
|
276 |
'x-upload-content-type' => $this->mimeType,
|
277 |
'x-upload-content-length' => $this->size,
|
278 |
'expect' => '',
|
287 |
if (200 == $code && true == $location) {
|
288 |
return $location;
|
289 |
}
|
290 |
+
throw new GoogleGAL_Exception("Failed to start the resumable upload");
|
291 |
}
|
292 |
}
|
core/Google/Http/REST.php
CHANGED
@@ -26,18 +26,18 @@ require_once 'Google/Utils/URITemplate.php';
|
|
26 |
* @author Chris Chabot <chabotc@google.com>
|
27 |
* @author Chirag Shah <chirags@google.com>
|
28 |
*/
|
29 |
-
class
|
30 |
{
|
31 |
/**
|
32 |
-
* Executes a
|
33 |
*
|
34 |
-
* @param
|
35 |
-
* @param
|
36 |
* @return array decoded result
|
37 |
-
* @throws
|
38 |
* invalid or malformed post body, invalid url)
|
39 |
*/
|
40 |
-
public static function execute(
|
41 |
{
|
42 |
$httpRequest = $client->getIo()->makeRequest($req);
|
43 |
$httpRequest->setExpectedClass($req->getExpectedClass());
|
@@ -47,8 +47,8 @@ class Google_Http_REST
|
|
47 |
/**
|
48 |
* Decode an HTTP Response.
|
49 |
* @static
|
50 |
-
* @throws
|
51 |
-
* @param
|
52 |
* @return mixed|null
|
53 |
*/
|
54 |
public static function decodeHttpResponse($response)
|
@@ -76,14 +76,14 @@ class Google_Http_REST
|
|
76 |
$errors = $decoded['error']['errors'];
|
77 |
}
|
78 |
|
79 |
-
throw new
|
80 |
}
|
81 |
|
82 |
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
|
83 |
if ($code != '204') {
|
84 |
$decoded = json_decode($body, true);
|
85 |
if ($decoded === null || $decoded === "") {
|
86 |
-
throw new
|
87 |
}
|
88 |
|
89 |
if ($response->getExpectedClass()) {
|
@@ -126,7 +126,7 @@ class Google_Http_REST
|
|
126 |
}
|
127 |
|
128 |
if (count($uriTemplateVars)) {
|
129 |
-
$uriTemplateParser = new
|
130 |
$requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars);
|
131 |
}
|
132 |
|
26 |
* @author Chris Chabot <chabotc@google.com>
|
27 |
* @author Chirag Shah <chirags@google.com>
|
28 |
*/
|
29 |
+
class GoogleGAL_Http_REST
|
30 |
{
|
31 |
/**
|
32 |
+
* Executes a GoogleGAL_Http_Request
|
33 |
*
|
34 |
+
* @param GoogleGAL_Client $client
|
35 |
+
* @param GoogleGAL_Http_Request $req
|
36 |
* @return array decoded result
|
37 |
+
* @throws GoogleGAL_Service_Exception on server side error (ie: not authenticated,
|
38 |
* invalid or malformed post body, invalid url)
|
39 |
*/
|
40 |
+
public static function execute(GoogleGAL_Client $client, GoogleGAL_Http_Request $req)
|
41 |
{
|
42 |
$httpRequest = $client->getIo()->makeRequest($req);
|
43 |
$httpRequest->setExpectedClass($req->getExpectedClass());
|
47 |
/**
|
48 |
* Decode an HTTP Response.
|
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)
|
76 |
$errors = $decoded['error']['errors'];
|
77 |
}
|
78 |
|
79 |
+
throw new GoogleGAL_Service_Exception($err, $code, null, $errors);
|
80 |
}
|
81 |
|
82 |
// Only attempt to decode the response, if the response code wasn't (204) 'no content'
|
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()) {
|
126 |
}
|
127 |
|
128 |
if (count($uriTemplateVars)) {
|
129 |
+
$uriTemplateParser = new GoogleGAL_Utils_URITemplate();
|
130 |
$requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars);
|
131 |
}
|
132 |
|
core/Google/Http/Request.php
CHANGED
@@ -25,7 +25,7 @@ require_once 'Google/Utils.php';
|
|
25 |
* @author Chirag Shah <chirags@google.com>
|
26 |
*
|
27 |
*/
|
28 |
-
class
|
29 |
{
|
30 |
const GZIP_UA = " (gzip)";
|
31 |
|
@@ -194,7 +194,7 @@ class Google_Http_Request
|
|
194 |
*/
|
195 |
public function setResponseHeaders($headers)
|
196 |
{
|
197 |
-
$headers =
|
198 |
if ($this->responseHeaders) {
|
199 |
$headers = array_merge($this->responseHeaders, $headers);
|
200 |
}
|
@@ -312,7 +312,7 @@ class Google_Http_Request
|
|
312 |
*/
|
313 |
public function setRequestHeaders($headers)
|
314 |
{
|
315 |
-
$headers =
|
316 |
if ($this->requestHeaders) {
|
317 |
$headers = array_merge($this->requestHeaders, $headers);
|
318 |
}
|
25 |
* @author Chirag Shah <chirags@google.com>
|
26 |
*
|
27 |
*/
|
28 |
+
class GoogleGAL_Http_Request
|
29 |
{
|
30 |
const GZIP_UA = " (gzip)";
|
31 |
|
194 |
*/
|
195 |
public function setResponseHeaders($headers)
|
196 |
{
|
197 |
+
$headers = GoogleGAL_Utils::normalize($headers);
|
198 |
if ($this->responseHeaders) {
|
199 |
$headers = array_merge($this->responseHeaders, $headers);
|
200 |
}
|
312 |
*/
|
313 |
public function setRequestHeaders($headers)
|
314 |
{
|
315 |
+
$headers = GoogleGAL_Utils::normalize($headers);
|
316 |
if ($this->requestHeaders) {
|
317 |
$headers = array_merge($this->requestHeaders, $headers);
|
318 |
}
|
core/Google/IO/Abstract.php
CHANGED
@@ -24,31 +24,31 @@ require_once 'Google/IO/Exception.php';
|
|
24 |
require_once 'Google/Http/CacheParser.php';
|
25 |
require_once 'Google/Http/Request.php';
|
26 |
|
27 |
-
abstract class
|
28 |
{
|
29 |
const UNKNOWN_CODE = 0;
|
30 |
const FORM_URLENCODED = 'application/x-www-form-urlencoded';
|
31 |
const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n";
|
32 |
private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null);
|
33 |
|
34 |
-
/** @var
|
35 |
protected $client;
|
36 |
|
37 |
-
public function __construct(
|
38 |
{
|
39 |
$this->client = $client;
|
40 |
-
$timeout = $client->getClassConfig('
|
41 |
if ($timeout > 0) {
|
42 |
$this->setTimeout($timeout);
|
43 |
}
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
-
* Executes a
|
48 |
-
* @param
|
49 |
-
* @return
|
50 |
*/
|
51 |
-
abstract public function executeRequest(
|
52 |
|
53 |
/**
|
54 |
* Set options that update the transport implementation's behavior.
|
@@ -77,14 +77,14 @@ abstract class Google_IO_Abstract
|
|
77 |
/**
|
78 |
* @visible for testing.
|
79 |
* Cache the response to an HTTP request if it is cacheable.
|
80 |
-
* @param
|
81 |
* @return bool Returns true if the insertion was successful.
|
82 |
* Otherwise, return false.
|
83 |
*/
|
84 |
-
public function setCachedRequest(
|
85 |
{
|
86 |
// Determine if the request is cacheable.
|
87 |
-
if (
|
88 |
$this->client->getCache()->set($request->getCacheKey(), $request);
|
89 |
return true;
|
90 |
}
|
@@ -95,16 +95,16 @@ abstract class Google_IO_Abstract
|
|
95 |
/**
|
96 |
* Execute an HTTP Request
|
97 |
*
|
98 |
-
* @param
|
99 |
-
* @return
|
100 |
* response headers and response body filled in
|
101 |
-
* @throws
|
102 |
*/
|
103 |
-
public function makeRequest(
|
104 |
{
|
105 |
// First, check to see if we have a valid cached version.
|
106 |
$cached = $this->getCachedRequest($request);
|
107 |
-
if ($cached !== false && $cached instanceof
|
108 |
if (!$this->checkMustRevalidateCachedRequest($cached, $request)) {
|
109 |
return $cached;
|
110 |
}
|
@@ -137,13 +137,13 @@ abstract class Google_IO_Abstract
|
|
137 |
|
138 |
/**
|
139 |
* @visible for testing.
|
140 |
-
* @param
|
141 |
-
* @return
|
142 |
* false if the operation was unsuccessful.
|
143 |
*/
|
144 |
-
public function getCachedRequest(
|
145 |
{
|
146 |
-
if (false ===
|
147 |
return false;
|
148 |
}
|
149 |
|
@@ -153,10 +153,10 @@ abstract class Google_IO_Abstract
|
|
153 |
/**
|
154 |
* @visible for testing
|
155 |
* Process an http request that contains an enclosed entity.
|
156 |
-
* @param
|
157 |
-
* @return
|
158 |
*/
|
159 |
-
public function processEntityRequest(
|
160 |
{
|
161 |
$postBody = $request->getPostBody();
|
162 |
$contentType = $request->getRequestHeader("content-type");
|
@@ -185,14 +185,14 @@ abstract class Google_IO_Abstract
|
|
185 |
/**
|
186 |
* Check if an already cached request must be revalidated, and if so update
|
187 |
* the request with the correct ETag headers.
|
188 |
-
* @param
|
189 |
-
* @param
|
190 |
* return bool If the cached object needs to be revalidated, false if it is
|
191 |
* still current and can be re-used.
|
192 |
*/
|
193 |
protected function checkMustRevalidateCachedRequest($cached, $request)
|
194 |
{
|
195 |
-
if (
|
196 |
$addHeaders = array();
|
197 |
if ($cached->getResponseHeader('etag')) {
|
198 |
// [13.3.4] If an entity tag has been provided by the origin server,
|
@@ -211,7 +211,7 @@ abstract class Google_IO_Abstract
|
|
211 |
|
212 |
/**
|
213 |
* Update a cached request, using the headers from the last response.
|
214 |
-
* @param
|
215 |
* @param mixed Associative array of response headers from the last request.
|
216 |
*/
|
217 |
protected function updateCachedRequest($cached, $responseHeaders)
|
24 |
require_once 'Google/Http/CacheParser.php';
|
25 |
require_once 'Google/Http/Request.php';
|
26 |
|
27 |
+
abstract class GoogleGAL_IO_Abstract
|
28 |
{
|
29 |
const UNKNOWN_CODE = 0;
|
30 |
const FORM_URLENCODED = 'application/x-www-form-urlencoded';
|
31 |
const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n";
|
32 |
private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null);
|
33 |
|
34 |
+
/** @var GoogleGAL_Client */
|
35 |
protected $client;
|
36 |
|
37 |
+
public function __construct(GoogleGAL_Client $client)
|
38 |
{
|
39 |
$this->client = $client;
|
40 |
+
$timeout = $client->getClassConfig('GoogleGAL_IO_Abstract', 'request_timeout_seconds');
|
41 |
if ($timeout > 0) {
|
42 |
$this->setTimeout($timeout);
|
43 |
}
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Executes a GoogleGAL_Http_Request and returns the resulting populated GoogleGAL_Http_Request
|
48 |
+
* @param GoogleGAL_Http_Request $request
|
49 |
+
* @return GoogleGAL_Http_Request $request
|
50 |
*/
|
51 |
+
abstract public function executeRequest(GoogleGAL_Http_Request $request);
|
52 |
|
53 |
/**
|
54 |
* Set options that update the transport implementation's behavior.
|
77 |
/**
|
78 |
* @visible for testing.
|
79 |
* Cache the response to an HTTP request if it is cacheable.
|
80 |
+
* @param GoogleGAL_Http_Request $request
|
81 |
* @return bool Returns true if the insertion was successful.
|
82 |
* Otherwise, return false.
|
83 |
*/
|
84 |
+
public function setCachedRequest(GoogleGAL_Http_Request $request)
|
85 |
{
|
86 |
// Determine if the request is cacheable.
|
87 |
+
if (GoogleGAL_Http_CacheParser::isResponseCacheable($request)) {
|
88 |
$this->client->getCache()->set($request->getCacheKey(), $request);
|
89 |
return true;
|
90 |
}
|
95 |
/**
|
96 |
* Execute an HTTP Request
|
97 |
*
|
98 |
+
* @param GoogleGAL_HttpRequest $request the http request to be executed
|
99 |
+
* @return GoogleGAL_HttpRequest http request with the response http code,
|
100 |
* response headers and response body filled in
|
101 |
+
* @throws GoogleGAL_IO_Exception on curl or IO error
|
102 |
*/
|
103 |
+
public function makeRequest(GoogleGAL_Http_Request $request)
|
104 |
{
|
105 |
// First, check to see if we have a valid cached version.
|
106 |
$cached = $this->getCachedRequest($request);
|
107 |
+
if ($cached !== false && $cached instanceof GoogleGAL_Http_Request) {
|
108 |
if (!$this->checkMustRevalidateCachedRequest($cached, $request)) {
|
109 |
return $cached;
|
110 |
}
|
137 |
|
138 |
/**
|
139 |
* @visible for testing.
|
140 |
+
* @param GoogleGAL_Http_Request $request
|
141 |
+
* @return GoogleGAL_Http_Request|bool Returns the cached object or
|
142 |
* false if the operation was unsuccessful.
|
143 |
*/
|
144 |
+
public function getCachedRequest(GoogleGAL_Http_Request $request)
|
145 |
{
|
146 |
+
if (false === GoogleGAL_Http_CacheParser::isRequestCacheable($request)) {
|
147 |
return false;
|
148 |
}
|
149 |
|
153 |
/**
|
154 |
* @visible for testing
|
155 |
* Process an http request that contains an enclosed entity.
|
156 |
+
* @param GoogleGAL_Http_Request $request
|
157 |
+
* @return GoogleGAL_Http_Request Processed request with the enclosed entity.
|
158 |
*/
|
159 |
+
public function processEntityRequest(GoogleGAL_Http_Request $request)
|
160 |
{
|
161 |
$postBody = $request->getPostBody();
|
162 |
$contentType = $request->getRequestHeader("content-type");
|
185 |
/**
|
186 |
* Check if an already cached request must be revalidated, and if so update
|
187 |
* the request with the correct ETag headers.
|
188 |
+
* @param GoogleGAL_Http_Request $cached A previously cached response.
|
189 |
+
* @param GoogleGAL_Http_Request $request The outbound request.
|
190 |
* return bool If the cached object needs to be revalidated, false if it is
|
191 |
* still current and can be re-used.
|
192 |
*/
|
193 |
protected function checkMustRevalidateCachedRequest($cached, $request)
|
194 |
{
|
195 |
+
if (GoogleGAL_Http_CacheParser::mustRevalidate($cached)) {
|
196 |
$addHeaders = array();
|
197 |
if ($cached->getResponseHeader('etag')) {
|
198 |
// [13.3.4] If an entity tag has been provided by the origin server,
|
211 |
|
212 |
/**
|
213 |
* Update a cached request, using the headers from the last response.
|
214 |
+
* @param GoogleGAL_HttpRequest $cached A previously cached response.
|
215 |
* @param mixed Associative array of response headers from the last request.
|
216 |
*/
|
217 |
protected function updateCachedRequest($cached, $responseHeaders)
|
core/Google/IO/Curl.php
CHANGED
@@ -16,14 +16,14 @@
|
|
16 |
*/
|
17 |
|
18 |
/**
|
19 |
-
* Curl based implementation of
|
20 |
*
|
21 |
* @author Stuart Langley <slangley@google.com>
|
22 |
*/
|
23 |
|
24 |
require_once 'Google/IO/Abstract.php';
|
25 |
|
26 |
-
class
|
27 |
{
|
28 |
// hex for version 7.31.0
|
29 |
const NO_QUIRK_VERSION = 0x071F00;
|
@@ -32,12 +32,12 @@ class Google_IO_Curl extends Google_IO_Abstract
|
|
32 |
/**
|
33 |
* Execute an HTTP Request
|
34 |
*
|
35 |
-
* @param
|
36 |
-
* @return
|
37 |
* response headers and response body filled in
|
38 |
-
* @throws
|
39 |
*/
|
40 |
-
public function executeRequest(
|
41 |
{
|
42 |
$curl = curl_init();
|
43 |
|
@@ -78,7 +78,7 @@ class Google_IO_Curl extends Google_IO_Abstract
|
|
78 |
|
79 |
$response = curl_exec($curl);
|
80 |
if ($response === false) {
|
81 |
-
throw new
|
82 |
}
|
83 |
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
84 |
|
@@ -130,6 +130,6 @@ class Google_IO_Curl extends Google_IO_Abstract
|
|
130 |
{
|
131 |
$ver = curl_version();
|
132 |
$versionNum = $ver['version_number'];
|
133 |
-
return $versionNum <
|
134 |
}
|
135 |
}
|
16 |
*/
|
17 |
|
18 |
/**
|
19 |
+
* Curl based implementation of GoogleGAL_IO.
|
20 |
*
|
21 |
* @author Stuart Langley <slangley@google.com>
|
22 |
*/
|
23 |
|
24 |
require_once 'Google/IO/Abstract.php';
|
25 |
|
26 |
+
class GoogleGAL_IO_Curl extends GoogleGAL_IO_Abstract
|
27 |
{
|
28 |
// hex for version 7.31.0
|
29 |
const NO_QUIRK_VERSION = 0x071F00;
|
32 |
/**
|
33 |
* Execute an HTTP Request
|
34 |
*
|
35 |
+
* @param GoogleGAL_HttpRequest $request the http request to be executed
|
36 |
+
* @return GoogleGAL_HttpRequest http request with the response http code,
|
37 |
* response headers and response body filled in
|
38 |
+
* @throws GoogleGAL_IO_Exception on curl or IO error
|
39 |
*/
|
40 |
+
public function executeRequest(GoogleGAL_Http_Request $request)
|
41 |
{
|
42 |
$curl = curl_init();
|
43 |
|
78 |
|
79 |
$response = curl_exec($curl);
|
80 |
if ($response === false) {
|
81 |
+
throw new GoogleGAL_IO_Exception(curl_error($curl));
|
82 |
}
|
83 |
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
84 |
|
130 |
{
|
131 |
$ver = curl_version();
|
132 |
$versionNum = $ver['version_number'];
|
133 |
+
return $versionNum < GoogleGAL_IO_Curl::NO_QUIRK_VERSION;
|
134 |
}
|
135 |
}
|
core/Google/IO/Exception.php
CHANGED
@@ -17,6 +17,6 @@
|
|
17 |
|
18 |
require_once 'Google/Exception.php';
|
19 |
|
20 |
-
class
|
21 |
{
|
22 |
}
|
17 |
|
18 |
require_once 'Google/Exception.php';
|
19 |
|
20 |
+
class GoogleGAL_IO_Exception extends GoogleGAL_Exception
|
21 |
{
|
22 |
}
|
core/Google/IO/Stream.php
CHANGED
@@ -16,14 +16,14 @@
|
|
16 |
*/
|
17 |
|
18 |
/**
|
19 |
-
* Http Streams based implementation of
|
20 |
*
|
21 |
* @author Stuart Langley <slangley@google.com>
|
22 |
*/
|
23 |
|
24 |
require_once 'Google/IO/Abstract.php';
|
25 |
|
26 |
-
class
|
27 |
{
|
28 |
const TIMEOUT = "timeout";
|
29 |
const ZLIB = "compress.zlib://";
|
@@ -41,12 +41,12 @@ class Google_IO_Stream extends Google_IO_Abstract
|
|
41 |
/**
|
42 |
* Execute an HTTP Request
|
43 |
*
|
44 |
-
* @param
|
45 |
-
* @return
|
46 |
* response headers and response body filled in
|
47 |
-
* @throws
|
48 |
*/
|
49 |
-
public function executeRequest(
|
50 |
{
|
51 |
$default_options = stream_context_get_options(stream_context_get_default());
|
52 |
|
@@ -115,7 +115,7 @@ class Google_IO_Stream extends Google_IO_Abstract
|
|
115 |
}
|
116 |
|
117 |
if (false === $response_data) {
|
118 |
-
throw new
|
119 |
sprintf(
|
120 |
"HTTP Error: Unable to connect: '%s'",
|
121 |
$respHttpCode
|
16 |
*/
|
17 |
|
18 |
/**
|
19 |
+
* Http Streams based implementation of GoogleGAL_IO.
|
20 |
*
|
21 |
* @author Stuart Langley <slangley@google.com>
|
22 |
*/
|
23 |
|
24 |
require_once 'Google/IO/Abstract.php';
|
25 |
|
26 |
+
class GoogleGAL_IO_Stream extends GoogleGAL_IO_Abstract
|
27 |
{
|
28 |
const TIMEOUT = "timeout";
|
29 |
const ZLIB = "compress.zlib://";
|
41 |
/**
|
42 |
* Execute an HTTP Request
|
43 |
*
|
44 |
+
* @param GoogleGAL_HttpRequest $request the http request to be executed
|
45 |
+
* @return GoogleGAL_HttpRequest http request with the response http code,
|
46 |
* response headers and response body filled in
|
47 |
+
* @throws GoogleGAL_IO_Exception on curl or IO error
|
48 |
*/
|
49 |
+
public function executeRequest(GoogleGAL_Http_Request $request)
|
50 |
{
|
51 |
$default_options = stream_context_get_options(stream_context_get_default());
|
52 |
|
115 |
}
|
116 |
|
117 |
if (false === $response_data) {
|
118 |
+
throw new GoogleGAL_IO_Exception(
|
119 |
sprintf(
|
120 |
"HTTP Error: Unable to connect: '%s'",
|
121 |
$respHttpCode
|
core/Google/Model.php
CHANGED
@@ -23,7 +23,7 @@
|
|
23 |
* @author Chirag Shah <chirags@google.com>
|
24 |
*
|
25 |
*/
|
26 |
-
class
|
27 |
{
|
28 |
protected $modelData = array();
|
29 |
protected $processed = array();
|
@@ -89,7 +89,7 @@ class Google_Model implements ArrayAccess
|
|
89 |
property_exists($this, $key)) {
|
90 |
$this->$key = $val;
|
91 |
unset($array[$key]);
|
92 |
-
} elseif (property_exists($this, $camelKey =
|
93 |
// This checks if property exists as camelCase, leaving it in array as snake_case
|
94 |
// in case of backwards compatibility issues.
|
95 |
$this->$camelKey = $val;
|
@@ -136,7 +136,7 @@ class Google_Model implements ArrayAccess
|
|
136 |
*/
|
137 |
private function getSimpleValue($value)
|
138 |
{
|
139 |
-
if ($value instanceof
|
140 |
return $value->toSimpleObject();
|
141 |
} else if (is_array($value)) {
|
142 |
$return = array();
|
@@ -185,14 +185,14 @@ class Google_Model implements ArrayAccess
|
|
185 |
|
186 |
/**
|
187 |
* Verify if $obj is an array.
|
188 |
-
* @throws
|
189 |
* @param array $obj Items that should be validated.
|
190 |
* @param string $method Method expecting an array as an argument.
|
191 |
*/
|
192 |
public function assertIsArray($obj, $method)
|
193 |
{
|
194 |
if ($obj && !is_array($obj)) {
|
195 |
-
throw new
|
196 |
"Incorrect parameter type passed to $method(). Expected an array."
|
197 |
);
|
198 |
}
|
23 |
* @author Chirag Shah <chirags@google.com>
|
24 |
*
|
25 |
*/
|
26 |
+
class GoogleGAL_Model implements ArrayAccess
|
27 |
{
|
28 |
protected $modelData = array();
|
29 |
protected $processed = array();
|
89 |
property_exists($this, $key)) {
|
90 |
$this->$key = $val;
|
91 |
unset($array[$key]);
|
92 |
+
} elseif (property_exists($this, $camelKey = GoogleGAL_Utils::camelCase($key))) {
|
93 |
// This checks if property exists as camelCase, leaving it in array as snake_case
|
94 |
// in case of backwards compatibility issues.
|
95 |
$this->$camelKey = $val;
|
136 |
*/
|
137 |
private function getSimpleValue($value)
|
138 |
{
|
139 |
+
if ($value instanceof GoogleGAL_Model) {
|
140 |
return $value->toSimpleObject();
|
141 |
} else if (is_array($value)) {
|
142 |
$return = array();
|
185 |
|
186 |
/**
|
187 |
* Verify if $obj is an array.
|
188 |
+
* @throws GoogleGAL_Exception Thrown if $obj isn't an array.
|
189 |
* @param array $obj Items that should be validated.
|
190 |
* @param string $method Method expecting an array as an argument.
|
191 |
*/
|
192 |
public function assertIsArray($obj, $method)
|
193 |
{
|
194 |
if ($obj && !is_array($obj)) {
|
195 |
+
throw new GoogleGAL_Exception(
|
196 |
"Incorrect parameter type passed to $method(). Expected an array."
|
197 |
);
|
198 |
}
|
core/Google/README.md
CHANGED
@@ -18,10 +18,10 @@ See the examples/ directory for examples of the key client features.
|
|
18 |
<?php
|
19 |
require_once 'Google/Client.php';
|
20 |
require_once 'Google/Service/Books.php';
|
21 |
-
$client = new
|
22 |
$client->setApplicationName("Client_Library_Examples");
|
23 |
$client->setDeveloperKey("YOUR_APP_KEY");
|
24 |
-
$service = new
|
25 |
$optParams = array('filter' => 'free-ebooks');
|
26 |
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
|
27 |
|
@@ -46,7 +46,7 @@ We accept contributions via Github Pull Requests, but all contributors need to b
|
|
46 |
|
47 |
When we started working on the 1.0.0 branch we knew there were several fundamental issues to fix with the 0.6 releases of the library. At that time we looked at the usage of the library, and other related projects, and determined that there was still a large and active base of PHP 5.2 installs. You can see this in statistics such as the PHP versions chart in the WordPress stats: http://wordpress.org/about/stats/. We will keep looking at the types of usage we see, and try to take advantage of newer PHP features where possible.
|
48 |
|
49 |
-
### Why does
|
50 |
|
51 |
The _Service classes are generally automatically generated from the API discovery documents: https://developers.google.com/discovery/. Sometimes new features are added to APIs with unusual names, which can cause some unexpected or non-standard style naming in the PHP classes.
|
52 |
|
18 |
<?php
|
19 |
require_once 'Google/Client.php';
|
20 |
require_once 'Google/Service/Books.php';
|
21 |
+
$client = new GoogleGAL_Client();
|
22 |
$client->setApplicationName("Client_Library_Examples");
|
23 |
$client->setDeveloperKey("YOUR_APP_KEY");
|
24 |
+
$service = new GoogleGAL_Service_Books($client);
|
25 |
$optParams = array('filter' => 'free-ebooks');
|
26 |
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
|
27 |
|
46 |
|
47 |
When we started working on the 1.0.0 branch we knew there were several fundamental issues to fix with the 0.6 releases of the library. At that time we looked at the usage of the library, and other related projects, and determined that there was still a large and active base of PHP 5.2 installs. You can see this in statistics such as the PHP versions chart in the WordPress stats: http://wordpress.org/about/stats/. We will keep looking at the types of usage we see, and try to take advantage of newer PHP features where possible.
|
48 |
|
49 |
+
### Why does GoogleGAL_..._Service have weird names? ###
|
50 |
|
51 |
The _Service classes are generally automatically generated from the API discovery documents: https://developers.google.com/discovery/. Sometimes new features are added to APIs with unusual names, which can cause some unexpected or non-standard style naming in the PHP classes.
|
52 |
|
core/Google/Service.php
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
* limitations under the License.
|
16 |
*/
|
17 |
|
18 |
-
class
|
19 |
{
|
20 |
public $version;
|
21 |
public $servicePath;
|
@@ -23,14 +23,14 @@ class Google_Service
|
|
23 |
public $resource;
|
24 |
private $client;
|
25 |
|
26 |
-
public function __construct(
|
27 |
{
|
28 |
$this->client = $client;
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
-
* Return the associated
|
33 |
-
* @return
|
34 |
*/
|
35 |
public function getClient()
|
36 |
{
|
15 |
* limitations under the License.
|
16 |
*/
|
17 |
|
18 |
+
class GoogleGAL_Service
|
19 |
{
|
20 |
public $version;
|
21 |
public $servicePath;
|
23 |
public $resource;
|
24 |
private $client;
|
25 |
|
26 |
+
public function __construct(GoogleGAL_Client $client)
|
27 |
{
|
28 |
$this->client = $client;
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
+
* Return the associated GoogleGAL_Client class.
|
33 |
+
* @return GoogleGAL_Client
|
34 |
*/
|
35 |
public function getClient()
|
36 |
{
|
core/Google/Service/AdExchangeBuyer.php
CHANGED
@@ -29,7 +29,7 @@
|
|
29 |
*
|
30 |
* @author Google, Inc.
|
31 |
*/
|
32 |
-
class
|
33 |
{
|
34 |
/** Manage your Ad Exchange buyer account configuration. */
|
35 |
const ADEXCHANGE_BUYER = "https://www.googleapis.com/auth/adexchange.buyer";
|
@@ -43,16 +43,16 @@ class Google_Service_AdExchangeBuyer extends Google_Service
|
|
43 |
/**
|
44 |
* Constructs the internal representation of the AdExchangeBuyer service.
|
45 |
*
|
46 |
-
* @param
|
47 |
*/
|
48 |
-
public function __construct(
|
49 |
{
|
50 |
parent::__construct($client);
|
51 |
$this->servicePath = 'adexchangebuyer/v1.3/';
|
52 |
$this->version = 'v1.3';
|
53 |
$this->serviceName = 'adexchangebuyer';
|
54 |
|
55 |
-
$this->accounts = new
|
56 |
$this,
|
57 |
$this->serviceName,
|
58 |
'accounts',
|
@@ -96,7 +96,7 @@ class Google_Service_AdExchangeBuyer extends Google_Service
|
|
96 |
)
|
97 |
)
|
98 |
);
|
99 |
-
$this->creatives = new
|
100 |
$this,
|
101 |
$this->serviceName,
|
102 |
'creatives',
|
@@ -142,7 +142,7 @@ class Google_Service_AdExchangeBuyer extends Google_Service
|
|
142 |
)
|
143 |
)
|
144 |
);
|
145 |
-
$this->directDeals = new
|
146 |
$this,
|
147 |
$this->serviceName,
|
148 |
'directDeals',
|
@@ -166,7 +166,7 @@ class Google_Service_AdExchangeBuyer extends Google_Service
|
|
166 |
)
|
167 |
)
|
168 |
);
|
169 |
-
$this->performanceReport = new
|
170 |
$this,
|
171 |
$this->serviceName,
|
172 |
'performanceReport',
|
@@ -212,11 +212,11 @@ class Google_Service_AdExchangeBuyer extends Google_Service
|
|
212 |
* The "accounts" collection of methods.
|
213 |
* Typical usage is:
|
214 |
* <code>
|
215 |
-
* $adexchangebuyerService = new
|
216 |
* $accounts = $adexchangebuyerService->accounts;
|
217 |
* </code>
|
218 |
*/
|
219 |
-
class
|
220 |
{
|
221 |
|
222 |
/**
|
@@ -225,25 +225,25 @@ class Google_Service_AdExchangeBuyer_Accounts_Resource extends Google_Service_Re
|
|
225 |
* @param int $id
|
226 |
* The account id
|
227 |
* @param array $optParams Optional parameters.
|
228 |
-
* @return
|
229 |
*/
|
230 |
public function get($id, $optParams = array())
|
231 |
{
|
232 |
$params = array('id' => $id);
|
233 |
$params = array_merge($params, $optParams);
|
234 |
-
return $this->call('get', array($params), "
|
235 |
}
|
236 |
/**
|
237 |
* Retrieves the authenticated user's list of accounts. (accounts.listAccounts)
|
238 |
*
|
239 |
* @param array $optParams Optional parameters.
|
240 |
-
* @return
|
241 |
*/
|
242 |
public function listAccounts($optParams = array())
|
243 |
{
|
244 |
$params = array();
|
245 |
$params = array_merge($params, $optParams);
|
246 |
-
return $this->call('list', array($params), "
|
247 |
}
|
248 |
/**
|
249 |
* Updates an existing account. This method supports patch semantics.
|
@@ -251,30 +251,30 @@ class Google_Service_AdExchangeBuyer_Accounts_Resource extends Google_Service_Re
|
|
251 |
*
|
252 |
* @param int $id
|
253 |
* The account id
|
254 |
-
* @param
|
255 |
* @param array $optParams Optional parameters.
|
256 |
-
* @return
|
257 |
*/
|
258 |
-
public function patch($id,
|
259 |
{
|
260 |
$params = array('id' => $id, 'postBody' => $postBody);
|
261 |
$params = array_merge($params, $optParams);
|
262 |
-
return $this->call('patch', array($params), "
|
263 |
}
|
264 |
/**
|
265 |
* Updates an existing account. (accounts.update)
|
266 |
*
|
267 |
* @param int $id
|
268 |
* The account id
|
269 |
-
* @param
|
270 |
* @param array $optParams Optional parameters.
|
271 |
-
* @return
|
272 |
*/
|
273 |
-
public function update($id,
|
274 |
{
|
275 |
$params = array('id' => $id, 'postBody' => $postBody);
|
276 |
$params = array_merge($params, $optParams);
|
277 |
-
return $this->call('update', array($params), "
|
278 |
}
|
279 |
}
|
280 |
|
@@ -282,11 +282,11 @@ class Google_Service_AdExchangeBuyer_Accounts_Resource extends Google_Service_Re
|
|
282 |
* The "creatives" collection of methods.
|
283 |
* Typical usage is:
|
284 |
* <code>
|
285 |
-
* $adexchangebuyerService = new
|
286 |
* $creatives = $adexchangebuyerService->creatives;
|
287 |
* </code>
|
288 |
*/
|
289 |
-
class
|
290 |
{
|
291 |
|
292 |
/**
|
@@ -298,26 +298,26 @@ class Google_Service_AdExchangeBuyer_Creatives_Resource extends Google_Service_R
|
|
298 |
* @param string $buyerCreativeId
|
299 |
* The buyer-specific id for this creative.
|
300 |
* @param array $optParams Optional parameters.
|
301 |
-
* @return
|
302 |
*/
|
303 |
public function get($accountId, $buyerCreativeId, $optParams = array())
|
304 |
{
|
305 |
$params = array('accountId' => $accountId, 'buyerCreativeId' => $buyerCreativeId);
|
306 |
$params = array_merge($params, $optParams);
|
307 |
-
return $this->call('get', array($params), "
|
308 |
}
|
309 |
/**
|
310 |
* Submit a new creative. (creatives.insert)
|
311 |
*
|
312 |
-
* @param
|
313 |
* @param array $optParams Optional parameters.
|
314 |
-
* @return
|
315 |
*/
|
316 |
-
public function insert(
|
317 |
{
|
318 |
$params = array('postBody' => $postBody);
|
319 |
$params = array_merge($params, $optParams);
|
320 |
-
return $this->call('insert', array($params), "
|
321 |
}
|
322 |
/**
|
323 |
* Retrieves a list of the authenticated user's active creatives. A creative
|
@@ -332,13 +332,13 @@ class Google_Service_AdExchangeBuyer_Creatives_Resource extends Google_Service_R
|
|
332 |
* parameter to the value of "nextPageToken" from the previous response. Optional.
|
333 |
* @opt_param string maxResults
|
334 |
* Maximum number of entries returned on one result page. If not set, the default is 100. Optional.
|
335 |
-
* @return
|
336 |
*/
|
337 |
public function listCreatives($optParams = array())
|
338 |
{
|
339 |
$params = array();
|
340 |
$params = array_merge($params, $optParams);
|
341 |
-
return $this->call('list', array($params), "
|
342 |
}
|
343 |
}
|
344 |
|
@@ -346,11 +346,11 @@ class Google_Service_AdExchangeBuyer_Creatives_Resource extends Google_Service_R
|
|
346 |
* The "directDeals" collection of methods.
|
347 |
* Typical usage is:
|
348 |
* <code>
|
349 |
-
* $adexchangebuyerService = new
|
350 |
* $directDeals = $adexchangebuyerService->directDeals;
|
351 |
* </code>
|
352 |
*/
|
353 |
-
class
|
354 |
{
|
355 |
|
356 |
/**
|
@@ -359,26 +359,26 @@ class Google_Service_AdExchangeBuyer_DirectDeals_Resource extends Google_Service
|
|
359 |
* @param string $id
|
360 |
* The direct deal id
|
361 |
* @param array $optParams Optional parameters.
|
362 |
-
* @return
|
363 |
*/
|
364 |
public function get($id, $optParams = array())
|
365 |
{
|
366 |
$params = array('id' => $id);
|
367 |
$params = array_merge($params, $optParams);
|
368 |
-
return $this->call('get', array($params), "
|
369 |
}
|
370 |
/**
|
371 |
* Retrieves the authenticated user's list of direct deals.
|
372 |
* (directDeals.listDirectDeals)
|
373 |
*
|
374 |
* @param array $optParams Optional parameters.
|
375 |
-
* @return
|
376 |
*/
|
377 |
public function listDirectDeals($optParams = array())
|
378 |
{
|
379 |
$params = array();
|
380 |
$params = array_merge($params, $optParams);
|
381 |
-
return $this->call('list', array($params), "
|
382 |
|