├── FormUploadToGoogleDrive.php
├── LinkUploadToGoogleDrive.php
├── LinkUploadToServer.php
├── README.md
├── css
└── style.css
├── google-api-php-client
├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── autoload.php
├── composer.json
├── examples
│ ├── appengineauth.php
│ ├── batch.php
│ ├── fileupload.php
│ ├── idtoken.php
│ ├── index.php
│ ├── multi-api.php
│ ├── service-account.php
│ ├── simple-query.php
│ ├── simplefileupload.php
│ ├── styles
│ │ └── style.css
│ ├── templates
│ │ └── base.php
│ └── user-example.php
├── phpunit.xml.dist
├── src
│ └── Google
│ │ ├── Auth
│ │ ├── Abstract.php
│ │ ├── AppIdentity.php
│ │ ├── AssertionCredentials.php
│ │ ├── ComputeEngine.php
│ │ ├── Exception.php
│ │ ├── LoginTicket.php
│ │ ├── OAuth2.php
│ │ └── Simple.php
│ │ ├── Cache
│ │ ├── Abstract.php
│ │ ├── Apc.php
│ │ ├── Exception.php
│ │ ├── File.php
│ │ ├── Memcache.php
│ │ └── Null.php
│ │ ├── Client.php
│ │ ├── Collection.php
│ │ ├── Config.php
│ │ ├── Exception.php
│ │ ├── Http
│ │ ├── Batch.php
│ │ ├── CacheParser.php
│ │ ├── MediaFileUpload.php
│ │ ├── REST.php
│ │ └── Request.php
│ │ ├── IO
│ │ ├── Abstract.php
│ │ ├── Curl.php
│ │ ├── Exception.php
│ │ ├── Stream.php
│ │ └── cacerts.pem
│ │ ├── Logger
│ │ ├── Abstract.php
│ │ ├── Exception.php
│ │ ├── File.php
│ │ ├── Null.php
│ │ └── Psr.php
│ │ ├── Model.php
│ │ ├── Service.php
│ │ ├── Service
│ │ ├── AdExchangeBuyer.php
│ │ ├── AdExchangeSeller.php
│ │ ├── AdSense.php
│ │ ├── AdSenseHost.php
│ │ ├── Admin.php
│ │ ├── Analytics.php
│ │ ├── AndroidPublisher.php
│ │ ├── AppState.php
│ │ ├── Appsactivity.php
│ │ ├── Audit.php
│ │ ├── Autoscaler.php
│ │ ├── Bigquery.php
│ │ ├── Blogger.php
│ │ ├── Books.php
│ │ ├── Calendar.php
│ │ ├── CivicInfo.php
│ │ ├── CloudMonitoring.php
│ │ ├── Cloudlatencytest.php
│ │ ├── Compute.php
│ │ ├── Container.php
│ │ ├── Coordinate.php
│ │ ├── Customsearch.php
│ │ ├── Dataflow.php
│ │ ├── Datastore.php
│ │ ├── Deploymentmanager.php
│ │ ├── Dfareporting.php
│ │ ├── Directory.php
│ │ ├── Dns.php
│ │ ├── DoubleClickBidManager.php
│ │ ├── Doubleclicksearch.php
│ │ ├── Drive.php
│ │ ├── Exception.php
│ │ ├── Fitness.php
│ │ ├── Freebase.php
│ │ ├── Fusiontables.php
│ │ ├── Games.php
│ │ ├── GamesConfiguration.php
│ │ ├── GamesManagement.php
│ │ ├── Genomics.php
│ │ ├── Gmail.php
│ │ ├── GroupsMigration.php
│ │ ├── Groupssettings.php
│ │ ├── IdentityToolkit.php
│ │ ├── Licensing.php
│ │ ├── Manager.php
│ │ ├── MapsEngine.php
│ │ ├── Mirror.php
│ │ ├── Oauth2.php
│ │ ├── Pagespeedonline.php
│ │ ├── Plus.php
│ │ ├── PlusDomains.php
│ │ ├── Prediction.php
│ │ ├── Pubsub.php
│ │ ├── QPXExpress.php
│ │ ├── Replicapool.php
│ │ ├── Replicapoolupdater.php
│ │ ├── Reports.php
│ │ ├── Reseller.php
│ │ ├── Resource.php
│ │ ├── Resourceviews.php
│ │ ├── ShoppingContent.php
│ │ ├── SiteVerification.php
│ │ ├── Spectrum.php
│ │ ├── Storage.php
│ │ ├── TagManager.php
│ │ ├── Taskqueue.php
│ │ ├── Tasks.php
│ │ ├── Translate.php
│ │ ├── Urlshortener.php
│ │ ├── Webfonts.php
│ │ ├── Webmasters.php
│ │ ├── YouTube.php
│ │ └── YouTubeAnalytics.php
│ │ ├── Signer
│ │ ├── Abstract.php
│ │ └── P12.php
│ │ ├── Task
│ │ ├── Exception.php
│ │ ├── Retryable.php
│ │ └── Runner.php
│ │ ├── Utils.php
│ │ ├── Utils
│ │ └── URITemplate.php
│ │ ├── Verifier
│ │ ├── Abstract.php
│ │ └── Pem.php
│ │ └── autoload.php
├── style
│ └── ruleset.xml
└── tests
│ ├── BaseTest.php
│ ├── OAuthHelper.php
│ ├── README
│ ├── adsense
│ └── AdSenseTest.php
│ ├── bootstrap.php
│ ├── general
│ ├── ApiBatchRequestTest.php
│ ├── ApiCacheParserTest.php
│ ├── ApiClientTest.php
│ ├── ApiMediaFileUploadTest.php
│ ├── ApiModelTest.php
│ ├── ApiOAuth2Test.php
│ ├── AuthTest.php
│ ├── CacheTest.php
│ ├── IoTest.php
│ ├── LoggerTest.php
│ ├── RequestTest.php
│ ├── RestTest.php
│ ├── ServiceTest.php
│ ├── TaskTest.php
│ ├── URITemplateTest.php
│ └── testdata
│ │ ├── ComputeEngineAuthTest.php
│ │ ├── cacert.json
│ │ ├── cacert.pem
│ │ ├── cert.p12
│ │ ├── privkey.pem
│ │ ├── test.ini
│ │ └── test_public_key.pem
│ ├── pagespeed
│ └── PageSpeedTest.php
│ ├── plus
│ └── PlusTest.php
│ ├── tasks
│ └── TasksTest.php
│ ├── urlshortener
│ └── UrlShortenerTests.php
│ └── youtube
│ └── YouTubeTest.php
└── index.php
/FormUploadToGoogleDrive.php:
--------------------------------------------------------------------------------
1 | setClientId('File Uploaded Successfully..
Below is the details of file:
";
60 | print_r($createdFile);
61 | //---------------------------------------------------------------
62 | // 3. removing the file from own server
63 | //---------------------------------------------------------------
64 | unlink('a.jpg'); //remove the file
65 |
66 | }
67 | // if no token
68 | else {
69 | $authUrl = $client->createAuthUrl();
70 | header('Location: ' . $authUrl);
71 | exit();
72 | }
73 | }
74 | else{
75 | ?>
76 |
80 |
--------------------------------------------------------------------------------
/LinkUploadToGoogleDrive.php:
--------------------------------------------------------------------------------
1 | setClientId('File Uploaded Successfully..
Below is the details of file:
";
68 | //---------------------------------------------------------------
69 | // 3. removing the file from own server
70 | //---------------------------------------------------------------
71 | unlink($_SESSION['filename']); //remove the file
72 | session_destroy();
73 | } else {
74 | $authUrl = $client->createAuthUrl();
75 | header('Location: ' . $authUrl);
76 | exit();
77 | }
78 | }
79 | else{
80 | ?>
81 |
82 |
86 |
87 |
--------------------------------------------------------------------------------
/LinkUploadToServer.php:
--------------------------------------------------------------------------------
1 |
2 |
6 |
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SaveToDrive
2 | Simple PHP scripts for downloading files to server or google drive from link.
3 |
4 | 1. Download file directly to the server from the link. (LinkUploadToServer.php)
5 | 2. Upload file directly to google drive using upload form. (FormUploadToGoogleDrive.php)
6 | 3. Download file directly to google drive from the link. (LinkUploadToGoogleDrive.php)
7 |
8 | #How to use
9 | 1. Download the SaveToDrive
10 | 2. Open LinkUploadToGoogleDrive.php file
11 | 3. Enable the Google Drive API (If not already done) as you will require the client_id, client_secret and uri
12 | a. Refer link: Enable Google Drive API (step-1)
13 | 4. Finally edit the following details in the file:
14 | a. Copy <CLIENT_ID> from the Google developer console
15 | b. Copy <CLIENT_SECRET> from the Google developer console
16 | c. Edit <COMPLETE_URL_OF_LinkUploadToGoogleDrive.php>
17 |
18 | # Demo example
19 | Link: save2drive.MyTechBlog.in
20 | Then select the third link to download file directly to google drive from link.
21 |
22 |
--------------------------------------------------------------------------------
/css/style.css:
--------------------------------------------------------------------------------
1 | *{
2 | margin:0px;
3 | padding:0px;
4 | border:0px;
5 | font:Georgia;
6 | font-size:20px;
7 | margin-left:auto;
8 | margin-right:auto;
9 | }
10 | .formDesigner{
11 | width:270px;
12 | height:auto;
13 | margin-top:50px;
14 | margin-left:auto;
15 | margin-right:auto;
16 | }
17 | h1{
18 | margin-bottom:20px;
19 | font-size:25px;
20 | }
21 | .formDesigner .formElements{
22 | display:block;
23 | padding:20px;
24 | background-color:#6699dd;
25 | }
26 | .submitButton{
27 | display:block;
28 | cursor:pointer;
29 | width:80px;
30 | height:30px;
31 | background-color:#fff;
32 | }
33 | input{
34 | margin-top:20px;
35 | }
36 | .Links{
37 | margin-top:10%;
38 | width:350px;
39 | height:auto;
40 | margin-left:auto;
41 | margin-right:auto;
42 | background-color:#ddd;
43 | padding:20px;
44 | }
45 | a{
46 | padding:5px;
47 | text-decoration:none;
48 | }
49 | a:hover{
50 | cursor:pointer;
51 | text-decoration:underline;
52 | }
--------------------------------------------------------------------------------
/google-api-php-client/.gitignore:
--------------------------------------------------------------------------------
1 | phpunit.xml
2 | composer.lock
3 | vendor
4 | examples/testfile-small.txt
5 | examples/testfile.txt
6 |
--------------------------------------------------------------------------------
/google-api-php-client/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | services:
4 | - memcached
5 |
6 | env:
7 | global:
8 | - MEMCACHE_HOST=127.0.0.1
9 | - MEMCACHE_PORT=11211
10 |
11 | sudo: false
12 |
13 | php:
14 | # Can't test against 5.2; openssl is not available:
15 | # http://docs.travis-ci.com/user/languages/php/#PHP-installation
16 | - 5.3
17 | - 5.4
18 | - 5.5
19 | - 5.6
20 | - hhvm
21 |
22 | before_script:
23 | - composer install
24 | - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
25 | - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
26 | - phpenv version-name | grep ^5.[34] && echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
27 | - phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
28 |
29 | script:
30 | - vendor/bin/phpunit
31 |
--------------------------------------------------------------------------------
/google-api-php-client/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to become a contributor and submit your own code
2 |
3 | ## Contributor License Agreements
4 |
5 | We'd love to accept your code patches! However, before we can take them, we have to jump a couple of legal hurdles.
6 |
7 | Please fill out either the individual or corporate Contributor License Agreement (CLA).
8 |
9 | * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html).
10 | * If you work for a company that wants to allow you to contribute your work to this client library, then you'll need to sign a[corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html).
11 |
12 | Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll add you to the official list of contributors and be able to accept your patches.
13 |
14 | ## Submitting Patches
15 |
16 | 1. Fork the PHP client library on GitHub
17 | 1. Decide which code you want to submit. A submission should be a set of changes that addresses one issue in the issue tracker. Please file one change per issue, and address one issue per change. If you want to make a change that doesn't have a corresponding issue in the issue tracker, please file a new ticket!
18 | 1. Ensure that your code adheres to standard PHP conventions, as used in the rest of the library.
19 | 1. Ensure that there are unit tests for your code.
20 | 1. Sign a Contributor License Agreement (see above).
21 | 1. Submit a pull request with your patch on Github.
22 |
23 |
--------------------------------------------------------------------------------
/google-api-php-client/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/google/google-api-php-client)
2 |
3 | # Google APIs Client Library for PHP #
4 |
5 | ## Description ##
6 | The Google API Client Library enables you to work with Google APIs such as Google+, Drive, or YouTube on your server.
7 |
8 | ## Beta ##
9 | This library is in Beta. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it. We will make an effort to support the public and protected surface of the library and maintain backwards compatibility in the future. While we are still in Beta, we reserve the right to make incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), our intention is to deprecate and provide ample time for developers to update their code.
10 |
11 | ## Requirements ##
12 | * [PHP 5.2.1 or higher](http://www.php.net/)
13 | * [PHP JSON extension](http://php.net/manual/en/book.json.php)
14 |
15 | *Note*: some features (service accounts and id token verification) require PHP 5.3.0 and above due to cryptographic algorithm requirements.
16 |
17 | ## Developer Documentation ##
18 | http://developers.google.com/api-client-library/php
19 |
20 | ## Installation ##
21 |
22 | For the latest installation and setup instructions, see [the documentation](https://developers.google.com/api-client-library/php/start/installation).
23 |
24 | ## Basic Example ##
25 | See the examples/ directory for examples of the key client features.
26 | ```PHP
27 | setApplicationName("Client_Library_Examples");
33 | $client->setDeveloperKey("YOUR_APP_KEY");
34 |
35 | $service = new Google_Service_Books($client);
36 | $optParams = array('filter' => 'free-ebooks');
37 | $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
38 |
39 | foreach ($results as $item) {
40 | echo $item['volumeInfo']['title'], "
\n";
41 | }
42 |
43 | ```
44 |
45 | ### Service Specific Examples ###
46 |
47 | YouTube: https://github.com/youtube/api-samples/tree/master/php
48 |
49 | ## Frequently Asked Questions ##
50 |
51 | ### What do I do if something isn't working? ###
52 |
53 | For support with the library the best place to ask is via the google-api-php-client tag on StackOverflow: http://stackoverflow.com/questions/tagged/google-api-php-client
54 |
55 | If there is a specific bug with the library, please file a issue in the Github issues tracker, including a (minimal) example of the failing code and any specific errors retrieved. Feature requests can also be filed, as long as they are core library requests, and not-API specific: for those, refer to the documentation for the individual APIs for the best place to file requests. Please try to provide a clear statement of the problem that the feature would address.
56 |
57 | ### How do I contribute? ###
58 |
59 | We accept contributions via Github Pull Requests, but all contributors need to be covered by the standard Google Contributor License Agreement. You can find links, and more instructions, in the documentation: https://developers.google.com/api-client-library/php/contribute
60 |
61 | ### I want an example of X! ###
62 |
63 | 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!
64 |
65 | ### Why do you still support 5.2? ###
66 |
67 | 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.
68 |
69 | ### Why does Google_..._Service have weird names? ###
70 |
71 | 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.
72 |
73 | ### How do I deal with non-JSON response types? ###
74 |
75 | Some services return XML or similar by default, rather than JSON, which is what the library supports. You can request a JSON response by adding an 'alt' argument to optional params that is normally the last argument to a method call:
76 |
77 | ```
78 | $opt_params = array(
79 | 'alt' => "json"
80 | );
81 | ```
82 |
83 | ## Notes For Distributors ##
84 |
85 | To avoid clashes with the autoloader, its best to update the function inside autoload.php to `google_api_php_client_autoload_MyProject`.
86 |
87 | ## Code Quality ##
88 |
89 | Run the PHPUnit tests with PHPUnit. You can configure and API key and token in BaseTest.php to run all calls, but this will require some setup on the Google Developer Console.
90 |
91 | phpunit tests/
92 |
93 | Copy the ruleset.xml in style/ into a new directory named GAPI/ in your
94 | /usr/share/php/PHP/CodeSniffer/Standards (or appropriate equivalent directory),
95 | and run code sniffs with:
96 |
97 | phpcs --standard=GAPI src/
98 |
--------------------------------------------------------------------------------
/google-api-php-client/autoload.php:
--------------------------------------------------------------------------------
1 | =5.2.1"
10 | },
11 | "require-dev": {
12 | "phpunit/phpunit": "3.7.*"
13 | },
14 | "autoload": {
15 | "classmap": [
16 | "src/"
17 | ]
18 | },
19 | "extra": {
20 | "branch-alias": {
21 | "dev-master": "1.1.x-dev"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/google-api-php-client/examples/appengineauth.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Client_Library_Examples");
30 |
31 | $auth = new Google_Auth_AppIdentity($client);
32 | $token = $auth->authenticateForScope(Google_Service_Storage::DEVSTORAGE_READ_ONLY);
33 | if (!$token) {
34 | die("Could not authenticate to AppIdentity service");
35 | }
36 | $client->setAuth($auth);
37 |
38 | $service = new Google_Service_Storage($client);
39 | $results = $service->buckets->listBuckets(str_replace("s~", "", $_SERVER['APPLICATION_ID']));
40 |
41 | echo "Results Of Call:
";
42 | echo "";
43 | var_dump($results);
44 | echo "
";
45 |
46 | echo pageFooter(__FILE__);
47 |
--------------------------------------------------------------------------------
/google-api-php-client/examples/batch.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Client_Library_Examples");
35 | $apiKey = "Results Of Call 1:
";
72 | foreach ($results['response-thoreau'] as $item) {
73 | echo $item['volumeInfo']['title'], "
\n";
74 | }
75 | echo "Results Of Call 2:
";
76 | foreach ($results['response-shaw'] as $item) {
77 | echo $item['volumeInfo']['title'], "
\n";
78 | }
79 | }
80 |
81 | echo pageFooter(__FILE__);
82 |
--------------------------------------------------------------------------------
/google-api-php-client/examples/fileupload.php:
--------------------------------------------------------------------------------
1 | ';
39 | $client_secret = '
10 |
19 | ';
28 | $client_secret = 'Results Of Drive List:
";
105 | foreach ($dr_results as $item) {
106 | echo $item->title, "
\n";
107 | }
108 |
109 | echo "Results Of YouTube Likes:
";
110 | foreach ($yt_results as $item) {
111 | echo $item['snippet']['title'], "
\n";
112 | }
113 | } ?>
114 | Results Of Call:
";
84 | foreach ($results as $item) {
85 | echo $item['volumeInfo']['title'], "
\n";
86 | }
87 |
88 | echo pageFooter(__FILE__);
89 |
--------------------------------------------------------------------------------
/google-api-php-client/examples/simple-query.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Client_Library_Examples");
38 | $apiKey = "Results Of Call:
";
69 | foreach ($results as $item) {
70 | echo $item['volumeInfo']['title'], "
\n";
71 | }
72 |
73 | /************************************************
74 | This is an example of deferring a call.
75 | ***********************************************/
76 | $client->setDefer(true);
77 | $optParams = array('filter' => 'free-ebooks');
78 | $request = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
79 | $results = $client->execute($request);
80 |
81 | echo "Results Of Deferred Call:
";
82 | foreach ($results as $item) {
83 | echo $item['volumeInfo']['title'], "
\n";
84 | }
85 |
86 | echo pageFooter(__FILE__);
87 |
--------------------------------------------------------------------------------
/google-api-php-client/examples/simplefileupload.php:
--------------------------------------------------------------------------------
1 | ';
39 | $client_secret = '" . $title . "
Code:
";
35 | $ret .= "";
36 | $ret .= htmlspecialchars(file_get_contents($file));
37 | $ret .= "
";
38 | }
39 | $ret .= "";
40 | }
41 | return $ret;
42 | }
43 |
44 | function missingApiKeyWarning()
45 | {
46 | $ret = "";
47 | if (isWebRequest()) {
48 | $ret = "
49 |
50 | Warning: You need to set a Simple API Access key from the
51 | Google API console
52 |
";
53 | } else {
54 | $ret = "Warning: You need to set a Simple API Access key from the Google API console:";
55 | $ret .= "\nhttp://developers.google.com/console";
56 | }
57 | return $ret;
58 | }
59 |
60 | function missingClientSecretsWarning()
61 | {
62 | $ret = "";
63 | if (isWebRequest()) {
64 | $ret = "
65 |
66 | Warning: You need to set Client ID, Client Secret and Redirect URI from the
67 | Google API console
68 |
";
69 | } else {
70 | $ret = "Warning: You need to set Client ID, Client Secret and Redirect URI from the";
71 | $ret .= "Google API console:\nhttp://developers.google.com/console";
72 | }
73 | return $ret;
74 | }
75 |
76 | function missingServiceAccountDetailsWarning()
77 | {
78 | $ret = "";
79 | if (isWebRequest()) {
80 | $ret = "
81 |
82 | Warning: You need to set Client ID, Email address and the location of the Key from the
83 | Google API console
84 |
";
85 | } else {
86 | $ret = "Warning: You need to set Client ID, Email address and the location of the Key from the";
87 | $ret .= "Google API console:\nhttp://developers.google.com/console";
88 | }
89 | return $ret;
90 | }
91 |
--------------------------------------------------------------------------------
/google-api-php-client/examples/user-example.php:
--------------------------------------------------------------------------------
1 | ';
28 | $client_secret = '
25 | * For more information about this service, see the API 26 | * Documentation 27 | *
28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_Admin extends Google_Service 32 | { 33 | /** Manage email messages of users on your domain. */ 34 | const EMAIL_MIGRATION = 35 | "https://www.googleapis.com/auth/email.migration"; 36 | 37 | public $mail; 38 | 39 | 40 | /** 41 | * Constructs the internal representation of the Admin service. 42 | * 43 | * @param Google_Client $client 44 | */ 45 | public function __construct(Google_Client $client) 46 | { 47 | parent::__construct($client); 48 | $this->servicePath = 'email/v2/users/'; 49 | $this->version = 'email_migration_v2'; 50 | $this->serviceName = 'admin'; 51 | 52 | $this->mail = new Google_Service_Admin_Mail_Resource( 53 | $this, 54 | $this->serviceName, 55 | 'mail', 56 | array( 57 | 'methods' => array( 58 | 'insert' => array( 59 | 'path' => '{userKey}/mail', 60 | 'httpMethod' => 'POST', 61 | 'parameters' => array( 62 | 'userKey' => array( 63 | 'location' => 'path', 64 | 'type' => 'string', 65 | 'required' => true, 66 | ), 67 | ), 68 | ), 69 | ) 70 | ) 71 | ); 72 | } 73 | } 74 | 75 | 76 | /** 77 | * The "mail" collection of methods. 78 | * Typical usage is: 79 | *
80 | * $adminService = new Google_Service_Admin(...);
81 | * $mail = $adminService->mail;
82 | *
83 | */
84 | class Google_Service_Admin_Mail_Resource extends Google_Service_Resource
85 | {
86 |
87 | /**
88 | * Insert Mail into Google's Gmail backends (mail.insert)
89 | *
90 | * @param string $userKey The email or immutable id of the user
91 | * @param Google_MailItem $postBody
92 | * @param array $optParams Optional parameters.
93 | */
94 | public function insert($userKey, Google_Service_Admin_MailItem $postBody, $optParams = array())
95 | {
96 | $params = array('userKey' => $userKey, 'postBody' => $postBody);
97 | $params = array_merge($params, $optParams);
98 | return $this->call('insert', array($params));
99 | }
100 | }
101 |
102 |
103 |
104 |
105 | class Google_Service_Admin_MailItem extends Google_Collection
106 | {
107 | protected $collection_key = 'labels';
108 | protected $internal_gapi_mappings = array(
109 | );
110 | public $isDeleted;
111 | public $isDraft;
112 | public $isInbox;
113 | public $isSent;
114 | public $isStarred;
115 | public $isTrash;
116 | public $isUnread;
117 | public $kind;
118 | public $labels;
119 |
120 |
121 | public function setIsDeleted($isDeleted)
122 | {
123 | $this->isDeleted = $isDeleted;
124 | }
125 | public function getIsDeleted()
126 | {
127 | return $this->isDeleted;
128 | }
129 | public function setIsDraft($isDraft)
130 | {
131 | $this->isDraft = $isDraft;
132 | }
133 | public function getIsDraft()
134 | {
135 | return $this->isDraft;
136 | }
137 | public function setIsInbox($isInbox)
138 | {
139 | $this->isInbox = $isInbox;
140 | }
141 | public function getIsInbox()
142 | {
143 | return $this->isInbox;
144 | }
145 | public function setIsSent($isSent)
146 | {
147 | $this->isSent = $isSent;
148 | }
149 | public function getIsSent()
150 | {
151 | return $this->isSent;
152 | }
153 | public function setIsStarred($isStarred)
154 | {
155 | $this->isStarred = $isStarred;
156 | }
157 | public function getIsStarred()
158 | {
159 | return $this->isStarred;
160 | }
161 | public function setIsTrash($isTrash)
162 | {
163 | $this->isTrash = $isTrash;
164 | }
165 | public function getIsTrash()
166 | {
167 | return $this->isTrash;
168 | }
169 | public function setIsUnread($isUnread)
170 | {
171 | $this->isUnread = $isUnread;
172 | }
173 | public function getIsUnread()
174 | {
175 | return $this->isUnread;
176 | }
177 | public function setKind($kind)
178 | {
179 | $this->kind = $kind;
180 | }
181 | public function getKind()
182 | {
183 | return $this->kind;
184 | }
185 | public function setLabels($labels)
186 | {
187 | $this->labels = $labels;
188 | }
189 | public function getLabels()
190 | {
191 | return $this->labels;
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Service/Dataflow.php:
--------------------------------------------------------------------------------
1 |
22 | * Google Dataflow API.
23 | *
24 | * 25 | * For more information about this service, see the API 26 | * Documentation 27 | *
28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_Dataflow extends Google_Service 32 | { 33 | 34 | 35 | 36 | 37 | 38 | /** 39 | * Constructs the internal representation of the Dataflow service. 40 | * 41 | * @param Google_Client $client 42 | */ 43 | public function __construct(Google_Client $client) 44 | { 45 | parent::__construct($client); 46 | $this->servicePath = ''; 47 | $this->version = 'v1b4'; 48 | $this->serviceName = 'dataflow'; 49 | 50 | } 51 | } 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service/Exception.php: -------------------------------------------------------------------------------- 1 | = 0) { 53 | parent::__construct($message, $code, $previous); 54 | } else { 55 | parent::__construct($message, $code); 56 | } 57 | 58 | $this->errors = $errors; 59 | 60 | if (is_array($retryMap)) { 61 | $this->retryMap = $retryMap; 62 | } 63 | } 64 | 65 | /** 66 | * An example of the possible errors returned. 67 | * 68 | * { 69 | * "domain": "global", 70 | * "reason": "authError", 71 | * "message": "Invalid Credentials", 72 | * "locationType": "header", 73 | * "location": "Authorization", 74 | * } 75 | * 76 | * @return [{string, string}] List of errors return in an HTTP response or []. 77 | */ 78 | public function getErrors() 79 | { 80 | return $this->errors; 81 | } 82 | 83 | /** 84 | * Gets the number of times the associated task can be retried. 85 | * 86 | * NOTE: -1 is returned if the task can be retried indefinitely 87 | * 88 | * @return integer 89 | */ 90 | public function allowedRetries() 91 | { 92 | if (isset($this->retryMap[$this->code])) { 93 | return $this->retryMap[$this->code]; 94 | } 95 | 96 | $errors = $this->getErrors(); 97 | 98 | if (!empty($errors) && isset($errors[0]['reason']) && 99 | isset($this->retryMap[$errors[0]['reason']])) { 100 | return $this->retryMap[$errors[0]['reason']]; 101 | } 102 | 103 | return 0; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service/GroupsMigration.php: -------------------------------------------------------------------------------- 1 | 22 | * Groups Migration Api. 23 | * 24 | *25 | * For more information about this service, see the API 26 | * Documentation 27 | *
28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_GroupsMigration extends Google_Service 32 | { 33 | 34 | 35 | public $archive; 36 | 37 | 38 | /** 39 | * Constructs the internal representation of the GroupsMigration service. 40 | * 41 | * @param Google_Client $client 42 | */ 43 | public function __construct(Google_Client $client) 44 | { 45 | parent::__construct($client); 46 | $this->servicePath = 'groups/v1/groups/'; 47 | $this->version = 'v1'; 48 | $this->serviceName = 'groupsmigration'; 49 | 50 | $this->archive = new Google_Service_GroupsMigration_Archive_Resource( 51 | $this, 52 | $this->serviceName, 53 | 'archive', 54 | array( 55 | 'methods' => array( 56 | 'insert' => array( 57 | 'path' => '{groupId}/archive', 58 | 'httpMethod' => 'POST', 59 | 'parameters' => array( 60 | 'groupId' => array( 61 | 'location' => 'path', 62 | 'type' => 'string', 63 | 'required' => true, 64 | ), 65 | ), 66 | ), 67 | ) 68 | ) 69 | ); 70 | } 71 | } 72 | 73 | 74 | /** 75 | * The "archive" collection of methods. 76 | * Typical usage is: 77 | *
78 | * $groupsmigrationService = new Google_Service_GroupsMigration(...);
79 | * $archive = $groupsmigrationService->archive;
80 | *
81 | */
82 | class Google_Service_GroupsMigration_Archive_Resource extends Google_Service_Resource
83 | {
84 |
85 | /**
86 | * Inserts a new mail into the archive of the Google group. (archive.insert)
87 | *
88 | * @param string $groupId The group ID
89 | * @param array $optParams Optional parameters.
90 | * @return Google_Service_GroupsMigration_Groups
91 | */
92 | public function insert($groupId, $optParams = array())
93 | {
94 | $params = array('groupId' => $groupId);
95 | $params = array_merge($params, $optParams);
96 | return $this->call('insert', array($params), "Google_Service_GroupsMigration_Groups");
97 | }
98 | }
99 |
100 |
101 |
102 |
103 | class Google_Service_GroupsMigration_Groups extends Google_Model
104 | {
105 | protected $internal_gapi_mappings = array(
106 | );
107 | public $kind;
108 | public $responseCode;
109 |
110 |
111 | public function setKind($kind)
112 | {
113 | $this->kind = $kind;
114 | }
115 | public function getKind()
116 | {
117 | return $this->kind;
118 | }
119 | public function setResponseCode($responseCode)
120 | {
121 | $this->responseCode = $responseCode;
122 | }
123 | public function getResponseCode()
124 | {
125 | return $this->responseCode;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Service/Webfonts.php:
--------------------------------------------------------------------------------
1 |
22 | * The Google Fonts Developer API.
23 | *
24 | * 25 | * For more information about this service, see the API 26 | * Documentation 27 | *
28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_Webfonts extends Google_Service 32 | { 33 | 34 | 35 | public $webfonts; 36 | 37 | 38 | /** 39 | * Constructs the internal representation of the Webfonts service. 40 | * 41 | * @param Google_Client $client 42 | */ 43 | public function __construct(Google_Client $client) 44 | { 45 | parent::__construct($client); 46 | $this->servicePath = 'webfonts/v1/'; 47 | $this->version = 'v1'; 48 | $this->serviceName = 'webfonts'; 49 | 50 | $this->webfonts = new Google_Service_Webfonts_Webfonts_Resource( 51 | $this, 52 | $this->serviceName, 53 | 'webfonts', 54 | array( 55 | 'methods' => array( 56 | 'list' => array( 57 | 'path' => 'webfonts', 58 | 'httpMethod' => 'GET', 59 | 'parameters' => array( 60 | 'sort' => array( 61 | 'location' => 'query', 62 | 'type' => 'string', 63 | ), 64 | ), 65 | ), 66 | ) 67 | ) 68 | ); 69 | } 70 | } 71 | 72 | 73 | /** 74 | * The "webfonts" collection of methods. 75 | * Typical usage is: 76 | *
77 | * $webfontsService = new Google_Service_Webfonts(...);
78 | * $webfonts = $webfontsService->webfonts;
79 | *
80 | */
81 | class Google_Service_Webfonts_Webfonts_Resource extends Google_Service_Resource
82 | {
83 |
84 | /**
85 | * Retrieves the list of fonts currently served by the Google Fonts Developer
86 | * API (webfonts.listWebfonts)
87 | *
88 | * @param array $optParams Optional parameters.
89 | *
90 | * @opt_param string sort Enables sorting of the list
91 | * @return Google_Service_Webfonts_WebfontList
92 | */
93 | public function listWebfonts($optParams = array())
94 | {
95 | $params = array();
96 | $params = array_merge($params, $optParams);
97 | return $this->call('list', array($params), "Google_Service_Webfonts_WebfontList");
98 | }
99 | }
100 |
101 |
102 |
103 |
104 | class Google_Service_Webfonts_Webfont extends Google_Collection
105 | {
106 | protected $collection_key = 'variants';
107 | protected $internal_gapi_mappings = array(
108 | );
109 | public $category;
110 | public $family;
111 | public $files;
112 | public $kind;
113 | public $lastModified;
114 | public $subsets;
115 | public $variants;
116 | public $version;
117 |
118 |
119 | public function setCategory($category)
120 | {
121 | $this->category = $category;
122 | }
123 | public function getCategory()
124 | {
125 | return $this->category;
126 | }
127 | public function setFamily($family)
128 | {
129 | $this->family = $family;
130 | }
131 | public function getFamily()
132 | {
133 | return $this->family;
134 | }
135 | public function setFiles($files)
136 | {
137 | $this->files = $files;
138 | }
139 | public function getFiles()
140 | {
141 | return $this->files;
142 | }
143 | public function setKind($kind)
144 | {
145 | $this->kind = $kind;
146 | }
147 | public function getKind()
148 | {
149 | return $this->kind;
150 | }
151 | public function setLastModified($lastModified)
152 | {
153 | $this->lastModified = $lastModified;
154 | }
155 | public function getLastModified()
156 | {
157 | return $this->lastModified;
158 | }
159 | public function setSubsets($subsets)
160 | {
161 | $this->subsets = $subsets;
162 | }
163 | public function getSubsets()
164 | {
165 | return $this->subsets;
166 | }
167 | public function setVariants($variants)
168 | {
169 | $this->variants = $variants;
170 | }
171 | public function getVariants()
172 | {
173 | return $this->variants;
174 | }
175 | public function setVersion($version)
176 | {
177 | $this->version = $version;
178 | }
179 | public function getVersion()
180 | {
181 | return $this->version;
182 | }
183 | }
184 |
185 | class Google_Service_Webfonts_WebfontFiles extends Google_Model
186 | {
187 | }
188 |
189 | class Google_Service_Webfonts_WebfontList extends Google_Collection
190 | {
191 | protected $collection_key = 'items';
192 | protected $internal_gapi_mappings = array(
193 | );
194 | protected $itemsType = 'Google_Service_Webfonts_Webfont';
195 | protected $itemsDataType = 'array';
196 | public $kind;
197 |
198 |
199 | public function setItems($items)
200 | {
201 | $this->items = $items;
202 | }
203 | public function getItems()
204 | {
205 | return $this->items;
206 | }
207 | public function setKind($kind)
208 | {
209 | $this->kind = $kind;
210 | }
211 | public function getKind()
212 | {
213 | return $this->kind;
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Signer/Abstract.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | abstract class Google_Signer_Abstract
24 | {
25 | /**
26 | * Signs data, returns the signature as binary data.
27 | */
28 | abstract public function sign($data);
29 | }
30 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Signer/P12.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class Google_Signer_P12 extends Google_Signer_Abstract
30 | {
31 | // OpenSSL private key resource
32 | private $privateKey;
33 |
34 | // Creates a new signer from a .p12 file.
35 | public function __construct($p12, $password)
36 | {
37 | if (!function_exists('openssl_x509_read')) {
38 | throw new Google_Exception(
39 | 'The Google PHP API library needs the openssl PHP extension'
40 | );
41 | }
42 |
43 | // If the private key is provided directly, then this isn't in the p12
44 | // format. Different versions of openssl support different p12 formats
45 | // and the key from google wasn't being accepted by the version available
46 | // at the time.
47 | if (!$password && strpos($p12, "-----BEGIN RSA PRIVATE KEY-----") !== false) {
48 | $this->privateKey = openssl_pkey_get_private($p12);
49 | } else {
50 | // This throws on error
51 | $certs = array();
52 | if (!openssl_pkcs12_read($p12, $certs, $password)) {
53 | throw new Google_Auth_Exception(
54 | "Unable to parse the p12 file. " .
55 | "Is this a .p12 file? Is the password correct? OpenSSL error: " .
56 | openssl_error_string()
57 | );
58 | }
59 | // TODO(beaton): is this part of the contract for the openssl_pkcs12_read
60 | // method? What happens if there are multiple private keys? Do we care?
61 | if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) {
62 | throw new Google_Auth_Exception("No private key found in p12 file.");
63 | }
64 | $this->privateKey = openssl_pkey_get_private($certs['pkey']);
65 | }
66 |
67 | if (!$this->privateKey) {
68 | throw new Google_Auth_Exception("Unable to load private key");
69 | }
70 | }
71 |
72 | public function __destruct()
73 | {
74 | if ($this->privateKey) {
75 | openssl_pkey_free($this->privateKey);
76 | }
77 | }
78 |
79 | public function sign($data)
80 | {
81 | if (version_compare(PHP_VERSION, '5.3.0') < 0) {
82 | throw new Google_Auth_Exception(
83 | "PHP 5.3.0 or higher is required to use service accounts."
84 | );
85 | }
86 | $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
87 | if (!openssl_sign($data, $signature, $this->privateKey, $hash)) {
88 | throw new Google_Auth_Exception("Unable to sign data");
89 | }
90 | return $signature;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Task/Exception.php:
--------------------------------------------------------------------------------
1 | = 0x20) && ($ordinalValue <= 0x7F)):
68 | // characters U-00000000 - U-0000007F (same as ASCII)
69 | $ret ++;
70 | break;
71 | case (($ordinalValue & 0xE0) == 0xC0):
72 | // characters U-00000080 - U-000007FF, mask 110XXXXX
73 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
74 | $ret += 2;
75 | break;
76 | case (($ordinalValue & 0xF0) == 0xE0):
77 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX
78 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
79 | $ret += 3;
80 | break;
81 | case (($ordinalValue & 0xF8) == 0xF0):
82 | // characters U-00010000 - U-001FFFFF, mask 11110XXX
83 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
84 | $ret += 4;
85 | break;
86 | case (($ordinalValue & 0xFC) == 0xF8):
87 | // characters U-00200000 - U-03FFFFFF, mask 111110XX
88 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
89 | $ret += 5;
90 | break;
91 | case (($ordinalValue & 0xFE) == 0xFC):
92 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X
93 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
94 | $ret += 6;
95 | break;
96 | default:
97 | $ret ++;
98 | }
99 | }
100 | return $ret;
101 | }
102 |
103 | /**
104 | * Normalize all keys in an array to lower-case.
105 | * @param array $arr
106 | * @return array Normalized array.
107 | */
108 | public static function normalize($arr)
109 | {
110 | if (!is_array($arr)) {
111 | return array();
112 | }
113 |
114 | $normalized = array();
115 | foreach ($arr as $key => $val) {
116 | $normalized[strtolower($key)] = $val;
117 | }
118 | return $normalized;
119 | }
120 |
121 | /**
122 | * Convert a string to camelCase
123 | * @param string $value
124 | * @return string
125 | */
126 | public static function camelCase($value)
127 | {
128 | $value = ucwords(str_replace(array('-', '_'), ' ', $value));
129 | $value = str_replace(' ', '', $value);
130 | $value[0] = strtolower($value[0]);
131 | return $value;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Verifier/Abstract.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | abstract class Google_Verifier_Abstract
24 | {
25 | /**
26 | * Checks a signature, returns true if the signature is correct,
27 | * false otherwise.
28 | */
29 | abstract public function verify($data, $signature);
30 | }
31 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/Verifier/Pem.php:
--------------------------------------------------------------------------------
1 |
26 | */
27 | class Google_Verifier_Pem extends Google_Verifier_Abstract
28 | {
29 | private $publicKey;
30 |
31 | /**
32 | * Constructs a verifier from the supplied PEM-encoded certificate.
33 | *
34 | * $pem: a PEM encoded certificate (not a file).
35 | * @param $pem
36 | * @throws Google_Auth_Exception
37 | * @throws Google_Exception
38 | */
39 | public function __construct($pem)
40 | {
41 | if (!function_exists('openssl_x509_read')) {
42 | throw new Google_Exception('Google API PHP client needs the openssl PHP extension');
43 | }
44 | $this->publicKey = openssl_x509_read($pem);
45 | if (!$this->publicKey) {
46 | throw new Google_Auth_Exception("Unable to parse PEM: $pem");
47 | }
48 | }
49 |
50 | public function __destruct()
51 | {
52 | if ($this->publicKey) {
53 | openssl_x509_free($this->publicKey);
54 | }
55 | }
56 |
57 | /**
58 | * Verifies the signature on data.
59 | *
60 | * Returns true if the signature is valid, false otherwise.
61 | * @param $data
62 | * @param $signature
63 | * @throws Google_Auth_Exception
64 | * @return bool
65 | */
66 | public function verify($data, $signature)
67 | {
68 | $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
69 | $status = openssl_verify($data, $signature, $this->publicKey, $hash);
70 | if ($status === -1) {
71 | throw new Google_Auth_Exception('Signature verification error: ' . openssl_error_string());
72 | }
73 | return $status === 1;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/google-api-php-client/src/Google/autoload.php:
--------------------------------------------------------------------------------
1 | token = '';
31 |
32 | $this->memcacheHost = getenv('MEMCACHE_HOST') ? getenv('MEMCACHE_HOST') : null;
33 | $this->memcachePort = getenv('MEMCACHE_PORT') ? getenv('MEMCACHE_PORT') : null;
34 | }
35 |
36 | public function getClient()
37 | {
38 | $client = new Google_Client();
39 | $client->setDeveloperKey(self::KEY);
40 | if (strlen($this->token)) {
41 | $client->setAccessToken($this->token);
42 | }
43 | if (strlen($this->memcacheHost)) {
44 | $client->setClassConfig('Google_Cache_Memcache', 'host', $this->memcacheHost);
45 | $client->setClassConfig('Google_Cache_Memcache', 'port', $this->memcachePort);
46 | }
47 | return $client;
48 | }
49 |
50 | public function checkToken()
51 | {
52 | if (!strlen($this->token)) {
53 | $this->markTestSkipped('Test requires access token');
54 | return false;
55 | }
56 | return true;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/OAuthHelper.php:
--------------------------------------------------------------------------------
1 | setScopes(
21 | array(
22 | "https://www.googleapis.com/auth/plus.me",
23 | "https://www.googleapis.com/auth/urlshortener",
24 | "https://www.googleapis.com/auth/tasks",
25 | "https://www.googleapis.com/auth/adsense",
26 | "https://www.googleapis.com/auth/youtube"
27 | )
28 | );
29 | $client->setRedirectUri("urn:ietf:wg:oauth:2.0:oob");
30 | // Visit https://code.google.com/apis/console to
31 | // generate your oauth2_client_id, oauth2_client_secret, and to
32 | // register your oauth2_redirect_uri.
33 | $client->setClientId("");
34 | $client->setClientSecret("");
35 |
36 | $authUrl = $client->createAuthUrl();
37 |
38 | `open '$authUrl'`;
39 | echo "\nPlease enter the auth code:\n";
40 | $authCode = trim(fgets(STDIN));
41 |
42 | $accessToken = $client->authenticate($authCode);
43 |
44 | echo "\n", 'Add the following to BaseTest.php as the $token value:', "\n\n";
45 | echo $accessToken, "\n\n";
46 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/README:
--------------------------------------------------------------------------------
1 | These tests depend on PHPUnit, see
2 | http://www.phpunit.de/manual/current/en/installation.html for more instructions
3 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | checkToken()) {
28 | return;
29 | }
30 | $client = $this->getClient();
31 | $batch = new Google_Http_Batch($client);
32 | $this->plus = new Google_Service_Plus($client);
33 |
34 | $client->setUseBatch(true);
35 | $batch->add($this->plus->people->get('me'), 'key1');
36 | $batch->add($this->plus->people->get('me'), 'key2');
37 | $batch->add($this->plus->people->get('me'), 'key3');
38 |
39 | $result = $batch->execute();
40 | $this->assertTrue(isset($result['response-key1']));
41 | $this->assertTrue(isset($result['response-key2']));
42 | $this->assertTrue(isset($result['response-key3']));
43 | }
44 |
45 | public function testBatchRequest()
46 | {
47 | $client = $this->getClient();
48 | $batch = new Google_Http_Batch($client);
49 | $this->plus = new Google_Service_Plus($client);
50 |
51 | $client->setUseBatch(true);
52 | $batch->add($this->plus->people->get('+LarryPage'), 'key1');
53 | $batch->add($this->plus->people->get('+LarryPage'), 'key2');
54 | $batch->add($this->plus->people->get('+LarryPage'), 'key3');
55 |
56 | $result = $batch->execute();
57 | $this->assertTrue(isset($result['response-key1']));
58 | $this->assertTrue(isset($result['response-key2']));
59 | $this->assertTrue(isset($result['response-key3']));
60 | }
61 |
62 | public function testInvalidBatchRequest()
63 | {
64 | $client = $this->getClient();
65 | $batch = new Google_Http_Batch($client);
66 | $this->plus = new Google_Service_Plus($client);
67 |
68 | $client->setUseBatch(true);
69 | $batch->add($this->plus->people->get('123456789987654321'), 'key1');
70 | $batch->add($this->plus->people->get('+LarryPage'), 'key2');
71 |
72 | $result = $batch->execute();
73 | $this->assertTrue(isset($result['response-key2']));
74 | $this->assertInstanceOf(
75 | 'Google_Service_Exception',
76 | $result['response-key1']
77 | );
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/ApiMediaFileUploadTest.php:
--------------------------------------------------------------------------------
1 | getClient();
26 | $request = new Google_Http_Request('http://www.example.com', 'POST');
27 | $media = new Google_Http_MediaFileUpload(
28 | $client,
29 | $request,
30 | 'image/png',
31 | base64_decode('data:image/png;base64,a')
32 | );
33 |
34 | $this->assertEquals(0, $media->getProgress());
35 | $this->assertGreaterThan(0, strlen($request->getPostBody()));
36 | }
37 |
38 | public function testGetUploadType()
39 | {
40 | $client = $this->getClient();
41 | $request = new Google_Http_Request('http://www.example.com', 'POST');
42 |
43 | // Test resumable upload
44 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true);
45 | $params = array('mediaUpload' => array('value' => $media));
46 | $this->assertEquals('resumable', $media->getUploadType(null));
47 |
48 | // Test data *only* uploads
49 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', false);
50 | $this->assertEquals('media', $media->getUploadType(null));
51 |
52 | // Test multipart uploads
53 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', false);
54 | $this->assertEquals('multipart', $media->getUploadType(array('a' => 'b')));
55 | }
56 |
57 | public function testResultCode()
58 | {
59 | $client = $this->getClient();
60 | $request = new Google_Http_Request('http://www.example.com', 'POST');
61 |
62 | // Test resumable upload
63 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true);
64 | $this->assertEquals(null, $media->getHttpResultCode());
65 | }
66 |
67 | public function testProcess()
68 | {
69 | $client = $this->getClient();
70 | $data = 'foo';
71 |
72 | // Test data *only* uploads.
73 | $request = new Google_Http_Request('http://www.example.com', 'POST');
74 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false);
75 | $this->assertEquals($data, $request->getPostBody());
76 |
77 | // Test resumable (meta data) - we want to send the metadata, not the app data.
78 | $request = new Google_Http_Request('http://www.example.com', 'POST');
79 | $reqData = json_encode("hello");
80 | $request->setPostBody($reqData);
81 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, true);
82 | $this->assertEquals(json_decode($reqData), $request->getPostBody());
83 |
84 | // Test multipart - we are sending encoded meta data and post data
85 | $request = new Google_Http_Request('http://www.example.com', 'POST');
86 | $reqData = json_encode("hello");
87 | $request->setPostBody($reqData);
88 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false);
89 | $this->assertContains($reqData, $request->getPostBody());
90 | $this->assertContains(base64_encode($data), $request->getPostBody());
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/CacheTest.php:
--------------------------------------------------------------------------------
1 | getClient();
27 | $client->setClassConfig(
28 | 'Google_Cache_File',
29 | 'directory',
30 | $dir
31 | );
32 | $cache = new Google_Cache_File($client);
33 | $cache->set('foo', 'bar');
34 | $this->assertEquals($cache->get('foo'), 'bar');
35 |
36 | $this->getSetDelete($cache);
37 | }
38 |
39 | /**
40 | * @requires extension Memcache
41 | */
42 | public function testNull()
43 | {
44 | $client = $this->getClient();
45 | $cache = new Google_Cache_Null($client);
46 | $client->setCache($cache);
47 |
48 | $cache->set('foo', 'bar');
49 | $cache->delete('foo');
50 | $this->assertEquals(false, $cache->get('foo'));
51 |
52 | $cache->set('foo.1', 'bar.1');
53 | $this->assertEquals($cache->get('foo.1'), false);
54 |
55 | $cache->set('foo', 'baz');
56 | $this->assertEquals($cache->get('foo'), false);
57 |
58 | $cache->set('foo', null);
59 | $cache->delete('foo');
60 | $this->assertEquals($cache->get('foo'), false);
61 | }
62 |
63 | /**
64 | * @requires extension Memcache
65 | */
66 | public function testMemcache()
67 | {
68 | $client = $this->getClient();
69 | if (!$client->getClassConfig('Google_Cache_Memcache', 'host')) {
70 | $this->markTestSkipped('Test requires memcache host specified');
71 | }
72 |
73 | $cache = new Google_Cache_Memcache($client);
74 |
75 | $this->getSetDelete($cache);
76 | }
77 |
78 | /**
79 | * @requires extension APC
80 | */
81 | public function testAPC()
82 | {
83 | if (!ini_get('apc.enable_cli')) {
84 | $this->markTestSkipped('Test requires APC enabled for CLI');
85 | }
86 | $client = $this->getClient();
87 | $cache = new Google_Cache_Apc($client);
88 |
89 | $this->getSetDelete($cache);
90 | }
91 |
92 | public function getSetDelete($cache)
93 | {
94 | $cache->set('foo', 'bar');
95 | $cache->delete('foo');
96 | $this->assertEquals(false, $cache->get('foo'));
97 |
98 | $cache->set('foo.1', 'bar.1');
99 | $cache->delete('foo.1');
100 | $this->assertEquals($cache->get('foo.1'), false);
101 |
102 | $cache->set('foo', 'baz');
103 | $cache->delete('foo');
104 | $this->assertEquals($cache->get('foo'), false);
105 |
106 | $cache->set('foo', null);
107 | $cache->delete('foo');
108 | $this->assertEquals($cache->get('foo'), false);
109 |
110 | $obj = new stdClass();
111 | $obj->foo = 'bar';
112 | $cache->set('foo', $obj);
113 | $cache->delete('foo');
114 | $this->assertEquals($cache->get('foo'), false);
115 |
116 | $cache->set('foo.1', 'bar.1');
117 | $this->assertEquals($cache->get('foo.1'), 'bar.1');
118 |
119 | $cache->set('foo', 'baz');
120 | $this->assertEquals($cache->get('foo'), 'baz');
121 |
122 | $cache->set('foo', null);
123 | $this->assertEquals($cache->get('foo'), null);
124 |
125 | $cache->set('1/2/3', 'bar');
126 | $this->assertEquals($cache->get('1/2/3'), 'bar');
127 |
128 | $obj = new stdClass();
129 | $obj->foo = 'bar';
130 | $cache->set('foo', $obj);
131 | $this->assertEquals($cache->get('foo'), $obj);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/RequestTest.php:
--------------------------------------------------------------------------------
1 | setExpectedClass("Google_Client");
29 | $this->assertEquals(2, count($request->getQueryParams()));
30 | $request->setQueryParam("hi", "there");
31 | $this->assertEquals($url2, $request->getUrl());
32 | $this->assertEquals("Google_Client", $request->getExpectedClass());
33 |
34 | $urlPath = "/foo/bar";
35 | $request = new Google_Http_Request($urlPath);
36 | $this->assertEquals($urlPath, $request->getUrl());
37 | $request->setBaseComponent("http://example.com");
38 | $this->assertEquals("http://example.com" . $urlPath, $request->getUrl());
39 |
40 | $url3a = 'http://localhost:8080/foo/bar';
41 | $url3b = 'foo=a&foo=b&wowee=oh+my';
42 | $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there';
43 | $request = new Google_Http_Request($url3a."?".$url3b, "POST");
44 | $request->setQueryParam("hi", "there");
45 | $request->maybeMoveParametersToBody();
46 | $this->assertEquals($url3a, $request->getUrl());
47 | $this->assertEquals($url3c, $request->getPostBody());
48 |
49 | $url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there';
50 | $request = new Google_Http_Request($url);
51 | $this->assertEquals(2, count($request->getQueryParams()));
52 | $request->setQueryParam("hi", "there");
53 | $base = $request->getBaseComponent();
54 | $request->setBaseComponent($base . '/upload');
55 | $this->assertEquals($url4, $request->getUrl());
56 | }
57 |
58 | public function testGzipSupport()
59 | {
60 | $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my';
61 | $request = new Google_Http_Request($url);
62 | $request->enableGzip();
63 | $this->assertStringEndsWith(Google_Http_Request::GZIP_UA, $request->getUserAgent());
64 | $this->assertArrayHasKey('accept-encoding', $request->getRequestHeaders());
65 | $this->assertTrue($request->canGzip());
66 | $request->disableGzip();
67 | $this->assertStringEndsNotWith(Google_Http_Request::GZIP_UA, $request->getUserAgent());
68 | $this->assertArrayNotHasKey('accept-encoding', $request->getRequestHeaders());
69 | $this->assertFalse($request->canGzip());
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/RestTest.php:
--------------------------------------------------------------------------------
1 | rest = new Google_Http_REST();
28 | }
29 |
30 | public function testDecodeResponse()
31 | {
32 | $url = 'http://localhost';
33 | $client = $this->getClient();
34 | $response = new Google_Http_Request($url);
35 | $response->setResponseHttpCode(204);
36 | $decoded = $this->rest->decodeHttpResponse($response, $client);
37 | $this->assertEquals(null, $decoded);
38 |
39 |
40 | foreach (array(200, 201) as $code) {
41 | $headers = array('foo', 'bar');
42 | $response = new Google_Http_Request($url, 'GET', $headers);
43 | $response->setResponseBody('{"a": 1}');
44 |
45 | $response->setResponseHttpCode($code);
46 | $decoded = $this->rest->decodeHttpResponse($response, $client);
47 | $this->assertEquals(array("a" => 1), $decoded);
48 | }
49 |
50 | $response = new Google_Http_Request($url);
51 | $response->setResponseHttpCode(500);
52 |
53 | $error = "";
54 | try {
55 | $this->rest->decodeHttpResponse($response, $client);
56 | } catch (Exception $e) {
57 | $error = $e->getMessage();
58 |
59 | }
60 | $this->assertEquals(trim($error), "Error calling GET http://localhost: (500)");
61 | }
62 |
63 |
64 | public function testDecodeEmptyResponse()
65 | {
66 | $url = 'http://localhost';
67 |
68 | $response = new Google_Http_Request($url, 'GET', array());
69 | $response->setResponseBody('{}');
70 |
71 | $response->setResponseHttpCode(200);
72 | $decoded = $this->rest->decodeHttpResponse($response);
73 | $this->assertEquals(array(), $decoded);
74 | }
75 |
76 | public function testCreateRequestUri()
77 | {
78 | $basePath = "http://localhost";
79 | $restPath = "/plus/{u}";
80 |
81 | // Test Path
82 | $params = array();
83 | $params['u']['type'] = 'string';
84 | $params['u']['location'] = 'path';
85 | $params['u']['value'] = 'me';
86 | $value = $this->rest->createRequestUri($basePath, $restPath, $params);
87 | $this->assertEquals("http://localhost/plus/me", $value);
88 |
89 | // Test Query
90 | $params = array();
91 | $params['u']['type'] = 'string';
92 | $params['u']['location'] = 'query';
93 | $params['u']['value'] = 'me';
94 | $value = $this->rest->createRequestUri($basePath, '/plus', $params);
95 | $this->assertEquals("http://localhost/plus?u=me", $value);
96 |
97 | // Test Booleans
98 | $params = array();
99 | $params['u']['type'] = 'boolean';
100 | $params['u']['location'] = 'path';
101 | $params['u']['value'] = '1';
102 | $value = $this->rest->createRequestUri($basePath, $restPath, $params);
103 | $this->assertEquals("http://localhost/plus/true", $value);
104 |
105 | $params['u']['location'] = 'query';
106 | $value = $this->rest->createRequestUri($basePath, '/plus', $params);
107 | $this->assertEquals("http://localhost/plus?u=true", $value);
108 |
109 | // Test encoding
110 | $params = array();
111 | $params['u']['type'] = 'string';
112 | $params['u']['location'] = 'query';
113 | $params['u']['value'] = '@me/';
114 | $value = $this->rest->createRequestUri($basePath, '/plus', $params);
115 | $this->assertEquals("http://localhost/plus?u=%40me%2F", $value);
116 | }
117 |
118 | /**
119 | * @expectedException Google_Service_Exception
120 | */
121 | public function testBadErrorFormatting()
122 | {
123 | $request = new Google_Http_Request("/a/b");
124 | $request->setResponseHttpCode(500);
125 | $request->setResponseBody(
126 | '{
127 | "error": {
128 | "code": 500,
129 | "message": null
130 | }
131 | }'
132 | );
133 | Google_Http_Rest::decodeHttpResponse($request);
134 | }
135 |
136 | /**
137 | * @expectedException Google_Service_Exception
138 | */
139 | public function tesProperErrorFormatting()
140 | {
141 | $request = new Google_Http_Request("/a/b");
142 | $request->setResponseHttpCode(401);
143 | $request->setResponseBody(
144 | '{
145 | error: {
146 | errors: [
147 | {
148 | "domain": "global",
149 | "reason": "authError",
150 | "message": "Invalid Credentials",
151 | "locationType": "header",
152 | "location": "Authorization",
153 | }
154 | ],
155 | "code": 401,
156 | "message": "Invalid Credentials"
157 | }'
158 | );
159 | Google_Http_Rest::decodeHttpResponse($request);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/ServiceTest.php:
--------------------------------------------------------------------------------
1 | mapTypes(
41 | array(
42 | 'name' => 'asdf',
43 | 'gender' => 'z',
44 | )
45 | );
46 | $this->assertEquals('asdf', $model->name);
47 | $this->assertEquals('z', $model->gender);
48 | $model->mapTypes(
49 | array(
50 | '__infoType' => 'Google_Model',
51 | '__infoDataType' => 'map',
52 | 'info' => array (
53 | 'location' => 'mars',
54 | 'timezone' => 'mst',
55 | ),
56 | 'name' => 'asdf',
57 | 'gender' => 'z',
58 | )
59 | );
60 | $this->assertEquals('asdf', $model->name);
61 | $this->assertEquals('z', $model->gender);
62 |
63 | $this->assertEquals(false, $model->isAssociativeArray(""));
64 | $this->assertEquals(false, $model->isAssociativeArray(false));
65 | $this->assertEquals(false, $model->isAssociativeArray(null));
66 | $this->assertEquals(false, $model->isAssociativeArray(array()));
67 | $this->assertEquals(false, $model->isAssociativeArray(array(1, 2)));
68 | $this->assertEquals(false, $model->isAssociativeArray(array(1 => 2)));
69 |
70 | $this->assertEquals(true, $model->isAssociativeArray(array('test' => 'a')));
71 | $this->assertEquals(true, $model->isAssociativeArray(array("a", "b" => 2)));
72 | }
73 |
74 | /**
75 | * @dataProvider serviceProvider
76 | */
77 | public function testIncludes($class)
78 | {
79 | $this->assertTrue(
80 | class_exists($class),
81 | sprintf('Failed asserting class %s exists.', $class)
82 | );
83 | }
84 |
85 | public function serviceProvider()
86 | {
87 | $classes = array();
88 | $path = dirname(dirname(dirname(__FILE__))) . '/src/Google/Service';
89 | foreach (glob($path . "/*.php") as $file) {
90 | $classes[] = array('Google_Service_' . basename($file, '.php'));
91 | }
92 |
93 | return $classes;
94 | }
95 |
96 | public function testStrLen()
97 | {
98 | $this->assertEquals(0, Google_Utils::getStrLen(null));
99 | $this->assertEquals(0, Google_Utils::getStrLen(false));
100 | $this->assertEquals(0, Google_Utils::getStrLen(""));
101 |
102 | $this->assertEquals(1, Google_Utils::getStrLen(" "));
103 | $this->assertEquals(2, Google_Utils::getStrLen(" 1"));
104 | $this->assertEquals(7, Google_Utils::getStrLen("0a\\n\n\r\n"));
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/ComputeEngineAuthTest.php:
--------------------------------------------------------------------------------
1 | "ACCESS_TOKEN",
31 | 'expires_in' => "12345"
32 | )
33 | );
34 | $response = $this->getMock("Google_Http_Request", array(), array(''));
35 | $response->expects($this->any())
36 | ->method('getResponseHttpCode')
37 | ->will($this->returnValue(200));
38 | $response->expects($this->any())
39 | ->method('getResponseBody')
40 | ->will($this->returnValue($response_data));
41 | $io = $this->getMock("Google_IO_Stream", array(), array($client));
42 | $client->setIo($io);$io->expects($this->any())
43 | ->method('makeRequest')
44 | ->will(
45 | $this->returnCallback(
46 | function ($request) use ($response) {
47 | return $response;
48 | }
49 | )
50 | );
51 |
52 | /* Run method */
53 | $oauth = new Google_Auth_ComputeEngine($client);
54 | $oauth->acquireAccessToken();
55 | $token = json_decode($oauth->getAccessToken(), true);
56 |
57 | /* Check results */
58 | $this->assertEquals($token['access_token'], "ACCESS_TOKEN");
59 | $this->assertEquals($token['expires_in'], "12345");
60 | $this->assertTrue($token['created'] > 0);
61 | }
62 |
63 | public function testSign()
64 | {
65 | $client = new Google_Client();
66 | $oauth = new Google_Auth_ComputeEngine($client);
67 |
68 | /* Load mock access token */
69 | $oauth->setAccessToken(json_encode(
70 | array(
71 | 'access_token' => "ACCESS_TOKEN",
72 | 'expires_in' => "12345"
73 | )
74 | ));
75 |
76 | /* Sign a URL and verify auth header is correctly set */
77 | $req = new Google_Http_Request('http://localhost');
78 | $req = $oauth->sign($req);
79 | $auth = $req->getRequestHeader('authorization');
80 | $this->assertEquals('Bearer ACCESS_TOKEN', $auth);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/cacert.json:
--------------------------------------------------------------------------------
1 | {"a": "-----BEGIN CERTIFICATE-----\nMIICrDCCAlagAwIBAgIJAIhhwVyFHrVfMA0GCSqGSIb3DQEBBQUAMG8xCzAJBgNV\nBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX\naWRnaXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG\n9w0BCQEWAWMwHhcNMTIwMjE5MDExMzQxWhcNMTUwMjE4MDExMzQxWjBvMQswCQYD\nVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQg\nV2lkZ2l0cyBQdHkgTHRkMQowCAYDVQQLEwFhMQowCAYDVQQDEwFiMRAwDgYJKoZI\nhvcNAQkBFgFjMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM4Aozh3TMZYcPx7MHln\nD8MtyVUjzo6OdT32JwRHzHHNMMm88lNVfLYIT9C/jgXlDqG0h5wSClMvTQbdihNd\nFOkCAwEAAaOB1DCB0TAdBgNVHQ4EFgQUv0Ahb7HD9TLfdtLeaatjFj91NqYwgaEG\nA1UdIwSBmTCBloAUv0Ahb7HD9TLfdtLeaatjFj91Nqahc6RxMG8xCzAJBgNVBAYT\nAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRn\naXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG9w0B\nCQEWAWOCCQCIYcFchR61XzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EA\nKAbxbWHsaVPnYc0YqG/Pn4HbcI1+xnVQSt3hdzq+yC0lP9H7hBMCVSykhhBkZ5XQ\nHA2t6LHuYsjcCO+LBX/4fA==\n-----END CERTIFICATE-----"}
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/cacert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICrDCCAlagAwIBAgIJAIhhwVyFHrVfMA0GCSqGSIb3DQEBBQUAMG8xCzAJBgNV
3 | BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
4 | aWRnaXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG
5 | 9w0BCQEWAWMwHhcNMTIwMjE5MDExMzQxWhcNMTUwMjE4MDExMzQxWjBvMQswCQYD
6 | VQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQg
7 | V2lkZ2l0cyBQdHkgTHRkMQowCAYDVQQLEwFhMQowCAYDVQQDEwFiMRAwDgYJKoZI
8 | hvcNAQkBFgFjMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM4Aozh3TMZYcPx7MHln
9 | D8MtyVUjzo6OdT32JwRHzHHNMMm88lNVfLYIT9C/jgXlDqG0h5wSClMvTQbdihNd
10 | FOkCAwEAAaOB1DCB0TAdBgNVHQ4EFgQUv0Ahb7HD9TLfdtLeaatjFj91NqYwgaEG
11 | A1UdIwSBmTCBloAUv0Ahb7HD9TLfdtLeaatjFj91Nqahc6RxMG8xCzAJBgNVBAYT
12 | AkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRn
13 | aXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG9w0B
14 | CQEWAWOCCQCIYcFchR61XzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EA
15 | KAbxbWHsaVPnYc0YqG/Pn4HbcI1+xnVQSt3hdzq+yC0lP9H7hBMCVSykhhBkZ5XQ
16 | HA2t6LHuYsjcCO+LBX/4fA==
17 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/cert.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitwasankar/Save-To-Google-Drive/7d1c420aef5b61267b0d8dfa3d247acdd43fdc04/google-api-php-client/tests/general/testdata/cert.p12
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/privkey.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIBOwIBAAJBAM4Aozh3TMZYcPx7MHlnD8MtyVUjzo6OdT32JwRHzHHNMMm88lNV
3 | fLYIT9C/jgXlDqG0h5wSClMvTQbdihNdFOkCAwEAAQJBAJuMo7KpcpF6iqY7Jtkk
4 | 1yQb2KCvTvMZ4rGMwt1akaeDW2noyqCeO675gFBtlizgcRsybealQVQgGX4E5VqF
5 | UJkCIQDzJZZi2jloDXcyyy2rEa4mj4RnrnIYsDMJ55XMWJ9c9wIhANjkY97FSRX3
6 | WSdRFqXd3Pc4URUho+rCcPibafMOwAUfAiAa58ngXm2DyhmqkTkYePhgY/kuz+ro
7 | OHctXWcCGbxouQIgLC5qAakieC0Ipi+oc2U8a8e3DJzrrRiqtpnB/VcV2nUCIQC2
8 | DXrpyt6jjVIzs4jI5Cl3QGLL6TZ8FqpyonU/1ARuhA==
9 | -----END RSA PRIVATE KEY-----
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/test.ini:
--------------------------------------------------------------------------------
1 | ; Test.ini file
2 | application_name = My Test application
3 | auth_class = Google_Auth_OAuth2
4 | [classes]
5 | Google_Auth_OAuth2[client_id] = 12345.apps.googleusercontent.com
6 | Google_Auth_OAuth2[client_secret] = gjfiwnGinpena3
7 | Google_Auth_OAuth2[redirect_uri] = http://example.com
--------------------------------------------------------------------------------
/google-api-php-client/tests/general/testdata/test_public_key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDQjCCAiqgAwIBAgIJAMJ1Z12ZdGgLMA0GCSqGSIb3DQEBBQUAMB8xHTAbBgNV
3 | BAMTFHRlc3Qtc2VydmljZS1hY2NvdW50MB4XDTExMDgyMzIwNTczNFoXDTIxMDgy
4 | MDIwNTczNFowHzEdMBsGA1UEAxMUdGVzdC1zZXJ2aWNlLWFjY291bnQwggEiMA0G
5 | CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDpbFTjUXd02HFluI2G0kGKp1J5K2F8
6 | cYr7hKXHcsmKo6S/5g8AEYnnV1fEbiopoGt7UWV4T0LA99K0gqQ7QmvZKvFHXlgR
7 | XJH1aO+ZipVs3ycZOcjBMcw4hspFSi4IyQta64gASFUT5NaxRVGhzAuPlzH09dZQ
8 | RJ0NL54HccGNzEDaLx5usB8t2aRHbE4zRWJlNIsjgWnfVoiXwOv5oRhyfFMIaTu1
9 | eIp3XP1QAv5cuYS2U4ZJ+J7Gzg6E7t4PWqK7rGjnc5BJsVIoiL77K/xKUWABNgHz
10 | b6JuiEp3LX9f2H5+CKo/IJFWoyIYWdZiu69LZivife9sTXmDnOcZkisRAgMBAAGj
11 | gYAwfjAdBgNVHQ4EFgQU0RkXlevVO2zuTFP/ksFUbNkpm+kwTwYDVR0jBEgwRoAU
12 | 0RkXlevVO2zuTFP/ksFUbNkpm+mhI6QhMB8xHTAbBgNVBAMTFHRlc3Qtc2Vydmlj
13 | ZS1hY2NvdW50ggkAwnVnXZl0aAswDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUF
14 | AAOCAQEAT+3VKautn+uV7ZQWbfx6xrGaDZ5wVK9FWOTVKsjdXyp11jtoVkDONLz5
15 | 3J7wgppZWabPargIZUHe9/P6j7QTgNV2na2thGHtVRIRyDECnVrvhCn/IDpMeJjj
16 | IAuysmSITHGEwb4AvRC5HdqfWzBqAvRhjJ2crcHZpx5/KkYZgJz9ylGJCynxpbHU
17 | 1aRu4qpkQNB4t4z5EzNOSLkFw9vEtm0hNX76CsNJFd0XDEKDQI2Lsc0WfDzQ1ZQH
18 | UVzIoTmQDkYGylQOBVyxZoGI6fuSo8c2I1BKvsdBGhSPjePNvaKUbmLSwUsranhX
19 | 2Y1kn7xbDTUHymZ0+g5rDM9kWmhZfg==
20 | -----END CERTIFICATE-----
21 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/pagespeed/PageSpeedTest.php:
--------------------------------------------------------------------------------
1 | service = new Google_Service_Pagespeedonline($this->getClient());
25 | }
26 |
27 | public function testPageSpeed()
28 | {
29 | $this->checkToken();
30 | $psapi = $this->service->pagespeedapi;
31 | $result = $psapi->runpagespeed('http://code.google.com');
32 | $this->assertArrayHasKey('kind', $result);
33 | $this->assertArrayHasKey('id', $result);
34 | $this->assertArrayHasKey('responseCode', $result);
35 | $this->assertArrayHasKey('title', $result);
36 | $this->assertArrayHasKey('score', $result->ruleGroups['SPEED']);
37 | $this->assertInstanceOf('Google_Service_Pagespeedonline_ResultPageStats', $result->pageStats);
38 | $this->assertArrayHasKey('minor', $result['version']);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/plus/PlusTest.php:
--------------------------------------------------------------------------------
1 | plus = new Google_Service_Plus($this->getClient());
26 | }
27 |
28 | public function testGetPerson()
29 | {
30 | $this->checkToken();
31 | $person = $this->plus->people->get("118051310819094153327");
32 | $this->assertArrayHasKey('kind', $person);
33 | $this->assertArrayHasKey('displayName', $person);
34 | $this->assertArrayHasKey('gender', $person);
35 | $this->assertArrayHasKey('id', $person);
36 | }
37 |
38 | public function testListActivities()
39 | {
40 | $this->checkToken();
41 | $activities = $this->plus->activities
42 | ->listActivities("118051310819094153327", "public");
43 |
44 | $this->assertArrayHasKey('kind', $activities);
45 | $this->assertGreaterThan(0, count($activities));
46 |
47 | // Test a variety of access methods.
48 | $this->assertItem($activities['items'][0]);
49 | $this->assertItem($activities[0]);
50 | foreach ($activities as $item) {
51 | $this->assertItem($item);
52 | break;
53 | }
54 |
55 | // Test deeper type transformations
56 | $this->assertGreaterThan(0, strlen($activities[0]->actor->displayName));
57 | }
58 |
59 | public function assertItem($item)
60 | {
61 | // assertArrayHasKey uses array_key_exists, which is not great:
62 | // it doesn't understand SPL ArrayAccess
63 | $this->assertTrue(isset($item['actor']));
64 | $this->assertInstanceOf('Google_Service_Plus_ActivityActor', $item->actor);
65 | $this->assertTrue(isset($item['actor']['displayName']));
66 | $this->assertTrue(isset($item['actor']->url));
67 | $this->assertTrue(isset($item['object']));
68 | $this->assertTrue(isset($item['access']));
69 | $this->assertTrue(isset($item['provider']));
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/tasks/TasksTest.php:
--------------------------------------------------------------------------------
1 | taskService = new Google_Service_Tasks($this->getClient());
27 | }
28 |
29 | public function testInsertTask()
30 | {
31 | if (!$this->checkToken()) {
32 | return;
33 | }
34 | $list = $this->createTaskList('List: ' . __METHOD__);
35 | $task = $this->createTask('Task: '.__METHOD__, $list->id);
36 | $this->assertIsTask($task);
37 | }
38 |
39 | /**
40 | * @depends testInsertTask
41 | */
42 | public function testGetTask()
43 | {
44 | $tasks = $this->taskService->tasks;
45 | $list = $this->createTaskList('List: ' . __METHOD__);
46 | $task = $this->createTask('Task: '. __METHOD__, $list['id']);
47 |
48 | $task = $tasks->get($list['id'], $task['id']);
49 | $this->assertIsTask($task);
50 | }
51 |
52 | /**
53 | * @depends testInsertTask
54 | */
55 | public function testListTask()
56 | {
57 | $tasks = $this->taskService->tasks;
58 | $list = $this->createTaskList('List: ' . __METHOD__);
59 |
60 | for ($i=0; $i<4; $i++) {
61 | $this->createTask("Task: $i ".__METHOD__, $list['id']);
62 | }
63 |
64 | $tasksArray = $tasks->listTasks($list['id']);
65 | $this->assertTrue(sizeof($tasksArray) > 1);
66 | foreach ($tasksArray['items'] as $task) {
67 | $this->assertIsTask($task);
68 | }
69 | }
70 |
71 | private function createTaskList($name)
72 | {
73 | $list = new Google_Service_Tasks_TaskList();
74 | $list->title = $name;
75 | return $this->taskService->tasklists->insert($list);
76 | }
77 |
78 | private function createTask($title, $listId)
79 | {
80 | $tasks = $this->taskService->tasks;
81 | $task = new Google_Service_Tasks_Task();
82 | $task->title = $title;
83 | return $tasks->insert($listId, $task);
84 | }
85 |
86 | private function assertIsTask($task)
87 | {
88 | $this->assertArrayHasKey('title', $task);
89 | $this->assertArrayHasKey('kind', $task);
90 | $this->assertArrayHasKey('id', $task);
91 | $this->assertArrayHasKey('position', $task);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/urlshortener/UrlShortenerTests.php:
--------------------------------------------------------------------------------
1 | service = new Google_Service_Urlshortener($this->getClient());
27 | }
28 |
29 | public function testUrlShort()
30 | {
31 | $url = new Google_Service_Urlshortener_Url();
32 | $url->longUrl = "http://google.com";
33 |
34 | $shortUrl = $this->service->url->insert($url);
35 | $this->assertEquals('urlshortener#url', $shortUrl['kind']);
36 | $this->assertEquals('http://google.com/', $shortUrl['longUrl']);
37 | }
38 |
39 | public function testEmptyJsonResponse()
40 | {
41 | $optParams = array('fields' => '');
42 | $resp = $this->service->url->get('http://goo.gl/KkHq8', $optParams);
43 |
44 | $this->assertEquals("", $resp->longUrl);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/google-api-php-client/tests/youtube/YouTubeTest.php:
--------------------------------------------------------------------------------
1 | youtube = new Google_Service_YouTube($this->getClient());
26 | }
27 |
28 | public function testMissingFieldsAreNull()
29 | {
30 | if (!$this->checkToken()) {
31 | return;
32 | }
33 |
34 | $parts = "id,brandingSettings";
35 | $opts = array("mine" => true);
36 | $channels = $this->youtube->channels->listChannels($parts, $opts);
37 |
38 | $newChannel = new Google_Service_YouTube_Channel();
39 | $newChannel->setId($channels[0]->getId());
40 | $newChannel->setBrandingSettings($channels[0]->getBrandingSettings());
41 |
42 | $simpleOriginal = $channels[0]->toSimpleObject();
43 | $simpleNew = $newChannel->toSimpleObject();
44 |
45 | $this->assertObjectHasAttribute('etag', $simpleOriginal);
46 | $this->assertObjectNotHasAttribute('etag', $simpleNew);
47 |
48 | $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails();
49 | $owner_details->setTimeLinked("123456789");
50 | $o_channel = new Google_Service_YouTube_Channel();
51 | $o_channel->setContentOwnerDetails($owner_details);
52 | $simpleManual = $o_channel->toSimpleObject();
53 | $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails);
54 | $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails);
55 |
56 | $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails();
57 | $owner_details->timeLinked = "123456789";
58 | $o_channel = new Google_Service_YouTube_Channel();
59 | $o_channel->setContentOwnerDetails($owner_details);
60 | $simpleManual = $o_channel->toSimpleObject();
61 |
62 | $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails);
63 | $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails);
64 |
65 | $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails();
66 | $owner_details['timeLinked'] = "123456789";
67 | $o_channel = new Google_Service_YouTube_Channel();
68 | $o_channel->setContentOwnerDetails($owner_details);
69 | $simpleManual = $o_channel->toSimpleObject();
70 |
71 | $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails);
72 | $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails);
73 |
74 | $ping = new Google_Service_YouTube_ChannelConversionPing();
75 | $ping->setContext("hello");
76 | $pings = new Google_Service_YouTube_ChannelConversionPings();
77 | $pings->setPings(array($ping));
78 | $simplePings = $pings->toSimpleObject();
79 | $this->assertObjectHasAttribute('context', $simplePings->pings[0]);
80 | $this->assertObjectNotHasAttribute('conversionUrl', $simplePings->pings[0]);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |