Skip to content

Commit a1f05ce

Browse files
authored
chore: fix tests in preparation of google/apiclient-services:v0.200.0 release (#2086)
1 parent 62f57e7 commit a1f05ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+568
-468
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ $client = new Google\Client();
138138
$client->setApplicationName("Client_Library_Examples");
139139
$client->setDeveloperKey("YOUR_APP_KEY");
140140

141-
$service = new Google_Service_Books($client);
142-
$optParams = array(
141+
$service = new Google\Service\Books($client);
142+
$query = 'Henry David Thoreau';
143+
$optParams = [
143144
'filter' => 'free-ebooks',
144-
'q' => 'Henry David Thoreau'
145-
);
146-
$results = $service->volumes->listVolumes($optParams);
145+
];
146+
$results = $service->volumes->listVolumes($query, $optParams);
147147

148148
foreach ($results->getItems() as $item) {
149149
echo $item['volumeInfo']['title'], "<br /> \n";
@@ -166,7 +166,7 @@ foreach ($results->getItems() as $item) {
166166
1. Set the scopes required for the API you are going to call
167167

168168
```php
169-
$client->addScope(Google_Service_Drive::DRIVE);
169+
$client->addScope(Google\Service\Drive::DRIVE);
170170
```
171171

172172
1. Set your application's redirect URI
@@ -213,7 +213,7 @@ calls return unexpected 401 or 403 errors.
213213
1. Set the scopes required for the API you are going to call
214214

215215
```php
216-
$client->addScope(Google_Service_Drive::DRIVE);
216+
$client->addScope(Google\Service\Drive::DRIVE);
217217
```
218218

219219
1. If you have delegated domain-wide access to the service account and you want to impersonate a user account, specify the email address of the user account using the method setSubject:
@@ -264,10 +264,10 @@ Using this library, the same call would look something like this:
264264

265265
```php
266266
// create the datastore service class
267-
$datastore = new Google_Service_Datastore($client);
267+
$datastore = new Google\Service\Datastore($client);
268268

269269
// build the query - this maps directly to the JSON
270-
$query = new Google_Service_Datastore_Query([
270+
$query = new Google\Service\Datastore\Query([
271271
'kind' => [
272272
[
273273
'name' => 'Book',
@@ -283,28 +283,28 @@ $query = new Google_Service_Datastore_Query([
283283
]);
284284

285285
// build the request and response
286-
$request = new Google_Service_Datastore_RunQueryRequest(['query' => $query]);
286+
$request = new Google\Service\Datastore\RunQueryRequest(['query' => $query]);
287287
$response = $datastore->projects->runQuery('YOUR_DATASET_ID', $request);
288288
```
289289

290290
However, as each property of the JSON API has a corresponding generated class, the above code could also be written like this:
291291

292292
```php
293293
// create the datastore service class
294-
$datastore = new Google_Service_Datastore($client);
294+
$datastore = new Google\Service\Datastore($client);
295295

296296
// build the query
297-
$request = new Google_Service_Datastore_RunQueryRequest();
298-
$query = new Google_Service_Datastore_Query();
297+
$request = new Google\Service\Datastore_RunQueryRequest();
298+
$query = new Google\Service\Datastore\Query();
299299
// - set the order
300-
$order = new Google_Service_Datastore_PropertyOrder();
300+
$order = new Google\Service\Datastore_PropertyOrder();
301301
$order->setDirection('descending');
302-
$property = new Google_Service_Datastore_PropertyReference();
302+
$property = new Google\Service\Datastore\PropertyReference();
303303
$property->setName('title');
304304
$order->setProperty($property);
305305
$query->setOrder([$order]);
306306
// - set the kinds
307-
$kind = new Google_Service_Datastore_KindExpression();
307+
$kind = new Google\Service\Datastore\KindExpression();
308308
$kind->setName('Book');
309309
$query->setKinds([$kind]);
310310
// - set the limit
@@ -335,7 +335,7 @@ $client = new Google\Client();
335335
* Application Default Credentials.
336336
*/
337337
$client->useApplicationDefaultCredentials();
338-
$client->addScope(Google_Service_Plus::PLUS_ME);
338+
$client->addScope(Google\Service\Plus::PLUS_ME);
339339

340340
// returns a Guzzle HTTP Client
341341
$httpClient = $client->authorize();
@@ -438,9 +438,9 @@ If there is a specific bug with the library, please [file an issue](https://gith
438438

439439
If X is a feature of the library, file away! If X is an example of using a specific service, the best place to go is to the teams for those specific APIs - our preference is to link to their examples rather than add them to the library, as they can then pin to specific versions of the library. If you have any examples for other APIs, let us know and we will happily add a link to the README above!
440440

441-
### Why does Google_..._Service have weird names? ###
441+
### Why do some Google\Service classes have weird names? ###
442442

443-
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.
443+
The _Google\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.
444444

445445
### How do I deal with non-JSON response types? ###
446446

UPGRADING.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,53 @@
11
Google API Client Upgrade Guide
22
===============================
33

4+
2.x to 2.10.0
5+
-------------
6+
7+
### Namespaces
8+
9+
The Google API Client for PHP now uses namespaces for all classes. Code using
10+
the legacy classnames will continue to work, but it is advised to upgrade to the
11+
underspaced names, as the legacy classnames will be deprecated some time in the
12+
future.
13+
14+
**Before**
15+
16+
```php
17+
$client = new Google_Client();
18+
$service = new Google_Service_Books($client);
19+
```
20+
21+
**After**
22+
```php
23+
$client = new Google\Client();
24+
$service = new Google\Service\Books($client);
25+
```
26+
27+
### Service class constructors
28+
29+
Service class constructors now accept an optional `Google\Client|array` parameter
30+
as their first argument, rather than requiring an instance of `Google\Client`.
31+
32+
**Before**
33+
34+
```php
35+
$client = new Google_Client();
36+
$client->setApplicationName("Client_Library_Examples");
37+
$client->setDeveloperKey("YOUR_APP_KEY");
38+
39+
$service = new Google_Service_Books($client);
40+
```
41+
42+
**After**
43+
44+
```php
45+
$service = new Google\Service\Books([
46+
'application_name' => "Client_Library_Examples",
47+
'developer_key' => "YOUR_APP_KEY",
48+
]);
49+
```
50+
451
1.0 to 2.0
552
----------
653

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"require": {
99
"php": "^5.6|^7.0|^8.0",
1010
"google/auth": "^1.10",
11-
"google/apiclient-services": "~0.13",
11+
"google/apiclient-services": "^0.200.0",
1212
"firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0",
1313
"monolog/monolog": "^1.17|^2.0",
1414
"phpseclib/phpseclib": "~2.0||^3.0.2",

docs/media.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The PHP client library allows for uploading large files for use with APIs such a
77
In the simple upload case, the data is passed as the body of the request made to the server. This limits the ability to specify metadata, but is very easy to use.
88

99
```php
10-
$file = new Google_Service_Drive_DriveFile();
10+
$file = new Google\Service\Drive\DriveFile();
1111
$result = $service->files->insert($file, array(
1212
'data' => file_get_contents("path/to/file"),
1313
'mimeType' => 'application/octet-stream',
@@ -20,7 +20,7 @@ $result = $service->files->insert($file, array(
2020
With multipart file uploads, the uploaded file is sent as one part of a multipart form post. This allows metadata about the file object to be sent as part of the post as well. This is triggered by specifying the _multipart_ uploadType.
2121

2222
```php
23-
$file = new Google_Service_Drive_DriveFile();
23+
$file = new Google\Service\Drive\DriveFile();
2424
$file->setTitle("Hello World!");
2525
$result = $service->files->insert($file, array(
2626
'data' => file_get_contents("path/to/file"),
@@ -34,7 +34,7 @@ $result = $service->files->insert($file, array(
3434
It is also possible to split the upload across multiple requests. This is convenient for larger files, and allows resumption of the upload if there is a problem. Resumable uploads can be sent with separate metadata.
3535

3636
```php
37-
$file = new Google_Service_Drive_DriveFile();
37+
$file = new Google\Service\Drive\DriveFile();
3838
$file->title = "Big File";
3939
$chunkSizeBytes = 1 * 1024 * 1024;
4040

docs/oauth-server.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Use the authorized `Google\Client` object to call Google APIs by completing the
8787
1. Build a service object for the API that you want to call, providing the authorized `Google\Client` object. For example, to call the Cloud SQL Administration API:
8888

8989
```php
90-
$sqladmin = new Google_Service_SQLAdmin($client);
90+
$sqladmin = new Google\Service\SQLAdmin($client);
9191
```
9292

9393
2. Make requests to the API service using the [interface provided by the service object](https://github.com/googleapis/google-api-php-client/blob/master/docs/start.md#build-the-service-object). For example, to list the instances of Cloud SQL databases in the examinable-example-123 project:
@@ -133,7 +133,7 @@ putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
133133
$client = new Google\Client();
134134
$client->useApplicationDefaultCredentials();
135135

136-
$sqladmin = new Google_Service_SQLAdmin($client);
136+
$sqladmin = new Google\Service\SQLAdmin($client);
137137
$response = $sqladmin->instances
138138
->listInstances('examinable-example-123')->getItems();
139139
echo json_encode($response) . "\n";

docs/oauth-web.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ For example, this code requests read-only, offline access to a user's Google Dri
8282
```php
8383
$client = new Google\Client();
8484
$client->setAuthConfig('client_secret.json');
85-
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
85+
$client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY);
8686
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
8787
$client->setAccessType('offline'); // offline access
8888
$client->setIncludeGrantedScopes(true); // incremental auth
@@ -118,7 +118,7 @@ $client->setRedirectUri('http://localhost:8080/oauth2callback.php');
118118
Scopes enable your application to only request access to the resources that it needs while also enabling users to control the amount of access that they grant to your application. Thus, there is an inverse relationship between the number of scopes requested and the likelihood of obtaining user consent. To set this value in PHP, call the `addScope` function:
119119
120120
```php
121-
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
121+
$client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY);
122122
```
123123
124124
The [OAuth 2.0 API Scopes](https://developers.google.com/identity/protocols/googlescopes) document provides a full list of scopes that you might use to access Google APIs.
@@ -284,7 +284,7 @@ Use the access token to call Google APIs by completing the following steps:
284284
2. Build a service object for the API that you want to call. You build a a service object by providing an authorized `Google\Client` object to the constructor for the API you want to call. For example, to call the Drive API:
285285

286286
```php
287-
$drive = new Google_Service_Drive($client);
287+
$drive = new Google\Service\Drive($client);
288288
```
289289

290290
3. Make requests to the API service using the [interface provided by the service object](start.md). For example, to list the files in the authenticated user's Google Drive:
@@ -331,11 +331,11 @@ session_start();
331331
332332
$client = new Google\Client();
333333
$client->setAuthConfig('client_secrets.json');
334-
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
334+
$client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY);
335335
336336
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
337337
$client->setAccessToken($_SESSION['access_token']);
338-
$drive = new Google_Service_Drive($client);
338+
$drive = new Google\Service\Drive($client);
339339
$files = $drive->files->listFiles(array())->getItems();
340340
echo json_encode($files);
341341
} else {
@@ -355,7 +355,7 @@ session_start();
355355
$client = new Google\Client();
356356
$client->setAuthConfigFile('client_secrets.json');
357357
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
358-
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
358+
$client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY);
359359
360360
if (! isset($_GET['code'])) {
361361
$auth_url = $client->createAuthUrl();

docs/parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Standard Parameters
22

3-
Many API methods include support for certain optional parameters. In addition to these there are several standard parameters that can be applied to any API call. These are defined in the `Google_Service_Resource` class.
3+
Many API methods include support for certain optional parameters. In addition to these there are several standard parameters that can be applied to any API call. These are defined in the `Google\Service\Resource` class.
44

55
## Parameters
66

docs/start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ $client->setDeveloperKey("MY_SIMPLE_API_KEY");
6464
Services are called through queries to service specific objects. These are created by constructing the service object, and passing an instance of `Google\Client` to it. `Google\Client` contains the IO, authentication and other classes required by the service to function, and the service informs the client which scopes it uses to provide a default when authenticating a user.
6565

6666
```php
67-
$service = new Google_Service_Books($client);
67+
$service = new Google\Service\Books($client);
6868
```
6969

7070
### Calling an API

examples/batch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343
$client->setDeveloperKey($apiKey);
4444

45-
$service = new Google_Service_Books($client);
45+
$service = new Google\Service\Books($client);
4646

4747
/************************************************
4848
To actually make the batch call we need to

examples/large-file-download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$client->setAuthConfig($oauth_credentials);
3939
$client->setRedirectUri($redirect_uri);
4040
$client->addScope("https://www.googleapis.com/auth/drive");
41-
$service = new Google_Service_Drive($client);
41+
$service = new Google\Service\Drive($client);
4242

4343
/************************************************
4444
* If we have a code back from the OAuth 2.0 flow,

0 commit comments

Comments
 (0)