Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 215 lines (187 sloc) 6.873 kb
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
1 <?php
2 /*
3 * Copyright 2010 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
17
18 /*
19 * This file has been modified by Mashery, Inc.
20 *
21 * Note that the original work's copyright and license information is located at
22 * the top of this file. Any modifications made by Mashery, Inc. are licensed
23 * under the following license.
24 *
25 * Copyright (c) 2012 Mashery, Inc.
26 *
27 * Permission is hereby granted, free of charge, to any person obtaining
28 * a copy of this software and associated documentation files (the
29 * "Software"), to deal in the Software without restriction, including
30 * without limitation the rights to use, copy, modify, merge, publish,
31 * distribute, sublicense, and/or sell copies of the Software, and to
32 * permit persons to whom the Software is furnished to do so, subject to
33 * the following conditions:
34
35 * The above copyright notice and this permission notice shall be
36 * included in all copies or substantial portions of the Software.
37
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
42 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
43 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
44 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 *
46 * @author Neil Mansilla <neil@mashery.com>
47 */
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
48
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
49 // Check for the required json and curl extensions, the Google API PHP Client won'tfunction without them.
26561cfb » chabotc
2010-08-23 Fully working list, get, update and insert plus few little fixes
50 if (! function_exists('curl_init')) {
dd00881b » chirags@google.com
2012-02-09 Safe-guard against http_build_query not being available. Ensure that …
51 throw new Exception('Google PHP API Client requires the CURL PHP extension');
d8f73734 » chabotc
2010-08-22 Reworked the http fetching, request building and signing chains to be…
52 }
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
53
26561cfb » chabotc
2010-08-23 Fully working list, get, update and insert plus few little fixes
54 if (! function_exists('json_decode')) {
dd00881b » chirags@google.com
2012-02-09 Safe-guard against http_build_query not being available. Ensure that …
55 throw new Exception('Google PHP API Client requires the JSON PHP extension');
56 }
57
58 if (! function_exists('http_build_query')) {
59 throw new Exception('Google PHP API Client requires http_build_query()');
d8f73734 » chabotc
2010-08-22 Reworked the http fetching, request building and signing chains to be…
60 }
61
622f6b09 » chirags@google.com
2012-01-12 Only call date_default_timezone_set when date.timezone isnt populated
62 if (! ini_get('date.timezone') && function_exists('date_default_timezone_set')) {
1bf0af25 » chirags@google.com
2012-01-04 [fix issue 62] - Set the default timezone property as UTC, as it is r…
63 date_default_timezone_set('UTC');
64 }
65
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
66 $cwd = dirname(__FILE__);
67 set_include_path("$cwd" . PATH_SEPARATOR . get_include_path());
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
68
69 require_once "config.php";
d8f73734 » chabotc
2010-08-22 Reworked the http fetching, request building and signing chains to be…
70 // If a local configuration file is found, merge it's values with the default configuration
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
71 if (file_exists($cwd . '/local_config.php')) {
d8f73734 » chabotc
2010-08-22 Reworked the http fetching, request building and signing chains to be…
72 $defaultConfig = $apiConfig;
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
73 require_once ($cwd . '/local_config.php');
d8f73734 » chabotc
2010-08-22 Reworked the http fetching, request building and signing chains to be…
74 $apiConfig = array_merge($defaultConfig, $apiConfig);
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
75 }
d8f73734 » chabotc
2010-08-22 Reworked the http fetching, request building and signing chains to be…
76
77 // Include the top level classes, they each include their own dependencies
4ec25d99 » chirags@google.com
2012-02-07 Move all required dependencies to be required by apiClient instead of…
78 require_once 'service/apiModel.php';
79 require_once 'service/apiService.php';
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
80 require_once 'service/apiServiceRequest.php';
95e2cbca » chirags@google.com
2011-10-27 Clean up documentation.
81 require_once 'auth/apiAuth.php';
82 require_once 'cache/apiCache.php';
83 require_once 'io/apiIO.php';
8af44ca8 » chirags@google.com
2012-01-31 Add support for media uploads
84 require_once('service/apiMediaFileUpload.php');
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
85
cb486e3b » chabotc
2010-08-19 working on the request pipeline and initial modeling for batching, wh…
86 /**
0ec728b7 » chabotc
2010-08-30 Improved class documentation a bit
87 * The Google API Client
88 * http://code.google.com/p/google-api-php-client/
89 *
90 * @author Chris Chabot <chabotc@google.com>
288fe8f4 » chirags@google.com
2011-11-08 Add more documentation to public methods in apiClient.php.
91 * @author Chirag Shah <chirags@google.com>
cb486e3b » chabotc
2010-08-19 working on the request pipeline and initial modeling for batching, wh…
92 */
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
93 class apiClient {
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
94 // the version of the discovery mechanism this class is meant to work with
95 const discoveryVersion = 'v0.3';
96
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
97 /**
98 * @static
99 * @var apiAuth $auth
100 */
101 static $auth;
95e2cbca » chirags@google.com
2011-10-27 Clean up documentation.
102
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
103 /** @var apiIo $io */
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
104 static $io;
95e2cbca » chirags@google.com
2011-10-27 Clean up documentation.
105
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
106 /** @var apiCache $cache */
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
107 static $cache;
95e2cbca » chirags@google.com
2011-10-27 Clean up documentation.
108
109 /** @var array $scopes */
d865676d » chirags@google.com
2011-05-20 $scopes is advertised to be a space delimited string, but is processe…
110 protected $scopes = array();
95e2cbca » chirags@google.com
2011-10-27 Clean up documentation.
111
112 /** @var bool $useObjects */
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
113 protected $useObjects = true;
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
114
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
115 // definitions of services that are discovered.
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
116 protected $services = array();
117
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
118 public function __construct($config = array()) {
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
119 global $apiConfig;
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
120 $apiConfig = array_merge($apiConfig, $config);
121 self::$cache = new $apiConfig['cacheClass']();
122 self::$auth = new $apiConfig['authClass']();
123 self::$io = new $apiConfig['ioClass']();
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
124 }
125
5cb14696 » chabotc
2010-08-26 Implemented an api wrapper generator, and generated classes for a num…
126 /**
127 * Add a service
128 */
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
129 public function addService($service, $version) {
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
130 global $apiConfig;
131 if ($this->authenticated) {
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
132 // Adding services after being authenticated, since the oauth scope is already set (so you wouldn't have access to that data)
95e2cbca » chirags@google.com
2011-10-27 Clean up documentation.
133 throw new apiException('Cant add services after having authenticated');
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
134 }
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
135 $this->services[$service] = $this->defaultService;
b3750c9a » chabotc
2010-11-02 If a service is unknown, use the default service config
136 if (isset($apiConfig['services'][$service])) {
137 // Merge the service descriptor with the default values
138 $this->services[$service] = array_merge($this->services[$service], $apiConfig['services'][$service]);
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
139 }
e6243831 » chirags@google.com
2011-09-12 Update all example apps to use the apiClient methods "setClientId/set…
140 }
141
288fe8f4 » chirags@google.com
2011-11-08 Add more documentation to public methods in apiClient.php.
142 /**
cddf1f62 » chirags@google.com
2012-03-23 -Add support for service accounts in the PHP client.
143 * Set the type of Auth class the client should use.
144 * @param string $authClassName
145 */
146 public function setAuthClass($authClassName) {
147 self::$auth = new $authClassName();
148 }
149
150 /**
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
151 * Set the developer key to use
e7418e7e » chirags@google.com
2011-09-01 Allow applications to set their application name in the application_n…
152 * @param string $developerKey
85839d37 » chabotc
2010-12-22 Fix up developer key support
153 */
154 public function setDeveloperKey($developerKey) {
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
155 self::$auth->setDeveloperKey($developerKey);
85839d37 » chabotc
2010-12-22 Fix up developer key support
156 }
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
157
0994bf2b » chirags@google.com
2011-11-17 Add support for two new parameters to the OAuth2 authorization URL.
158 /**
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
159 * * Set the developer shared secret to use
160 * @param string $developersecret
0994bf2b » chirags@google.com
2011-11-17 Add support for two new parameters to the OAuth2 authorization URL.
161 */
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
162 public function setDeveloperSecret($developerSecret) {
163 self::$auth->setDeveloperSecret($developerSecret);
0994bf2b » chirags@google.com
2011-11-17 Add support for two new parameters to the OAuth2 authorization URL.
164 }
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
165
3b05c9f6 » chirags@google.com
2011-10-04 [fix issue 17] - Add support for the OAuth 2 State Parameter.
166 /**
e7418e7e » chirags@google.com
2011-09-01 Allow applications to set their application name in the application_n…
167 * Set the application name, this is included in the User-Agent HTTP header.
168 * @param string $applicationName
169 */
170 public function setApplicationName($applicationName) {
171 global $apiConfig;
172 $apiConfig['application_name'] = $applicationName;
173 }
174
175 /**
08d9d740 » chirags@google.com
2011-09-06 Declare if objects or arrays should be returned by the api service cl…
176 * Declare if objects should be returned by the api service classes.
177 *
178 * @param boolean $useObjects True if objects should be returned by the service classes.
179 * False if associative arrays should be returned (default behavior).
180 */
181 public function setUseObjects($useObjects) {
182 global $apiConfig;
183 $apiConfig['use_objects'] = $useObjects;
184 }
185
cddf1f62 » chirags@google.com
2012-03-23 -Add support for service accounts in the PHP client.
186 /**
86fe1d2b » chirags@google.com
2012-01-06 Improve documentation inside apiClient.php
187 * @static
188 * @return apiAuth the implementation of apiAuth.
189 */
190 public static function getAuth() {
191 return apiClient::$auth;
192 }
193
194 /**
195 * @static
5eff92e9 » chirags@google.com
2011-08-11 Update the OAuth2 endpoints from https://www.google.com/accounts/o8/o…
196 * @return apiIo the implementation of apiIo.
197 */
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
198 public static function getIo() {
199 return apiClient::$io;
26561cfb » chabotc
2010-08-23 Fully working list, get, update and insert plus few little fixes
200 }
201
86fe1d2b » chirags@google.com
2012-01-06 Improve documentation inside apiClient.php
202 /**
5eff92e9 » chirags@google.com
2011-08-11 Update the OAuth2 endpoints from https://www.google.com/accounts/o8/o…
203 * @return apiCache the implementation of apiCache.
204 */
205 public function getCache() {
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
206 return apiClient::$cache;
5eff92e9 » chirags@google.com
2011-08-11 Update the OAuth2 endpoints from https://www.google.com/accounts/o8/o…
207 }
ffebf788 » chabotc
2010-08-16 Initial work on implementing the discovery and request representation…
208 }
72a7b279 » chirags@google.com
2011-12-12 Remove use of global variables in the SDK (first pass).
209
210 // Exceptions that the Google PHP API Library can throw
211 class apiException extends Exception {}
212 class apiAuthException extends apiException {}
213 class apiCacheException extends apiException {}
214 class apiIOException extends apiException {}
4f823cf0 » mansilladev
2012-07-19 Signatures added, other reductions
215 class apiServiceException extends apiException {}
Something went wrong with that request. Please try again.