From 145ac46ad71f0061be397b89d70dad96ceea2e41 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Mon, 9 Jul 2018 16:27:19 -0700 Subject: [PATCH 01/17] Finish basic job samples and basic company samples --- jobs/cjd_sample/cjd_sample.php | 35 ++ jobs/cjd_sample/composer.json | 16 +- jobs/cjd_sample/composer.lock | 585 ++++++++++++------ jobs/cjd_sample/phpunit.xml.dist | 34 + jobs/cjd_sample/quickstart.php | 6 +- jobs/cjd_sample/src/basic_company_sample.php | 178 ++++++ jobs/cjd_sample/src/basic_job_sample.php | 198 ++++++ jobs/cjd_sample/src/job_service_connector.php | 42 ++ .../test/BasicCompanySampleTest.php | 42 ++ jobs/cjd_sample/test/BasicJobSampleTest.php | 42 ++ 10 files changed, 977 insertions(+), 201 deletions(-) create mode 100644 jobs/cjd_sample/cjd_sample.php create mode 100644 jobs/cjd_sample/phpunit.xml.dist create mode 100644 jobs/cjd_sample/src/basic_company_sample.php create mode 100644 jobs/cjd_sample/src/basic_job_sample.php create mode 100644 jobs/cjd_sample/src/job_service_connector.php create mode 100644 jobs/cjd_sample/test/BasicCompanySampleTest.php create mode 100644 jobs/cjd_sample/test/BasicJobSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php new file mode 100644 index 0000000000..efc7a45707 --- /dev/null +++ b/jobs/cjd_sample/cjd_sample.php @@ -0,0 +1,35 @@ +add(new BasicCompanySample()); +$application->add(new BasicJobSample()); + + +// for testing +if (getenv('PHPUNIT_TESTS') === '1') { + return $application; +} + +$application->run(); \ No newline at end of file diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index d203050d00..2b41203ddc 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -1,10 +1,20 @@ { "require": { "google/apiclient": "^2.1", - "symfony/console": " ^3.0", - "symfony/event-dispatcher": "^3.3" + "google/apiclient-services": "^0.64", + "symfony/console": " ^3.0" }, "require-dev": { - "phpunit/phpunit": "~4" + "phpunit/phpunit": "~5.0" + }, + "autoload": { + "psr-4": { + "Google\\Cloud\\Samples\\Language\\": "src/" + }, + "files": [ + "src/basic_job_sample.php", + "src/basic_company_sample.php", + "src/job_service_connector.php" + ] } } diff --git a/jobs/cjd_sample/composer.lock b/jobs/cjd_sample/composer.lock index 0ac29b0cc6..c830606ae3 100644 --- a/jobs/cjd_sample/composer.lock +++ b/jobs/cjd_sample/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "72055f6791350548d0b745742b3c4ca2", + "content-hash": "918a52f634141c37993aabe931e2c0e2", "packages": [ { "name": "firebase/php-jwt", @@ -54,21 +54,21 @@ }, { "name": "google/apiclient", - "version": "v2.2.1", + "version": "v2.2.2", "source": { "type": "git", "url": "https://github.com/google/google-api-php-client.git", - "reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2" + "reference": "4e0fd83510e579043e10e565528b323b7c2b3c81" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/google/google-api-php-client/zipball/b69b8ac4bf6501793c389d4e013a79d09c85c5f2", - "reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2", + "url": "https://api.github.com/repos/google/google-api-php-client/zipball/4e0fd83510e579043e10e565528b323b7c2b3c81", + "reference": "4e0fd83510e579043e10e565528b323b7c2b3c81", "shasum": "" }, "require": { "firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0", - "google/apiclient-services": "~0.64", + "google/apiclient-services": "~0.13", "google/auth": "^1.0", "guzzlehttp/guzzle": "~5.3.1|~6.0", "guzzlehttp/psr7": "^1.2", @@ -78,7 +78,7 @@ }, "require-dev": { "cache/filesystem-adapter": "^0.3.2", - "phpunit/phpunit": "~4", + "phpunit/phpunit": "~4.8.36", "squizlabs/php_codesniffer": "~2.3", "symfony/css-selector": "~2.1", "symfony/dom-crawler": "~2.1" @@ -109,7 +109,7 @@ "keywords": [ "google" ], - "time": "2017-11-03T01:19:53+00:00" + "time": "2018-06-20T15:52:20+00:00" }, { "name": "google/apiclient-services", @@ -146,26 +146,26 @@ "keywords": [ "google" ], - "time": "2018-01-22T00:23:18+00:00" + "time": "2018-06-30T00:22:51+00:00" }, { "name": "google/auth", - "version": "v1.2.1", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/google/google-auth-library-php.git", - "reference": "da0062d279c9459350808a4fb63dbc08b90d6b90" + "reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/google/google-auth-library-php/zipball/da0062d279c9459350808a4fb63dbc08b90d6b90", - "reference": "da0062d279c9459350808a4fb63dbc08b90d6b90", + "url": "https://api.github.com/repos/google/google-auth-library-php/zipball/8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71", + "reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71", "shasum": "" }, "require": { "firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0", "guzzlehttp/guzzle": "~5.3.1|~6.0", - "guzzlehttp/psr7": "~1.2", + "guzzlehttp/psr7": "^1.2", "php": ">=5.4", "psr/cache": "^1.0", "psr/http-message": "^1.0" @@ -193,20 +193,20 @@ "google", "oauth2" ], - "time": "2018-01-24T18:28:42+00:00" + "time": "2018-04-06T19:26:30+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "6.3.0", + "version": "6.3.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", - "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", "shasum": "" }, "require": { @@ -216,7 +216,7 @@ }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^4.0 || ^5.0", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "psr/log": "^1.0" }, "suggest": { @@ -225,7 +225,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.2-dev" + "dev-master": "6.3-dev" } }, "autoload": { @@ -258,7 +258,7 @@ "rest", "web service" ], - "time": "2017-06-22T18:50:49+00:00" + "time": "2018-04-22T15:46:56+00:00" }, { "name": "guzzlehttp/promises", @@ -456,16 +456,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "2.0.9", + "version": "2.0.11", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "c9a3fe35e20eb6eeaca716d6a23cde03f52d1558" + "reference": "7053f06f91b3de78e143d430e55a8f7889efc08b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/c9a3fe35e20eb6eeaca716d6a23cde03f52d1558", - "reference": "c9a3fe35e20eb6eeaca716d6a23cde03f52d1558", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/7053f06f91b3de78e143d430e55a8f7889efc08b", + "reference": "7053f06f91b3de78e143d430e55a8f7889efc08b", "shasum": "" }, "require": { @@ -473,7 +473,7 @@ }, "require-dev": { "phing/phing": "~2.7", - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^4.8.35|^5.7|^6.0", "sami/sami": "~2.0", "squizlabs/php_codesniffer": "~2.0" }, @@ -544,7 +544,7 @@ "x.509", "x509" ], - "time": "2017-11-29T06:38:08+00:00" + "time": "2018-04-15T16:55:05+00:00" }, { "name": "psr/cache", @@ -691,16 +691,16 @@ }, { "name": "symfony/console", - "version": "v3.4.3", + "version": "v3.4.12", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "8394c8ef121949e8f858f13bc1e34f05169e4e7d" + "reference": "1b97071a26d028c9bd4588264e101e14f6e7cd00" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/8394c8ef121949e8f858f13bc1e34f05169e4e7d", - "reference": "8394c8ef121949e8f858f13bc1e34f05169e4e7d", + "url": "https://api.github.com/repos/symfony/console/zipball/1b97071a26d028c9bd4588264e101e14f6e7cd00", + "reference": "1b97071a26d028c9bd4588264e101e14f6e7cd00", "shasum": "" }, "require": { @@ -721,7 +721,7 @@ "symfony/process": "~3.3|~4.0" }, "suggest": { - "psr/log": "For using the console logger", + "psr/log-implementation": "For using the console logger", "symfony/event-dispatcher": "", "symfony/lock": "", "symfony/process": "" @@ -756,20 +756,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com/", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-05-23T05:02:55+00:00" }, { "name": "symfony/debug", - "version": "v3.4.3", + "version": "v3.4.12", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "603b95dda8b00020e4e6e60dc906e7b715b1c245" + "reference": "47e6788c5b151cf0cfdf3329116bf33800632d75" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/603b95dda8b00020e4e6e60dc906e7b715b1c245", - "reference": "603b95dda8b00020e4e6e60dc906e7b715b1c245", + "url": "https://api.github.com/repos/symfony/debug/zipball/47e6788c5b151cf0cfdf3329116bf33800632d75", + "reference": "47e6788c5b151cf0cfdf3329116bf33800632d75", "shasum": "" }, "require": { @@ -812,83 +812,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com/", - "time": "2018-01-03T17:14:19+00:00" - }, - { - "name": "symfony/event-dispatcher", - "version": "v3.4.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "26b87b6bca8f8f797331a30b76fdae5342dc26ca" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/26b87b6bca8f8f797331a30b76fdae5342dc26ca", - "reference": "26b87b6bca8f8f797331a30b76fdae5342dc26ca", - "shasum": "" - }, - "require": { - "php": "^5.5.9|>=7.0.8" - }, - "conflict": { - "symfony/dependency-injection": "<3.3" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~2.8|~3.0|~4.0", - "symfony/dependency-injection": "~3.3|~4.0", - "symfony/expression-language": "~2.8|~3.0|~4.0", - "symfony/stopwatch": "~2.8|~3.0|~4.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony EventDispatcher Component", - "homepage": "https://symfony.com/", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-06-25T11:10:40+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.6.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296" + "reference": "3296adf6a6454a050679cde90f95350ad604b171" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", - "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", "shasum": "" }, "require": { @@ -900,7 +837,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -934,7 +871,7 @@ "portable", "shim" ], - "time": "2017-10-11T12:05:26+00:00" + "time": "2018-04-26T10:06:28+00:00" } ], "packages-dev": [ @@ -992,6 +929,51 @@ ], "time": "2015-06-14T21:17:01+00:00" }, + { + "name": "myclabs/deep-copy", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2017-10-19T19:58:43+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -1048,29 +1030,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.3.2", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bf329f6c1aadea3299f08ee804682b7c45b326a2", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0", + "php": "^7.0", "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -1089,7 +1077,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-10T14:09:06+00:00" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1140,28 +1128,28 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.3", + "version": "1.7.6", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" + "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { @@ -1199,43 +1187,44 @@ "spy", "stub" ], - "time": "2017-11-24T13:59:53+00:00" + "time": "2018-04-18T13:57:24+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "2.2.4", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", "shasum": "" }, "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "^1.3.2", - "sebastian/version": "~1.0" + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "^1.0 || ^2.0" }, "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" }, "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" + "ext-xdebug": "^2.5.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2.x-dev" + "dev-master": "4.0.x-dev" } }, "autoload": { @@ -1261,7 +1250,7 @@ "testing", "xunit" ], - "time": "2015-10-06T15:47:00+00:00" + "time": "2017-04-02T07:44:40+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1402,29 +1391,29 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.12", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" + "reference": "791198a2c6254db10131eecfe8c06670700904db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.2.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1447,20 +1436,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-12-04T08:55:13+00:00" + "time": "2017-11-27T05:48:46+00:00" }, { "name": "phpunit/phpunit", - "version": "4.8.36", + "version": "5.5.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" + "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6e88e56c912133de6e99b87728cca7ed70c5f5", + "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5", "shasum": "" }, "require": { @@ -1469,21 +1458,27 @@ "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", - "php": ">=5.3.3", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", + "phpunit/php-code-coverage": "^4.0.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.2.2", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", + "sebastian/environment": "^1.3 || ^2.0", "sebastian/exporter": "~1.2", "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", + "sebastian/object-enumerator": "~1.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "~1.0|~2.0", "symfony/yaml": "~2.1|~3.0" }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, "suggest": { "phpunit/php-invoker": "~1.1" }, @@ -1493,7 +1488,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.8.x-dev" + "dev-master": "5.5.x-dev" } }, "autoload": { @@ -1519,30 +1514,33 @@ "testing", "xunit" ], - "time": "2017-06-21T08:07:12+00:00" + "time": "2016-08-26T07:11:44+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", + "version": "3.4.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^5.4" }, "suggest": { "ext-soap": "*" @@ -1550,7 +1548,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "3.2.x-dev" } }, "autoload": { @@ -1575,7 +1573,52 @@ "mock", "xunit" ], - "time": "2015-10-02T06:51:40+00:00" + "time": "2017-06-30T09:13:00+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" }, { "name": "sebastian/comparator", @@ -1695,28 +1738,28 @@ }, { "name": "sebastian/environment", - "version": "1.3.8", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" + "phpunit/phpunit": "^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1741,7 +1784,7 @@ "environment", "hhvm" ], - "time": "2016-08-18T05:49:44+00:00" + "time": "2016-11-26T07:53:53+00:00" }, { "name": "sebastian/exporter", @@ -1861,6 +1904,52 @@ ], "time": "2015-10-12T03:26:01+00:00" }, + { + "name": "sebastian/object-enumerator", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", + "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2016-01-28T13:25:10+00:00" + }, { "name": "sebastian/recursion-context", "version": "1.0.5", @@ -1914,21 +2003,71 @@ "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "time": "2016-10-03T07:41:43+00:00" }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, { "name": "sebastian/version", - "version": "1.0.6", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", "shasum": "" }, + "require": { + "php": ">=5.6" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -1947,24 +2086,80 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21T13:59:46+00:00" + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com/", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-04-30T19:57:29+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.3", + "version": "v3.4.12", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "25c192f25721a74084272671f658797d9e0e0146" + "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/25c192f25721a74084272671f658797d9e0e0146", - "reference": "25c192f25721a74084272671f658797d9e0e0146", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c5010cc1692ce1fa328b1fb666961eb3d4a85bb0", + "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-ctype": "~1.8" }, "conflict": { "symfony/console": "<3.4" @@ -2005,20 +2200,20 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com/", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-05-03T23:18:14+00:00" }, { "name": "webmozart/assert", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", "shasum": "" }, "require": { @@ -2055,7 +2250,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2018-01-29T19:49:41+00:00" } ], "aliases": [], diff --git a/jobs/cjd_sample/phpunit.xml.dist b/jobs/cjd_sample/phpunit.xml.dist new file mode 100644 index 0000000000..bc37699374 --- /dev/null +++ b/jobs/cjd_sample/phpunit.xml.dist @@ -0,0 +1,34 @@ + + + + + + test + + + + + + + + ./src + + + + + + diff --git a/jobs/cjd_sample/quickstart.php b/jobs/cjd_sample/quickstart.php index a61a05eabb..50a949ba87 100644 --- a/jobs/cjd_sample/quickstart.php +++ b/jobs/cjd_sample/quickstart.php @@ -1,6 +1,6 @@ name . PHP_EOL; + echo $company->displayName . PHP_EOL; } # [END quickstart] -return $companies; \ No newline at end of file +return $companies; diff --git a/jobs/cjd_sample/src/basic_company_sample.php b/jobs/cjd_sample/src/basic_company_sample.php new file mode 100644 index 0000000000..23026920c9 --- /dev/null +++ b/jobs/cjd_sample/src/basic_company_sample.php @@ -0,0 +1,178 @@ +setDisplayName('Google'); + $company->setHqLocation('1600 Amphitheatre Parkway Mountain View, CA 94043'); + $company->setDistributorCompanyId($distributorCompanyId); + + printf("Company generated:\n%s\n", var_export($company, true)); + return $company; + } + # [END basic_company] + + # [START create_company] + /** + * Creates a company in Google Cloud Job Discovery. + * + * @param Google_Service_JobService_Company $companyToBeCreated + * @return Google_Service_JobService_Company + */ + public static function create_company(Google_Service_JobService_Company $companyToBeCreated) + { + $jobService = JobServiceConnector::get_job_service(); + + $companyCreated = $jobService->companies->create($companyToBeCreated); + printf("Company created:\n%s\n", var_export($companyCreated, true)); + return $companyCreated; + } + # [END create_company] + + # [START get_company] + /** + * Gets a company by its name. + * + * @param string $companyName + * @return Google_Service_JobService_Company + */ + public static function get_company(string $companyName) + { + $jobService = JobServiceConnector::get_job_service(); + + $companyExisted = $jobService->companies->get($companyName); + printf("Company existed:\n%s\n", var_export($companyExisted, true)); + return $companyExisted; + } + # [END get_company] + + # [START update_company] + /** + * Updates a company. + * + * @param string $companyName + * @param Google_Service_JobService_Company $companyToBeUpdated + * @return Google_Service_JobService_Company + */ + public static function update_company(string $companyName, Google_Service_JobService_Company $companyToBeUpdated) + { + $jobService = JobServiceConnector::get_job_service(); + + $companyUpdated = $jobService->companies->patch($companyName, $companyToBeUpdated); + printf("Company updated:\n%s\n", var_export($companyUpdated, true)); + return $companyUpdated; + } + # [END update_company] + + # [START update_company_with_field_mask] + /** + * Updates a company with field mask. + * + * @param string $companyName + * @param string $fieldMask + * @param Google_Service_JobService_Company $companyToBeUpdated + * @return Google_Service_JobService_Company + */ + public static function update_company_with_field_mask(string $companyName, string $fieldMask, Google_Service_JobService_Company $companyToBeUpdated) + { + $jobService = JobServiceConnector::get_job_service(); + + $optParams = array('updateCompanyFields' => $fieldMask); + $companyUpdated = $jobService->companies->patch($companyName, $companyToBeUpdated, $optParams); + printf("Company updated:\n%s\n", var_export($companyUpdated, true)); + return $companyUpdated; + } + # [END update_company_with_field_mask] + + # [START delete_company] + public static function delete_company(string $companyName) + { + $jobService = JobServiceConnector::get_job_service(); + + $jobService->companies->delete($companyName); + echo 'Company deleted' . PHP_EOL; + } + + # [END delete_company] + + protected function configure() + { + $this + ->setName('basic-company-sample') + ->setDescription('Run basic company sample script to create, update, and delete a company.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Construct a company. + $companyToBeCreated = self::generate_company(); + + // Create a company. + $companyCreated = self::create_company($companyToBeCreated); + + // Get a company + $companyName = $companyCreated->getName(); + self::get_company($companyName); + + // Update a company + $companyToBeUpdated = clone $companyCreated; + $companyToBeUpdated->setWebsite("https://elgoog.im/"); + self::update_company($companyName, $companyToBeUpdated); + + // Update a company with field mask + $companyToBeUpdated = new Google_Service_JobService_Company(); + $companyToBeUpdated->setDisplayName("changedTitle"); + $companyToBeUpdated->setDistributorCompanyId($companyCreated->getDistributorCompanyId()); + self::update_company_with_field_mask($companyName, 'displayName', $companyToBeUpdated); + + self::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/src/basic_job_sample.php b/jobs/cjd_sample/src/basic_job_sample.php new file mode 100644 index 0000000000..3abba1845a --- /dev/null +++ b/jobs/cjd_sample/src/basic_job_sample.php @@ -0,0 +1,198 @@ +setRequisitionId($requisitionId); + $job->setJobTitle('Software Engineer'); + $job->setCompanyName($companyName); + $job->setApplicationUrls(array('http://careers.google.com/')); + $job->setDescription('Design, develop, test, deploy, maintain and improve software.'); + printf("Job generated:\n%s\n", var_export($job, true)); + return $job; + } + + # [END basic_job] + + # [START create_job] + /** + * Creates a job. + * + * @param Google_Service_JobService_Job $jobToBeCreated + * @return Google_Service_JobService_Job + */ + public static function create_job(Google_Service_JobService_Job $jobToBeCreated) + { + $jobService = JobServiceConnector::get_job_service(); + + $createJobRequest = new Google_Service_JobService_CreateJobRequest(); + $createJobRequest->setJob($jobToBeCreated); + $jobCreated = $jobService->jobs->create($createJobRequest); + printf("Job created:\n%s\n", var_export($jobCreated, true)); + return $jobCreated; + } + # [END create_job] + + # [START get_job] + /** + * Gets a job by jobName. + * + * @param string $jobName + * @return Google_Service_JobService_Job + */ + public static function get_job(string $jobName) + { + $jobService = JobServiceConnector::get_job_service(); + + $jobExisted = $jobService->jobs->get($jobName); + printf("Job existed:\n%s\n", var_export($jobExisted, true)); + return $jobExisted; + } + # [END get_job] + + # [START update_job] + /** + * Updates a job. + * + * @param string $jobName + * @param Google_Service_JobService_Job $jobToBeUpdated + * @return Google_Service_JobService_Job + */ + public static function update_job(string $jobName, Google_Service_JobService_Job $jobToBeUpdated) + { + $jobService = JobServiceConnector::get_job_service(); + + $updateJobRequest = new Google_Service_JobService_UpdateJobRequest(); + $updateJobRequest->setJob($jobToBeUpdated); + $jobUpdated = $jobService->jobs->patch($jobName, $updateJobRequest); + printf("Job updated:\n%s\n", var_export($jobUpdated, true)); + return $jobUpdated; + } + # [END update_job] + + # [START update_job_with_field_mask] + /** + * Updates a job with field mask. + * + * @param string $jobName + * @param string $fieldMask + * @param Google_Service_JobService_Job $jobToBeUpdated + * @return Google_Service_JobService_Job + */ + public static function update_job_with_field_mask(string $jobName, string $fieldMask, Google_Service_JobService_Job $jobToBeUpdated) + { + $jobService = JobServiceConnector::get_job_service(); + + $updateJobRequest = new Google_Service_JobService_UpdateJobRequest(); + $updateJobRequest->setJob($jobToBeUpdated); + $updateJobRequest->setUpdateJobFields($fieldMask); + + $jobUpdated = $jobService->jobs->patch($jobName, $updateJobRequest); + printf("Job updated:\n%s\n", var_export($jobUpdated, true)); + return $jobUpdated; + } + # [END update_job_with_field_mask] + + # [START delete_job] + public static function delete_job(string $jobName) + { + $jobService = JobServiceConnector::get_job_service(); + + $jobService->jobs->delete($jobName); + echo 'Job deleted' . PHP_EOL; + } + + # [END delete_job] + + + protected function configure() + { + $this + ->setName('basic-job-sample') + ->setDescription('Run basic job sample script to create, update, and delete a job.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Create a company before creating jobs. + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyCreated = BasicCompanySample::create_company($companyToBeCreated); + $companyName = $companyCreated->getName(); + + // Construct a job. + $jobToBeCreated = self::generate_job_with_required_fields($companyName); + + // Create a job. + $jobCreated = self::create_job($jobToBeCreated); + + // Get a job. + $jobName = $jobCreated->getName(); + self::get_job($jobName); + + // Update a job. + $jobToBeUpdated = clone $jobCreated; + $jobToBeUpdated->setDescription('changedDescription'); + self::update_job($jobName, $jobToBeUpdated); + + // Update a job with field mask. + $jobToBeUpdated = new Google_Service_JobService_Job(); + $jobToBeUpdated->setJobTitle('changedJobTitle'); + self::update_job_with_field_mask($jobName, 'jobTitle', $jobToBeUpdated); + + // Delete a job. + self::delete_job($jobName); + + // Delete company only after cleaning all jobs under this company. + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/src/job_service_connector.php b/jobs/cjd_sample/src/job_service_connector.php new file mode 100644 index 0000000000..f23eb27d9d --- /dev/null +++ b/jobs/cjd_sample/src/job_service_connector.php @@ -0,0 +1,42 @@ +useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + public static function get_job_service() + { + if (!isset($jobService)) { + $jobService = self::create_job_service(); + } + return $jobService; + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/test/BasicCompanySampleTest.php b/jobs/cjd_sample/test/BasicCompanySampleTest.php new file mode 100644 index 0000000000..7294d824ea --- /dev/null +++ b/jobs/cjd_sample/test/BasicCompanySampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('basic-company-sample')); + } + + public function testBasicCompanySample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/.*Company generated:.*Company created:.*Company existed:' + . '.*Company updated:.*elgoog.*Company updated:.*changedTitle.*Company deleted/s'); + } +} diff --git a/jobs/cjd_sample/test/BasicJobSampleTest.php b/jobs/cjd_sample/test/BasicJobSampleTest.php new file mode 100644 index 0000000000..fdcf772c62 --- /dev/null +++ b/jobs/cjd_sample/test/BasicJobSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('basic-job-sample')); + } + + public function testBasicCompanySample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/Job generated:.*Job created:.*Job existed:.*Job updated:' + . '.*changedDescription.*Job updated:.*changedJobTitle.*Job deleted/s'); + } +} From 1ba6c7adf5b8615fade7edb127f8bb14d12713ef Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Tue, 10 Jul 2018 21:08:39 -0700 Subject: [PATCH 02/17] Finish general search sample and its test --- jobs/cjd_sample/cjd_sample.php | 2 +- jobs/cjd_sample/composer.json | 5 +- jobs/cjd_sample/composer.lock | 318 +++------------ jobs/cjd_sample/src/general_search_sample.php | 379 ++++++++++++++++++ jobs/cjd_sample/test/BasicJobSampleTest.php | 2 +- .../test/GeneralSearchSampleTest.php | 34 ++ 6 files changed, 479 insertions(+), 261 deletions(-) create mode 100644 jobs/cjd_sample/src/general_search_sample.php create mode 100644 jobs/cjd_sample/test/GeneralSearchSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index efc7a45707..37c704d970 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -25,7 +25,7 @@ $application->add(new BasicCompanySample()); $application->add(new BasicJobSample()); - +$application->add(new GeneralSearchSample()); // for testing if (getenv('PHPUNIT_TESTS') === '1') { diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index 2b41203ddc..b427d7dbc8 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -5,15 +5,16 @@ "symfony/console": " ^3.0" }, "require-dev": { - "phpunit/phpunit": "~5.0" + "phpunit/phpunit": "~4.0" }, "autoload": { "psr-4": { "Google\\Cloud\\Samples\\Language\\": "src/" }, "files": [ - "src/basic_job_sample.php", "src/basic_company_sample.php", + "src/basic_job_sample.php", + "src/general_search_sample.php", "src/job_service_connector.php" ] } diff --git a/jobs/cjd_sample/composer.lock b/jobs/cjd_sample/composer.lock index c830606ae3..979f5aa9fe 100644 --- a/jobs/cjd_sample/composer.lock +++ b/jobs/cjd_sample/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "918a52f634141c37993aabe931e2c0e2", + "content-hash": "4190f32a9bdb93d261931a5f6bcfa366", "packages": [ { "name": "firebase/php-jwt", @@ -929,51 +929,6 @@ ], "time": "2015-06-14T21:17:01+00:00" }, - { - "name": "myclabs/deep-copy", - "version": "1.7.0", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "doctrine/collections": "^1.0", - "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - }, - "files": [ - "src/DeepCopy/deep_copy.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Create deep copies (clones) of your objects", - "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" - ], - "time": "2017-10-19T19:58:43+00:00" - }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -1191,40 +1146,39 @@ }, { "name": "phpunit/php-code-coverage", - "version": "4.0.8", + "version": "2.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", "shasum": "" }, "require": { - "ext-dom": "*", - "ext-xmlwriter": "*", - "php": "^5.6 || ^7.0", - "phpunit/php-file-iterator": "^1.3", - "phpunit/php-text-template": "^1.2", - "phpunit/php-token-stream": "^1.4.2 || ^2.0", - "sebastian/code-unit-reverse-lookup": "^1.0", - "sebastian/environment": "^1.3.2 || ^2.0", - "sebastian/version": "^1.0 || ^2.0" + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "^1.3.2", + "sebastian/version": "~1.0" }, "require-dev": { - "ext-xdebug": "^2.1.4", - "phpunit/phpunit": "^5.7" + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" }, "suggest": { - "ext-xdebug": "^2.5.1" + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "2.2.x-dev" } }, "autoload": { @@ -1250,7 +1204,7 @@ "testing", "xunit" ], - "time": "2017-04-02T07:44:40+00:00" + "time": "2015-10-06T15:47:00+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1391,29 +1345,29 @@ }, { "name": "phpunit/php-token-stream", - "version": "2.0.2", + "version": "1.4.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "791198a2c6254db10131eecfe8c06670700904db" + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", - "reference": "791198a2c6254db10131eecfe8c06670700904db", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.0" + "php": ">=5.3.3" }, "require-dev": { - "phpunit/phpunit": "^6.2.4" + "phpunit/phpunit": "~4.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -1436,20 +1390,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-11-27T05:48:46+00:00" + "time": "2017-12-04T08:55:13+00:00" }, { "name": "phpunit/phpunit", - "version": "5.5.4", + "version": "4.8.36", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5" + "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6e88e56c912133de6e99b87728cca7ed70c5f5", - "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", + "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", "shasum": "" }, "require": { @@ -1458,27 +1412,21 @@ "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", - "myclabs/deep-copy": "~1.3", - "php": "^5.6 || ^7.0", + "php": ">=5.3.3", "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "^4.0.1", + "phpunit/php-code-coverage": "~2.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "~1.1", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.2.2", "sebastian/diff": "~1.2", - "sebastian/environment": "^1.3 || ^2.0", + "sebastian/environment": "~1.3", "sebastian/exporter": "~1.2", "sebastian/global-state": "~1.0", - "sebastian/object-enumerator": "~1.0", - "sebastian/resource-operations": "~1.0", - "sebastian/version": "~1.0|~2.0", + "sebastian/version": "~1.0", "symfony/yaml": "~2.1|~3.0" }, - "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2" - }, "suggest": { "phpunit/php-invoker": "~1.1" }, @@ -1488,7 +1436,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.5.x-dev" + "dev-master": "4.8.x-dev" } }, "autoload": { @@ -1514,33 +1462,30 @@ "testing", "xunit" ], - "time": "2016-08-26T07:11:44+00:00" + "time": "2017-06-21T08:07:12+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.4.4", + "version": "2.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" + "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", - "php": "^5.6 || ^7.0", - "phpunit/php-text-template": "^1.2", - "sebastian/exporter": "^1.2 || ^2.0" - }, - "conflict": { - "phpunit/phpunit": "<5.4.0" + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" }, "require-dev": { - "phpunit/phpunit": "^5.4" + "phpunit/phpunit": "~4.4" }, "suggest": { "ext-soap": "*" @@ -1548,7 +1493,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2.x-dev" + "dev-master": "2.3.x-dev" } }, "autoload": { @@ -1573,52 +1518,7 @@ "mock", "xunit" ], - "time": "2017-06-30T09:13:00+00:00" - }, - { - "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Looks up which function or method a line of code belongs to", - "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "time": "2015-10-02T06:51:40+00:00" }, { "name": "sebastian/comparator", @@ -1738,28 +1638,28 @@ }, { "name": "sebastian/environment", - "version": "2.0.0", + "version": "1.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^5.0" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -1784,7 +1684,7 @@ "environment", "hhvm" ], - "time": "2016-11-26T07:53:53+00:00" + "time": "2016-08-18T05:49:44+00:00" }, { "name": "sebastian/exporter", @@ -1904,52 +1804,6 @@ ], "time": "2015-10-12T03:26:01+00:00" }, - { - "name": "sebastian/object-enumerator", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", - "shasum": "" - }, - "require": { - "php": ">=5.6", - "sebastian/recursion-context": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "~5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Traverses array structures and object graphs to enumerate all referenced objects", - "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2016-01-28T13:25:10+00:00" - }, { "name": "sebastian/recursion-context", "version": "1.0.5", @@ -2003,71 +1857,21 @@ "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "time": "2016-10-03T07:41:43+00:00" }, - { - "name": "sebastian/resource-operations", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "shasum": "" - }, - "require": { - "php": ">=5.6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides a list of PHP built-in functions that operate on resources", - "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" - }, { "name": "sebastian/version", - "version": "2.0.1", + "version": "1.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", "shasum": "" }, - "require": { - "php": ">=5.6" - }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, "autoload": { "classmap": [ "src/" @@ -2086,7 +1890,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03T07:35:21+00:00" + "time": "2015-06-21T13:59:46+00:00" }, { "name": "symfony/polyfill-ctype", diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/cjd_sample/src/general_search_sample.php new file mode 100644 index 0000000000..8909c72870 --- /dev/null +++ b/jobs/cjd_sample/src/general_search_sample.php @@ -0,0 +1,379 @@ +setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + // Perform a search for analyst related jobs + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setQuery($query); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END basic_keyword_search] + + # [START category_filter] + /** + * Search on category filter. + * + * @param string $companyName + * @param string ...$categories + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function category_filter_search(string $companyName, string ...$categories) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCategories(array($categories)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [START employment_types_filter] + + /** + * Search on employment types. + * + * @param string $companyName + * @param string ...$employmentTypes + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function employment_types_search(string $companyName, string ...$employmentTypes) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setEmploymentTypes(array($employmentTypes)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END employment_types_filter] + + # [START date_range_filter] + /** + * Search by date range. + * + * @param string $companyName + * @param string $dateRange + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function date_range_search(string $companyName, string $dateRange) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setPublishDateRange($dateRange); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END date_range_filter] + + # [START language_code_filter] + /** + * Search by language code. + * + * @param string $companyName + * @param string ...$languageCodes + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function language_code_search(string $companyName, string ...$languageCodes) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setLanguageCodes(array($languageCodes)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END language_code_filter] + + # [START company_display_name_filter] + /** + * Search on company display name. + * + * @param string $companyName + * @param string ...$companyDisplayNames + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function company_display_name_search(string $companyName, string ...$companyDisplayNames) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCompanyDisplayNames($companyDisplayNames); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END company_display_name_filter] + + # [START compensation_filter] + /** + * Search on compensation. + * + * @param string $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function compensation_search(string $companyName) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $compensationFilter = new Google_Service_JobService_CompensationFilter(); + $compensationFilter->setType('UNIT_AND_AMOUNT'); + $compensationFilter->setUnits(array('HOURLY')); + + $compensationRange = new Google_Service_JobService_CompensationRange(); + $maxMoney = new Google_Service_JobService_Money(); + $maxMoney->setCurrencyCode('USD'); + $maxMoney->setUnits(15); + $compensationRange->setMax($maxMoney); + $minMoney = new Google_Service_JobService_Money(); + $minMoney->setCurrencyCode('USD'); + $minMoney->setUnits(10); + $minMoney->setNanos(500000000); + $compensationRange->setMin($minMoney); + $compensationFilter->setRange($compensationRange); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCompensationFilter($compensationFilter); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [END compensation_filter] + + protected function configure() + { + $this + ->setName('general-search-sample') + ->setDescription('Run general search sample script to do search with different filters.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyToBeCreated->setDisplayName('Google'); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + $jobToBeCreated = BasicJobSample::generate_job_with_required_fields($companyName); + $jobToBeCreated->setJobTitle('Systems Administrator'); + $jobToBeCreated->setEmploymentTypes(array('FULL_TIME')); + $jobToBeCreated->setLanguageCode('en-US'); + $compensationEntry = new Google_Service_JobService_CompensationEntry(); + $compensationEntry->setType('BASE'); + $compensationEntry->setUnit('HOURLY'); + $amount = new Google_Service_JobService_Money(); + $amount->setCurrencyCode('USD'); + $amount->setUnits(12); + $compensationEntry->setAmount($amount); + $compensationInfo = new Google_Service_JobService_CompensationInfo(); + $compensationInfo->setEntries(array($compensationEntry)); + $jobToBeCreated->setCompensationInfo($compensationInfo); + + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing. + sleep(20); + self::basic_search_jobs($companyName, 'Systems Administrator'); + self::category_filter_search($companyName, 'COMPUTER_AND_IT'); + self::date_range_search($companyName, 'PAST_24_HOURS'); + self::employment_types_search($companyName, 'FULL_TIME', 'CONTRACTOR', 'PER_DIEM'); + self::company_display_name_search($companyName, 'Google'); + self::compensation_search($companyName); + self::language_code_search($companyName, 'pt-BR', 'en-US'); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/test/BasicJobSampleTest.php b/jobs/cjd_sample/test/BasicJobSampleTest.php index fdcf772c62..cf8b0c08f8 100644 --- a/jobs/cjd_sample/test/BasicJobSampleTest.php +++ b/jobs/cjd_sample/test/BasicJobSampleTest.php @@ -33,7 +33,7 @@ public function setUp() $this->commandTester = new CommandTester($application->get('basic-job-sample')); } - public function testBasicCompanySample() + public function testBasicJobSample() { $this->commandTester->execute([], ['interactive' => false]); $this->expectOutputRegex('/Job generated:.*Job created:.*Job existed:.*Job updated:' diff --git a/jobs/cjd_sample/test/GeneralSearchSampleTest.php b/jobs/cjd_sample/test/GeneralSearchSampleTest.php new file mode 100644 index 0000000000..f62b1b7ab6 --- /dev/null +++ b/jobs/cjd_sample/test/GeneralSearchSampleTest.php @@ -0,0 +1,34 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('general-search-sample')); + } + + public function testGeneralSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/matchingJobs.*matchingJobs.*matchingJobs.*matchingJobs.*' + . 'matchingJobs.*matchingJobs.*matchingJobs.*/s'); + } +} From 6dfe099be55e0ae10bd13bccb25915d864f5e9f3 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 13:57:39 -0700 Subject: [PATCH 03/17] Finish location search sample and its tests --- jobs/cjd_sample/cjd_sample.php | 1 + jobs/cjd_sample/composer.json | 3 +- jobs/cjd_sample/src/basic_company_sample.php | 3 +- jobs/cjd_sample/src/basic_job_sample.php | 3 +- jobs/cjd_sample/src/general_search_sample.php | 2 +- .../cjd_sample/src/location_search_sample.php | 314 ++++++++++++++++++ .../test/LocationSearchSampleTest.php | 37 +++ 7 files changed, 359 insertions(+), 4 deletions(-) create mode 100644 jobs/cjd_sample/src/location_search_sample.php create mode 100644 jobs/cjd_sample/test/LocationSearchSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index 37c704d970..769fa28f69 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -26,6 +26,7 @@ $application->add(new BasicCompanySample()); $application->add(new BasicJobSample()); $application->add(new GeneralSearchSample()); +$application->add(new LocationSearchSample()); // for testing if (getenv('PHPUNIT_TESTS') === '1') { diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index b427d7dbc8..296cbe2cda 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -15,7 +15,8 @@ "src/basic_company_sample.php", "src/basic_job_sample.php", "src/general_search_sample.php", - "src/job_service_connector.php" + "src/job_service_connector.php", + "src/location_search_sample.php" ] } } diff --git a/jobs/cjd_sample/src/basic_company_sample.php b/jobs/cjd_sample/src/basic_company_sample.php index 23026920c9..944a29dc4a 100644 --- a/jobs/cjd_sample/src/basic_company_sample.php +++ b/jobs/cjd_sample/src/basic_company_sample.php @@ -121,7 +121,8 @@ public static function update_company(string $companyName, Google_Service_JobSer * @param Google_Service_JobService_Company $companyToBeUpdated * @return Google_Service_JobService_Company */ - public static function update_company_with_field_mask(string $companyName, string $fieldMask, Google_Service_JobService_Company $companyToBeUpdated) + public static function update_company_with_field_mask(string $companyName, string $fieldMask, + Google_Service_JobService_Company $companyToBeUpdated) { $jobService = JobServiceConnector::get_job_service(); diff --git a/jobs/cjd_sample/src/basic_job_sample.php b/jobs/cjd_sample/src/basic_job_sample.php index 3abba1845a..5c4cd7d90d 100644 --- a/jobs/cjd_sample/src/basic_job_sample.php +++ b/jobs/cjd_sample/src/basic_job_sample.php @@ -129,7 +129,8 @@ public static function update_job(string $jobName, Google_Service_JobService_Job * @param Google_Service_JobService_Job $jobToBeUpdated * @return Google_Service_JobService_Job */ - public static function update_job_with_field_mask(string $jobName, string $fieldMask, Google_Service_JobService_Job $jobToBeUpdated) + public static function update_job_with_field_mask(string $jobName, string $fieldMask, + Google_Service_JobService_Job $jobToBeUpdated) { $jobService = JobServiceConnector::get_job_service(); diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/cjd_sample/src/general_search_sample.php index 8909c72870..96a6637c87 100644 --- a/jobs/cjd_sample/src/general_search_sample.php +++ b/jobs/cjd_sample/src/general_search_sample.php @@ -364,7 +364,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); // Wait several seconds for post processing. - sleep(20); + sleep(10); self::basic_search_jobs($companyName, 'Systems Administrator'); self::category_filter_search($companyName, 'COMPUTER_AND_IT'); self::date_range_search($companyName, 'PAST_24_HOURS'); diff --git a/jobs/cjd_sample/src/location_search_sample.php b/jobs/cjd_sample/src/location_search_sample.php new file mode 100644 index 0000000000..218a5fba3d --- /dev/null +++ b/jobs/cjd_sample/src/location_search_sample.php @@ -0,0 +1,314 @@ +setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $locationFilter = new Google_Service_JobService_LocationFilter(); + $locationFilter->setName($location); + $locationFilter->setDistanceInMiles($distance); + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setLocationFilters(array($locationFilter)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END basic_location_search] + + # [START keyword_location_search] + /** + * Keyword location search. + * + * @param string $companyName + * @param string $location + * @param float $distance + * @param string $keyword + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function keyword_location_search(string $companyName, string $location, float $distance, + string $keyword) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $locationFilter = new Google_Service_JobService_LocationFilter(); + $locationFilter->setName($location); + $locationFilter->setDistanceInMiles($distance); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setQuery($keyword); + $jobQuery->setLocationFilters(array($locationFilter)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END keyword_location_search] + + # [START city_location_search] + /** + * City location search. + * + * @param string $companyName + * @param string $location + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function city_location_search(string $companyName, string $location) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $locationFilter = new Google_Service_JobService_LocationFilter(); + $locationFilter->setName($location); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setLocationFilters(array($locationFilter)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END city_location_search] + + # [START multi_locations_search] + /** + * Multiple locations search. + * + * @param string $companyName + * @param string $location1 + * @param float $distance1 + * @param string $location2 + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function multi_locations_search(string $companyName, string $location1, float $distance1, + string $location2) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $locationFilter1 = new Google_Service_JobService_LocationFilter(); + $locationFilter1->setName($location1); + $locationFilter1->setDistanceInMiles($distance1); + + $locationFilter2 = new Google_Service_JobService_LocationFilter(); + $locationFilter2->setName($location2); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setLocationFilters(array($locationFilter1, $locationFilter2)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + # [END multi_locations_search] + + # [START broadening_location_search] + /** + * Broadening location search. + * + * @param string $companyName + * @param string $location + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function broadening_location_search(string $companyName, string $location) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $locationFilter = new Google_Service_JobService_LocationFilter(); + $locationFilter->setName($location); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setLocationFilters(array($locationFilter)); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + // Enable broadening. + $searchRequest->setEnableBroadening(true); + $searchRequest->setMode('JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + + } + + # [END broadening_location_search] + + protected function configure() + { + $this + ->setName('location-search-sample') + ->setDescription('Run location search sample script to do location search.') + ->addOption('location', null, InputOption::VALUE_OPTIONAL, 'The location to search.', 'Mountain View, CA') + ->addOption('distance', null, InputOption::VALUE_OPTIONAL, 'Distance in miles to search.', 0.5) + ->addOption('keyword', + null, + InputOption::VALUE_OPTIONAL, + 'The keyword used in keyword search sample', + 'Software Engineer') + ->addOption('location2', + null, + InputOption::VALUE_OPTIONAL, + 'Second location in multiple locations search sample', + 'Sunnyvale, CA'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $location = $input->getOption('location'); + $distance = $input->getOption('distance'); + $keyword = $input->getOption('keyword'); + $location2 = $input->getOption('location2'); + + // Create a company. + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + // Create first job. + $jobToBeCreated = BasicJobSample::generate_job_with_required_fields($companyName); + $jobToBeCreated->setLocations(array($location)); + $jobToBeCreated->setJobTitle($keyword); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Create second job. + $jobToBeCreated2 = BasicJobSample::generate_job_with_required_fields($companyName); + $jobToBeCreated2->setLocations(array($location2)); + $jobToBeCreated2->setJobTitle($keyword); + $jobName2 = BasicJobSample::create_job($jobToBeCreated2)->getName(); + + // Wait several seconds for post processing. + sleep(10); + self::basic_location_search($companyName, $location, $distance); + self::city_location_search($companyName, $location); + self::broadening_location_search($companyName, $location); + self::keyword_location_search($companyName, $location, $distance, $keyword); + self::multi_locations_search($companyName, $location, $distance, $location2); + + // Delete jobs before deleting the company. + BasicJobSample::delete_job($jobName); + BasicJobSample::delete_job($jobName2); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/test/LocationSearchSampleTest.php b/jobs/cjd_sample/test/LocationSearchSampleTest.php new file mode 100644 index 0000000000..ef7b762cf0 --- /dev/null +++ b/jobs/cjd_sample/test/LocationSearchSampleTest.php @@ -0,0 +1,37 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('location-search-sample')); + } + + public function testLocationSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*/s'); + } +} From d2daf47de8a4c7ff009a8e3be4134e9ef6816497 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 14:14:40 -0700 Subject: [PATCH 04/17] Add featured jobs search sample and its test --- jobs/cjd_sample/cjd_sample.php | 1 + jobs/cjd_sample/composer.json | 1 + jobs/cjd_sample/src/basic_company_sample.php | 2 +- jobs/cjd_sample/src/basic_job_sample.php | 2 +- .../src/featured_jobs_search_sample.php | 126 ++++++++++++++++++ jobs/cjd_sample/src/general_search_sample.php | 2 +- .../cjd_sample/src/location_search_sample.php | 19 ++- .../test/FeaturedJobsSearchSampleTest.php | 42 ++++++ .../test/GeneralSearchSampleTest.php | 17 ++- .../test/LocationSearchSampleTest.php | 17 ++- 10 files changed, 213 insertions(+), 16 deletions(-) create mode 100644 jobs/cjd_sample/src/featured_jobs_search_sample.php create mode 100644 jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index 769fa28f69..4e0709f175 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -27,6 +27,7 @@ $application->add(new BasicJobSample()); $application->add(new GeneralSearchSample()); $application->add(new LocationSearchSample()); +$application->add(new FeaturedJobsSearchSample()); // for testing if (getenv('PHPUNIT_TESTS') === '1') { diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index 296cbe2cda..fc2e4013b8 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -14,6 +14,7 @@ "files": [ "src/basic_company_sample.php", "src/basic_job_sample.php", + "src/featured_jobs_search_sample.php", "src/general_search_sample.php", "src/job_service_connector.php", "src/location_search_sample.php" diff --git a/jobs/cjd_sample/src/basic_company_sample.php b/jobs/cjd_sample/src/basic_company_sample.php index 944a29dc4a..2062ff1c98 100644 --- a/jobs/cjd_sample/src/basic_company_sample.php +++ b/jobs/cjd_sample/src/basic_company_sample.php @@ -147,7 +147,7 @@ public static function delete_company(string $companyName) protected function configure() { $this - ->setName('basic-company-sample') + ->setName('basic-company') ->setDescription('Run basic company sample script to create, update, and delete a company.'); } diff --git a/jobs/cjd_sample/src/basic_job_sample.php b/jobs/cjd_sample/src/basic_job_sample.php index 5c4cd7d90d..aad8f41b85 100644 --- a/jobs/cjd_sample/src/basic_job_sample.php +++ b/jobs/cjd_sample/src/basic_job_sample.php @@ -159,7 +159,7 @@ public static function delete_job(string $jobName) protected function configure() { $this - ->setName('basic-job-sample') + ->setName('basic-job') ->setDescription('Run basic job sample script to create, update, and delete a job.'); } diff --git a/jobs/cjd_sample/src/featured_jobs_search_sample.php b/jobs/cjd_sample/src/featured_jobs_search_sample.php new file mode 100644 index 0000000000..eb0b328e7d --- /dev/null +++ b/jobs/cjd_sample/src/featured_jobs_search_sample.php @@ -0,0 +1,126 @@ +setRequisitionId($requisitionId); + $job->setJobTitle('Software Engineer'); + $job->setCompanyName($companyName); + $job->setApplicationUrls(array('https://careers.google.com/')); + $job->setDescription('Design, develop, test, deploy, maintain and improve software.'); + // Featured job is the job with positive promotion value + $job->setPromotionValue(2); + + printf("Job generated:\n%s\n", var_export($job, true)); + return $job; + } + # [END featured_job] + + # [START search_featured_job] + /** + * Searches featured jobs. + * + * @param string $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function search_featured_jobs(string $companyName) + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setQuery('Software Engineer'); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + // Set the search mode to a featured search, + // which would only search the jobs with positive promotion value. + $searchRequest->setMode('FEATURED_JOB_SEARCH'); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [END search_featured_job] + + protected function configure() + { + $this + ->setName('featured-jobs-search') + ->setDescription('Run featured jobs search sample script.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + $jobToBeCreated = self::generate_featured_job($companyName); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing + sleep(10); + self::search_featured_jobs($companyName); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/cjd_sample/src/general_search_sample.php index 96a6637c87..b6a7ae4726 100644 --- a/jobs/cjd_sample/src/general_search_sample.php +++ b/jobs/cjd_sample/src/general_search_sample.php @@ -336,7 +336,7 @@ public static function compensation_search(string $companyName) protected function configure() { $this - ->setName('general-search-sample') + ->setName('general-search') ->setDescription('Run general search sample script to do search with different filters.'); } diff --git a/jobs/cjd_sample/src/location_search_sample.php b/jobs/cjd_sample/src/location_search_sample.php index 218a5fba3d..9abb1ff024 100644 --- a/jobs/cjd_sample/src/location_search_sample.php +++ b/jobs/cjd_sample/src/location_search_sample.php @@ -1,9 +1,18 @@ setName('location-search-sample') + ->setName('location-search') ->setDescription('Run location search sample script to do location search.') ->addOption('location', null, InputOption::VALUE_OPTIONAL, 'The location to search.', 'Mountain View, CA') ->addOption('distance', null, InputOption::VALUE_OPTIONAL, 'Distance in miles to search.', 0.5) diff --git a/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php b/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php new file mode 100644 index 0000000000..15a0b2b27c --- /dev/null +++ b/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('featured-jobs-search')); + } + + public function testFeaturedJobsSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/matchingJobs/'); + } +} diff --git a/jobs/cjd_sample/test/GeneralSearchSampleTest.php b/jobs/cjd_sample/test/GeneralSearchSampleTest.php index f62b1b7ab6..a82ad841c4 100644 --- a/jobs/cjd_sample/test/GeneralSearchSampleTest.php +++ b/jobs/cjd_sample/test/GeneralSearchSampleTest.php @@ -1,9 +1,18 @@ Date: Wed, 11 Jul 2018 15:28:26 -0700 Subject: [PATCH 05/17] Add auto complete sample and its test --- jobs/cjd_sample/cjd_sample.php | 3 +- jobs/cjd_sample/composer.json | 1 + jobs/cjd_sample/src/auto_complete_sample.php | 101 ++++++++++++++++++ .../src/featured_jobs_search_sample.php | 2 +- jobs/cjd_sample/src/general_search_sample.php | 14 +-- .../cjd_sample/src/location_search_sample.php | 10 +- .../test/AutoCompleteSampleTest.php | 44 ++++++++ 7 files changed, 161 insertions(+), 14 deletions(-) create mode 100644 jobs/cjd_sample/src/auto_complete_sample.php create mode 100644 jobs/cjd_sample/test/AutoCompleteSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index 4e0709f175..7b13e5e116 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -23,11 +23,12 @@ $application = new Application('Cloud Job Discovery'); +$application->add(new AutoCompleteSample()); $application->add(new BasicCompanySample()); $application->add(new BasicJobSample()); +$application->add(new FeaturedJobsSearchSample()); $application->add(new GeneralSearchSample()); $application->add(new LocationSearchSample()); -$application->add(new FeaturedJobsSearchSample()); // for testing if (getenv('PHPUNIT_TESTS') === '1') { diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index fc2e4013b8..d0d3e4ce31 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -12,6 +12,7 @@ "Google\\Cloud\\Samples\\Language\\": "src/" }, "files": [ + "src/auto_complete_sample.php", "src/basic_company_sample.php", "src/basic_job_sample.php", "src/featured_jobs_search_sample.php", diff --git a/jobs/cjd_sample/src/auto_complete_sample.php b/jobs/cjd_sample/src/auto_complete_sample.php new file mode 100644 index 0000000000..007245b7b9 --- /dev/null +++ b/jobs/cjd_sample/src/auto_complete_sample.php @@ -0,0 +1,101 @@ + $query, + 'languageCode' => 'en-US', + 'type' => 'JOB_TITLE', + 'pageSize' => 10); + if (isset($companyName)) { + $optParams['companyName'] = $companyName; + } + + $jobService = JobServiceConnector::get_job_service(); + $results = $jobService->v2->complete($optParams); + + var_export($results); + return $results; + } + + # [END auto_complete_job_title] + + # [START auto_complete_default] + public static function default_auto_complete(string $companyName = null, string $query) + { + $optParams = array( + 'query' => $query, + 'languageCode' => 'en-US', + 'pageSize' => 10); + if (isset($companyName)) { + $optParams['companyName'] = $companyName; + } + + $jobService = JobServiceConnector::get_job_service(); + $results = $jobService->v2->complete($optParams); + + var_export($results); + return $results; + } + + # [END auto_complete_default] + + protected function configure() + { + $this + ->setName('auto-complete') + ->setDescription('Run auto complete sample script.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyToBeCreated->setDisplayName('Google'); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + $jobToBeCreated = BasicJobSample::generate_job_with_required_fields($companyName); + $jobToBeCreated->setJobTitle('Software engineer'); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing. + sleep(10); + self::default_auto_complete($companyName, 'goo'); + self::default_auto_complete($companyName, 'sof'); + self::job_title_auto_complete($companyName, 'sof'); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/src/featured_jobs_search_sample.php b/jobs/cjd_sample/src/featured_jobs_search_sample.php index eb0b328e7d..be63f6d269 100644 --- a/jobs/cjd_sample/src/featured_jobs_search_sample.php +++ b/jobs/cjd_sample/src/featured_jobs_search_sample.php @@ -68,7 +68,7 @@ public static function generate_featured_job(string $companyName) * @param string $companyName * @return Google_Service_JobService_SearchJobsResponse */ - public static function search_featured_jobs(string $companyName) + public static function search_featured_jobs(string $companyName = null) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/cjd_sample/src/general_search_sample.php index b6a7ae4726..b86ff04ea2 100644 --- a/jobs/cjd_sample/src/general_search_sample.php +++ b/jobs/cjd_sample/src/general_search_sample.php @@ -58,7 +58,7 @@ final class GeneralSearchSample extends Command * @param string $query * @return Google_Service_JobService_SearchJobsResponse */ - public static function basic_search_jobs(string $companyName, string $query) + public static function basic_search_jobs(string $companyName = null, string $query) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -97,7 +97,7 @@ public static function basic_search_jobs(string $companyName, string $query) * @param string ...$categories * @return Google_Service_JobService_SearchJobsResponse */ - public static function category_filter_search(string $companyName, string ...$categories) + public static function category_filter_search(string $companyName = null, string ...$categories) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -135,7 +135,7 @@ public static function category_filter_search(string $companyName, string ...$ca * @param string ...$employmentTypes * @return Google_Service_JobService_SearchJobsResponse */ - public static function employment_types_search(string $companyName, string ...$employmentTypes) + public static function employment_types_search(string $companyName = null, string ...$employmentTypes) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -173,7 +173,7 @@ public static function employment_types_search(string $companyName, string ...$e * @param string $dateRange * @return Google_Service_JobService_SearchJobsResponse */ - public static function date_range_search(string $companyName, string $dateRange) + public static function date_range_search(string $companyName = null, string $dateRange) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -211,7 +211,7 @@ public static function date_range_search(string $companyName, string $dateRange) * @param string ...$languageCodes * @return Google_Service_JobService_SearchJobsResponse */ - public static function language_code_search(string $companyName, string ...$languageCodes) + public static function language_code_search(string $companyName = null, string ...$languageCodes) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -249,7 +249,7 @@ public static function language_code_search(string $companyName, string ...$lang * @param string ...$companyDisplayNames * @return Google_Service_JobService_SearchJobsResponse */ - public static function company_display_name_search(string $companyName, string ...$companyDisplayNames) + public static function company_display_name_search(string $companyName = null, string ...$companyDisplayNames) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -286,7 +286,7 @@ public static function company_display_name_search(string $companyName, string . * @param string $companyName * @return Google_Service_JobService_SearchJobsResponse */ - public static function compensation_search(string $companyName) + public static function compensation_search(string $companyName = null) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); diff --git a/jobs/cjd_sample/src/location_search_sample.php b/jobs/cjd_sample/src/location_search_sample.php index 9abb1ff024..a22e1e31f3 100644 --- a/jobs/cjd_sample/src/location_search_sample.php +++ b/jobs/cjd_sample/src/location_search_sample.php @@ -52,7 +52,7 @@ final class LocationSearchSample extends Command * @param float $distance * @return Google_Service_JobService_SearchJobsResponse */ - public static function basic_location_search(string $companyName, string $location, float $distance) + public static function basic_location_search(string $companyName = null, string $location, float $distance) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -95,7 +95,7 @@ public static function basic_location_search(string $companyName, string $locati * @param string $keyword * @return Google_Service_JobService_SearchJobsResponse */ - public static function keyword_location_search(string $companyName, string $location, float $distance, + public static function keyword_location_search(string $companyName = null, string $location, float $distance, string $keyword) { // Make sure to set the requestMetadata the same as the associated search request @@ -139,7 +139,7 @@ public static function keyword_location_search(string $companyName, string $loca * @param string $location * @return Google_Service_JobService_SearchJobsResponse */ - public static function city_location_search(string $companyName, string $location) + public static function city_location_search(string $companyName = null, string $location) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); @@ -182,7 +182,7 @@ public static function city_location_search(string $companyName, string $locatio * @param string $location2 * @return Google_Service_JobService_SearchJobsResponse */ - public static function multi_locations_search(string $companyName, string $location1, float $distance1, + public static function multi_locations_search(string $companyName = null, string $location1, float $distance1, string $location2) { // Make sure to set the requestMetadata the same as the associated search request @@ -228,7 +228,7 @@ public static function multi_locations_search(string $companyName, string $locat * @param string $location * @return Google_Service_JobService_SearchJobsResponse */ - public static function broadening_location_search(string $companyName, string $location) + public static function broadening_location_search(string $companyName = null, string $location) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); diff --git a/jobs/cjd_sample/test/AutoCompleteSampleTest.php b/jobs/cjd_sample/test/AutoCompleteSampleTest.php new file mode 100644 index 0000000000..d0c4936d8c --- /dev/null +++ b/jobs/cjd_sample/test/AutoCompleteSampleTest.php @@ -0,0 +1,44 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('auto-complete')); + } + + public function testAutoCompleteSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/completionResults.*\'suggestion\' => \'Google\',\s+\'type\' => \'COMPANY_NAME\',' + . '.*completionResults.*\'suggestion\' => \'Software Engineer\',\s+\'type\' => \'JOB_TITLE\',.*' + . '.*completionResults.*\'suggestion\' => \'Software Engineer\',\s+\'type\' => \'JOB_TITLE\',/s'); + } +} From b9c69fa207bf12772af0b29c0e40bab7ebb12157 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 16:48:22 -0700 Subject: [PATCH 06/17] Finish batch operation sample. Used cs fixer to fix code --- jobs/cjd_sample/cjd_sample.php | 1 + jobs/cjd_sample/composer.json | 1 + jobs/cjd_sample/src/auto_complete_sample.php | 3 +- jobs/cjd_sample/src/basic_company_sample.php | 10 +- jobs/cjd_sample/src/basic_job_sample.php | 10 +- .../cjd_sample/src/batch_operation_sample.php | 207 ++++++++++++++++++ .../src/featured_jobs_search_sample.php | 3 +- jobs/cjd_sample/src/general_search_sample.php | 3 +- jobs/cjd_sample/src/job_service_connector.php | 8 +- .../cjd_sample/src/location_search_sample.php | 34 +-- .../test/AutoCompleteSampleTest.php | 1 - .../test/BasicCompanySampleTest.php | 2 +- jobs/cjd_sample/test/BasicJobSampleTest.php | 2 +- .../test/BatchOperationSampleTest.php | 44 ++++ .../test/FeaturedJobsSearchSampleTest.php | 1 - .../test/GeneralSearchSampleTest.php | 3 +- .../test/LocationSearchSampleTest.php | 3 +- 17 files changed, 296 insertions(+), 40 deletions(-) create mode 100644 jobs/cjd_sample/src/batch_operation_sample.php create mode 100644 jobs/cjd_sample/test/BatchOperationSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index 7b13e5e116..32202501e6 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -26,6 +26,7 @@ $application->add(new AutoCompleteSample()); $application->add(new BasicCompanySample()); $application->add(new BasicJobSample()); +$application->add(new BatchOperationSample()); $application->add(new FeaturedJobsSearchSample()); $application->add(new GeneralSearchSample()); $application->add(new LocationSearchSample()); diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index d0d3e4ce31..b2cd14abd1 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -15,6 +15,7 @@ "src/auto_complete_sample.php", "src/basic_company_sample.php", "src/basic_job_sample.php", + "src/batch_operation_sample.php", "src/featured_jobs_search_sample.php", "src/general_search_sample.php", "src/job_service_connector.php", diff --git a/jobs/cjd_sample/src/auto_complete_sample.php b/jobs/cjd_sample/src/auto_complete_sample.php index 007245b7b9..5416fca4ca 100644 --- a/jobs/cjd_sample/src/auto_complete_sample.php +++ b/jobs/cjd_sample/src/auto_complete_sample.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -98,4 +97,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/src/basic_company_sample.php b/jobs/cjd_sample/src/basic_company_sample.php index 2062ff1c98..f24a8c2d09 100644 --- a/jobs/cjd_sample/src/basic_company_sample.php +++ b/jobs/cjd_sample/src/basic_company_sample.php @@ -121,9 +121,11 @@ public static function update_company(string $companyName, Google_Service_JobSer * @param Google_Service_JobService_Company $companyToBeUpdated * @return Google_Service_JobService_Company */ - public static function update_company_with_field_mask(string $companyName, string $fieldMask, - Google_Service_JobService_Company $companyToBeUpdated) - { + public static function update_company_with_field_mask( + string $companyName, + string $fieldMask, + Google_Service_JobService_Company $companyToBeUpdated + ) { $jobService = JobServiceConnector::get_job_service(); $optParams = array('updateCompanyFields' => $fieldMask); @@ -176,4 +178,4 @@ protected function execute(InputInterface $input, OutputInterface $output) self::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/src/basic_job_sample.php b/jobs/cjd_sample/src/basic_job_sample.php index aad8f41b85..7fbc5158a6 100644 --- a/jobs/cjd_sample/src/basic_job_sample.php +++ b/jobs/cjd_sample/src/basic_job_sample.php @@ -129,9 +129,11 @@ public static function update_job(string $jobName, Google_Service_JobService_Job * @param Google_Service_JobService_Job $jobToBeUpdated * @return Google_Service_JobService_Job */ - public static function update_job_with_field_mask(string $jobName, string $fieldMask, - Google_Service_JobService_Job $jobToBeUpdated) - { + public static function update_job_with_field_mask( + string $jobName, + string $fieldMask, + Google_Service_JobService_Job $jobToBeUpdated + ) { $jobService = JobServiceConnector::get_job_service(); $updateJobRequest = new Google_Service_JobService_UpdateJobRequest(); @@ -196,4 +198,4 @@ protected function execute(InputInterface $input, OutputInterface $output) // Delete company only after cleaning all jobs under this company. BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/src/batch_operation_sample.php b/jobs/cjd_sample/src/batch_operation_sample.php new file mode 100644 index 0000000000..e2c3db260f --- /dev/null +++ b/jobs/cjd_sample/src/batch_operation_sample.php @@ -0,0 +1,207 @@ +getClient()->setUseBatch(true); + + $softwareEngineerJob = new Google_Service_JobService_Job(); + $softwareEngineerJob->setCompanyName($companyName); + $softwareEngineerJob->setRequisitionId('123456'); + $softwareEngineerJob->setJobTitle('Software Engineer'); + $softwareEngineerJob->setApplicationUrls(array('https://careers.google.com/')); + $softwareEngineerJob->setDescription('Design, develop, test, deploy, maintain and improve software.'); + + $hardwareEngineerJob = new Google_Service_JobService_Job(); + $hardwareEngineerJob->setCompanyName($companyName); + $hardwareEngineerJob->setRequisitionId('1234567'); + $hardwareEngineerJob->setJobTitle('Hardware Engineer'); + $hardwareEngineerJob->setApplicationUrls(array('https://careers.google.com/')); + $hardwareEngineerJob->setDescription('Design prototype PCBs or modify existing board designs to prototype new features or functions.'); + + // Creates batch request. + $batchCreate = $jobService->createBatch(); + + $createJobRequest1 = new Google_Service_JobService_CreateJobRequest(); + $createJobRequest1->setJob($softwareEngineerJob); + $batchRequest1 = $jobService->jobs->create($createJobRequest1); + $batchCreate->add($batchRequest1); + + $createJobRequest2 = new Google_Service_JobService_CreateJobRequest(); + $createJobRequest2->setJob($hardwareEngineerJob); + $batchRequest2 = $jobService->jobs->create($createJobRequest2); + $batchCreate->add($batchRequest2); + + $results = $batchCreate->execute(); + // Disable batch mode. + $jobService->getClient()->setUseBatch(false); + $createdJobs = array(); + foreach ($results as $result) { + if ($result instanceof Google_Service_Exception) { + printf("Create Error Message:\n%s\n", $result->getMessage()); + } else { + printf("Create Job:\n%s\n", var_export($result, true)); + array_push($createdJobs, $result); + } + } + + return $createdJobs; + } + + # [END batch_job_create] + + # [START batch_job_update] + /** + * Updates jobs in batch. + * + * @param Google_Service_JobService_Job ...$jobsToBeUpdated + * @return array + */ + public static function batch_job_update(Google_Service_JobService_Job ...$jobsToBeUpdated) + { + $jobService = JobServiceConnector::get_job_service(); + $jobService->getClient()->setUseBatch(true); + + // Creates batch request. + $batchUpdate = $jobService->createBatch(); + $i = 0; + foreach ($jobsToBeUpdated as $job) { + if ($i % 2 == 0) { + // You might use Job entity with all fields filled in to do the update + $job->setJobTitle('Engineer in Mountain View'); + $updateRequest = new Google_Service_JobService_UpdateJobRequest(); + $updateRequest->setJob($job); + $batchUpdate->add($jobService->jobs->patch($job->getName(), $updateRequest)); + } else { + // Or just fill in part of field in Job entity and set the updateJobFields + $newJob = new Google_Service_JobService_Job(); + $newJob->setJobTitle('Engineer in Mountain View'); + $newJob->setName($job->getName()); + $updateRequest = new Google_Service_JobService_UpdateJobRequest(); + $updateRequest->setJob($newJob); + $updateRequest->setUpdateJobFields('jobTitle'); + $batchUpdate->add($jobService->jobs->patch($job->getName(), $updateRequest)); + } + $i++; + } + + $results = $batchUpdate->execute(); + // Disable batch mode. + $jobService->getClient()->setUseBatch(false); + $updatedJobs = array(); + foreach ($results as $result) { + if ($result instanceof Google_Service_Exception) { + printf("Update Error Message:\n%s\n", $result->getMessage()); + } else { + printf("Update Job:\n%s\n", var_export($result, true)); + array_push($updatedJobs, $result); + } + } + + return $updatedJobs; + } + # [END batch_job_update] + + # [START batch_job_delete] + /** + * Deletes jobs in batch. + * + * @param Google_Service_JobService_Job ...$jobsToBeDeleted + */ + public static function batch_delete_jobs(Google_Service_JobService_Job ...$jobsToBeDeleted) + { + $jobService = JobServiceConnector::get_job_service(); + $jobService->getClient()->setUseBatch(true); + + // Creates batch request. + $batchDelete = $jobService->createBatch(); + + foreach ($jobsToBeDeleted as $jobToBeDeleted) { + $deleteRequest = $jobService->jobs->delete($jobToBeDeleted->getName()); + $batchDelete->add($deleteRequest); + } + $results = $batchDelete->execute(); + // Disable batch mode. + $jobService->getClient()->setUseBatch(false); + + foreach ($results as $result) { + if ($result instanceof Google_Service_Exception) { + printf("Delete Error Message:\n%s\n", $result->getMessage()); + } else { + echo "Job deleted\n"; + } + } + } + + # [END batch_job_delete] + + protected function configure() + { + $this + ->setName('batch-operation') + ->setDescription('Run batch operation sample script.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Create a company. + $companyName = BasicCompanySample::create_company(BasicCompanySample::generate_company())->getName(); + + // Batch create jobs. + $createdJobs = self::batch_create_jobs($companyName); + + // Batch update jobs. + $updatedJobs = self::batch_job_update(...$createdJobs); + + // Batch delete jobs. + self::batch_delete_jobs(...$updatedJobs); + + BasicCompanySample::delete_company($companyName); + } +} diff --git a/jobs/cjd_sample/src/featured_jobs_search_sample.php b/jobs/cjd_sample/src/featured_jobs_search_sample.php index be63f6d269..f31d884be7 100644 --- a/jobs/cjd_sample/src/featured_jobs_search_sample.php +++ b/jobs/cjd_sample/src/featured_jobs_search_sample.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Google_Service_JobService_Job; use Google_Service_JobService_JobQuery; use Google_Service_JobService_RequestMetadata; @@ -123,4 +122,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/cjd_sample/src/general_search_sample.php index b86ff04ea2..fd8cf678ab 100644 --- a/jobs/cjd_sample/src/general_search_sample.php +++ b/jobs/cjd_sample/src/general_search_sample.php @@ -30,7 +30,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; - /** * The samples in this file introduce how to do a general search, including: * @@ -376,4 +375,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/src/job_service_connector.php b/jobs/cjd_sample/src/job_service_connector.php index f23eb27d9d..cac4a99d57 100644 --- a/jobs/cjd_sample/src/job_service_connector.php +++ b/jobs/cjd_sample/src/job_service_connector.php @@ -8,13 +8,11 @@ namespace Google\Cloud\Samples\Jobs; - use Google_Client; use Google_Service_JobService; final class JobServiceConnector { - private static $jobService; private static function create_job_service() @@ -35,8 +33,8 @@ private static function create_job_service() public static function get_job_service() { if (!isset($jobService)) { - $jobService = self::create_job_service(); + self::$jobService = self::create_job_service(); } - return $jobService; + return self::$jobService; } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/src/location_search_sample.php b/jobs/cjd_sample/src/location_search_sample.php index a22e1e31f3..eb1bca555f 100644 --- a/jobs/cjd_sample/src/location_search_sample.php +++ b/jobs/cjd_sample/src/location_search_sample.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Google_Service_JobService_JobQuery; use Google_Service_JobService_LocationFilter; use Google_Service_JobService_RequestMetadata; @@ -95,9 +94,12 @@ public static function basic_location_search(string $companyName = null, string * @param string $keyword * @return Google_Service_JobService_SearchJobsResponse */ - public static function keyword_location_search(string $companyName = null, string $location, float $distance, - string $keyword) - { + public static function keyword_location_search( + string $companyName = null, + string $location, + float $distance, + string $keyword + ) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); // Make sure to hash your userID @@ -182,9 +184,12 @@ public static function city_location_search(string $companyName = null, string $ * @param string $location2 * @return Google_Service_JobService_SearchJobsResponse */ - public static function multi_locations_search(string $companyName = null, string $location1, float $distance1, - string $location2) - { + public static function multi_locations_search( + string $companyName = null, + string $location1, + float $distance1, + string $location2 + ) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); // Make sure to hash your userID @@ -260,7 +265,6 @@ public static function broadening_location_search(string $companyName = null, st var_export($response); return $response; - } # [END broadening_location_search] @@ -272,16 +276,20 @@ protected function configure() ->setDescription('Run location search sample script to do location search.') ->addOption('location', null, InputOption::VALUE_OPTIONAL, 'The location to search.', 'Mountain View, CA') ->addOption('distance', null, InputOption::VALUE_OPTIONAL, 'Distance in miles to search.', 0.5) - ->addOption('keyword', + ->addOption( + 'keyword', null, InputOption::VALUE_OPTIONAL, 'The keyword used in keyword search sample', - 'Software Engineer') - ->addOption('location2', + 'Software Engineer' + ) + ->addOption( + 'location2', null, InputOption::VALUE_OPTIONAL, 'Second location in multiple locations search sample', - 'Sunnyvale, CA'); + 'Sunnyvale, CA' + ); } protected function execute(InputInterface $input, OutputInterface $output) @@ -320,4 +328,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName2); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/cjd_sample/test/AutoCompleteSampleTest.php b/jobs/cjd_sample/test/AutoCompleteSampleTest.php index d0c4936d8c..7f7b47d85d 100644 --- a/jobs/cjd_sample/test/AutoCompleteSampleTest.php +++ b/jobs/cjd_sample/test/AutoCompleteSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class AutoCompleteSampleTest extends \PHPUnit_Framework_TestCase diff --git a/jobs/cjd_sample/test/BasicCompanySampleTest.php b/jobs/cjd_sample/test/BasicCompanySampleTest.php index 7294d824ea..a56e1d6328 100644 --- a/jobs/cjd_sample/test/BasicCompanySampleTest.php +++ b/jobs/cjd_sample/test/BasicCompanySampleTest.php @@ -30,7 +30,7 @@ public function setUp() } $application = require __DIR__ . '/../cjd_sample.php'; - $this->commandTester = new CommandTester($application->get('basic-company-sample')); + $this->commandTester = new CommandTester($application->get('basic-company')); } public function testBasicCompanySample() diff --git a/jobs/cjd_sample/test/BasicJobSampleTest.php b/jobs/cjd_sample/test/BasicJobSampleTest.php index cf8b0c08f8..f6b209015e 100644 --- a/jobs/cjd_sample/test/BasicJobSampleTest.php +++ b/jobs/cjd_sample/test/BasicJobSampleTest.php @@ -30,7 +30,7 @@ public function setUp() } $application = require __DIR__ . '/../cjd_sample.php'; - $this->commandTester = new CommandTester($application->get('basic-job-sample')); + $this->commandTester = new CommandTester($application->get('basic-job')); } public function testBasicJobSample() diff --git a/jobs/cjd_sample/test/BatchOperationSampleTest.php b/jobs/cjd_sample/test/BatchOperationSampleTest.php new file mode 100644 index 0000000000..bebff03800 --- /dev/null +++ b/jobs/cjd_sample/test/BatchOperationSampleTest.php @@ -0,0 +1,44 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('batch-operation')); + } + + public function testBatchOperationSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/Company generated:.*Company created:.*Create Job:.*Create Job:.*' + . 'Update Job:.*Engineer in Mountain View.*Update Job:.*Engineer in Mountain View.*' + . 'Job deleted.*Job Deleted.*Company deleted./s'); + } +} diff --git a/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php b/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php index 15a0b2b27c..1ed52f38db 100644 --- a/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php +++ b/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class FeaturedJobsSearchSampleTest extends \PHPUnit_Framework_TestCase diff --git a/jobs/cjd_sample/test/GeneralSearchSampleTest.php b/jobs/cjd_sample/test/GeneralSearchSampleTest.php index a82ad841c4..784640e172 100644 --- a/jobs/cjd_sample/test/GeneralSearchSampleTest.php +++ b/jobs/cjd_sample/test/GeneralSearchSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class GeneralSearchSampleTest extends \PHPUnit_Framework_TestCase @@ -31,7 +30,7 @@ public function setUp() } $application = require __DIR__ . '/../cjd_sample.php'; - $this->commandTester = new CommandTester($application->get('general-search-sample')); + $this->commandTester = new CommandTester($application->get('general-search')); } public function testGeneralSearchSample() diff --git a/jobs/cjd_sample/test/LocationSearchSampleTest.php b/jobs/cjd_sample/test/LocationSearchSampleTest.php index a294bd230c..16a61d0260 100644 --- a/jobs/cjd_sample/test/LocationSearchSampleTest.php +++ b/jobs/cjd_sample/test/LocationSearchSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class LocationSearchSampleTest extends \PHPUnit_Framework_TestCase @@ -31,7 +30,7 @@ public function setUp() } $application = require __DIR__ . '/../cjd_sample.php'; - $this->commandTester = new CommandTester($application->get('location-search-sample')); + $this->commandTester = new CommandTester($application->get('location-search')); } public function testLocationSearchSample() From b9c3ec5f16c1e035179d5b9719b03b9746db711c Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 17:04:17 -0700 Subject: [PATCH 07/17] Add commute search sample and its test --- jobs/cjd_sample/cjd_sample.php | 1 + jobs/cjd_sample/composer.json | 1 + jobs/cjd_sample/src/commute_search_sample.php | 109 ++++++++++++++++++ .../test/CommuteSearchSampleTest.php | 42 +++++++ 4 files changed, 153 insertions(+) create mode 100644 jobs/cjd_sample/src/commute_search_sample.php create mode 100644 jobs/cjd_sample/test/CommuteSearchSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index 32202501e6..e0dcb515fb 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -27,6 +27,7 @@ $application->add(new BasicCompanySample()); $application->add(new BasicJobSample()); $application->add(new BatchOperationSample()); +$application->add(new CommuteSearchSample()); $application->add(new FeaturedJobsSearchSample()); $application->add(new GeneralSearchSample()); $application->add(new LocationSearchSample()); diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index b2cd14abd1..7265a5e9d6 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -16,6 +16,7 @@ "src/basic_company_sample.php", "src/basic_job_sample.php", "src/batch_operation_sample.php", + "src/commute_search_sample.php", "src/featured_jobs_search_sample.php", "src/general_search_sample.php", "src/job_service_connector.php", diff --git a/jobs/cjd_sample/src/commute_search_sample.php b/jobs/cjd_sample/src/commute_search_sample.php new file mode 100644 index 0000000000..777d3311ce --- /dev/null +++ b/jobs/cjd_sample/src/commute_search_sample.php @@ -0,0 +1,109 @@ +setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + // Create commute search filter. + $commuteFilter = new Google_Service_JobService_CommutePreference(); + $commuteFilter->setRoadTraffic('TRAFFIC_FREE'); + $commuteFilter->setMethod('TRANSIT'); + $commuteFilter->setTravelTime('1000s'); + $startLocation = new Google_Service_JobService_LatLng(); + $startLocation->setLatitude(37.422408); + $startLocation->setLongitude(-122.085609); + $commuteFilter->setStartLocation($startLocation); + + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCommuteFilter($commuteFilter); + if (isset($companyName)) { + $jobQuery->setCompanyNames(array($companyName)); + } + + $searchRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchRequest->setRequestMetadata($requestMetadata); + $searchRequest->setQuery($jobQuery); + $searchRequest->setJobView('FULL'); + $searchRequest->setEnablePreciseResultSize(true); + + $jobService = JobServiceConnector::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + protected function configure() + { + $this + ->setName('commute-search') + ->setDescription('Run commute search sample script to search based on commute location and time.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Create a company first. + $companyName = BasicCompanySample::create_company(BasicCompanySample::generate_company())->getName(); + + // Create a job with location. + $jobToBeCreated = BasicJobSample::generate_job_with_required_fields($companyName); + $jobToBeCreated->setLocations(array('1600 Amphitheatre Pkwy, Mountain View, CA 94043')); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing. + sleep(10); + self::commute_search($companyName); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} diff --git a/jobs/cjd_sample/test/CommuteSearchSampleTest.php b/jobs/cjd_sample/test/CommuteSearchSampleTest.php new file mode 100644 index 0000000000..59e5e98610 --- /dev/null +++ b/jobs/cjd_sample/test/CommuteSearchSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('commute-search')); + } + + public function testFeaturedJobsSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/.*appliedCommuteFilter.*1600 Amphitheatre Pkwy.*/s'); + } +} From e02b166e7c978523ea4a5fa84f42bc658498cbd9 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 17:16:15 -0700 Subject: [PATCH 08/17] Add email alert search sample and its test --- jobs/cjd_sample/cjd_sample.php | 1 + jobs/cjd_sample/composer.json | 1 + .../src/email_alert_search_sample.php | 90 +++++++++++++++++++ .../test/EmailAlertSearchSampleTest.php | 42 +++++++++ 4 files changed, 134 insertions(+) create mode 100644 jobs/cjd_sample/src/email_alert_search_sample.php create mode 100644 jobs/cjd_sample/test/EmailAlertSearchSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index e0dcb515fb..8b7acf2d36 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -28,6 +28,7 @@ $application->add(new BasicJobSample()); $application->add(new BatchOperationSample()); $application->add(new CommuteSearchSample()); +$application->add(new EmailAlertSearchSample()); $application->add(new FeaturedJobsSearchSample()); $application->add(new GeneralSearchSample()); $application->add(new LocationSearchSample()); diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index 7265a5e9d6..8da92d9b2f 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -17,6 +17,7 @@ "src/basic_job_sample.php", "src/batch_operation_sample.php", "src/commute_search_sample.php", + "src/email_alert_search_sample.php", "src/featured_jobs_search_sample.php", "src/general_search_sample.php", "src/job_service_connector.php", diff --git a/jobs/cjd_sample/src/email_alert_search_sample.php b/jobs/cjd_sample/src/email_alert_search_sample.php new file mode 100644 index 0000000000..cb9ce26d5a --- /dev/null +++ b/jobs/cjd_sample/src/email_alert_search_sample.php @@ -0,0 +1,90 @@ +setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $request = new Google_Service_JobService_SearchJobsRequest(); + $request->setRequestMetadata($requestMetadata); + $request->setMode('JOB_SEARCH'); + if (isset($companyName)) { + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCompanyNames(array($companyName)); + $request->setQuery($jobQuery); + } + + $response = JobServiceConnector::get_job_service()->jobs->searchForAlert($request); + var_export($response); + return $response; + } + + # [END search_for_alerts] + + protected function configure() + { + $this + ->setName('email-alert-search') + ->setDescription('Run email alert search sample script.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + $jobToBeCreated = BasicJobSample::generate_job_with_required_fields($companyName); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing. + sleep(10); + self::search_for_alerts($companyName); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/test/EmailAlertSearchSampleTest.php b/jobs/cjd_sample/test/EmailAlertSearchSampleTest.php new file mode 100644 index 0000000000..48aaf36e66 --- /dev/null +++ b/jobs/cjd_sample/test/EmailAlertSearchSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('email-alert-search')); + } + + public function testFeaturedJobsSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/matchingJobs/'); + } +} From b15029eddd7666a071565d7a36c69545323d8c8c Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 18:01:58 -0700 Subject: [PATCH 09/17] Add custom attribute sample and histogram sample --- jobs/cjd_sample/cjd_sample.php | 2 + jobs/cjd_sample/composer.json | 2 + .../src/custom_attribute_sample.php | 198 ++++++++++++++++++ jobs/cjd_sample/src/histogram_sample.php | 95 +++++++++ .../test/CustomAttributeSampleTest.php | 43 ++++ jobs/cjd_sample/test/HistogramSampleTest.php | 43 ++++ 6 files changed, 383 insertions(+) create mode 100644 jobs/cjd_sample/src/custom_attribute_sample.php create mode 100644 jobs/cjd_sample/src/histogram_sample.php create mode 100644 jobs/cjd_sample/test/CustomAttributeSampleTest.php create mode 100644 jobs/cjd_sample/test/HistogramSampleTest.php diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample/cjd_sample.php index 8b7acf2d36..ccd316cc12 100644 --- a/jobs/cjd_sample/cjd_sample.php +++ b/jobs/cjd_sample/cjd_sample.php @@ -28,8 +28,10 @@ $application->add(new BasicJobSample()); $application->add(new BatchOperationSample()); $application->add(new CommuteSearchSample()); +$application->add(new CustomAttributeSample()); $application->add(new EmailAlertSearchSample()); $application->add(new FeaturedJobsSearchSample()); +$application->add(new HistogramSample()); $application->add(new GeneralSearchSample()); $application->add(new LocationSearchSample()); diff --git a/jobs/cjd_sample/composer.json b/jobs/cjd_sample/composer.json index 8da92d9b2f..8d74b60dd6 100644 --- a/jobs/cjd_sample/composer.json +++ b/jobs/cjd_sample/composer.json @@ -17,9 +17,11 @@ "src/basic_job_sample.php", "src/batch_operation_sample.php", "src/commute_search_sample.php", + "src/custom_attribute_sample.php", "src/email_alert_search_sample.php", "src/featured_jobs_search_sample.php", "src/general_search_sample.php", + "src/histogram_sample.php", "src/job_service_connector.php", "src/location_search_sample.php" ] diff --git a/jobs/cjd_sample/src/custom_attribute_sample.php b/jobs/cjd_sample/src/custom_attribute_sample.php new file mode 100644 index 0000000000..cb35aed7c1 --- /dev/null +++ b/jobs/cjd_sample/src/custom_attribute_sample.php @@ -0,0 +1,198 @@ +setValues(array('value1')); + $customAttribute1->setStringValues($stringValues); + $customAttribute1->setFilterable(true); + $customAttribute2 = new Google_Service_JobService_CustomAttribute(); + $customAttribute2->setLongValue(256); + $customAttribute2->setFilterable(true); + $customAttributes = array('someFieldName1' => $customAttribute1, 'someFieldName2' => $customAttribute2); + + // Creates job with custom attributes. + $job = new Google_Service_JobService_Job(); + $job->setCompanyName($companyName); + $job->setRequisitionId($requisitionId); + $job->setJobTitle('Software Engineer'); + $job->setApplicationUrls(array('https://careers.google.com/')); + $job->setDescription('Design, develop, test, deploy, maintain and improve software.'); + $job->setCustomAttributes($customAttributes); + + printf("Job generated:\n%s\n", var_export($job, true)); + return $job; + } + # [END custom_attribute_job] + + # [START custom_attribute_filter_string_value] + /** + * CustomAttributeFilter on String value CustomAttribute + * + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function filters_on_string_value_custom_attribute() + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $customAttributeFilter = 'NOT EMPTY(someFieldName1)'; + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCustomAttributeFilter($customAttributeFilter); + + $searchJobsRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchJobsRequest->setQuery($jobQuery); + $searchJobsRequest->setRequestMetadata($requestMetadata); + $searchJobsRequest->setJobView('FULL'); + + $response = JobServiceConnector::get_job_service()->jobs->search($searchJobsRequest); + var_export($response); + return $response; + } + # [END custom_attribute_filter_string_value] + + # [START custom_attribute_filter_long_value] + /** + * CustomAttributeFilter on Long value CustomAttribute + * + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function filters_on_long_value_custom_attribute() + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $customAttributeFilter = '(255 <= someFieldName2) AND (someFieldName2 <= 257)'; + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCustomAttributeFilter($customAttributeFilter); + + $searchJobsRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchJobsRequest->setQuery($jobQuery); + $searchJobsRequest->setRequestMetadata($requestMetadata); + $searchJobsRequest->setJobView('FULL'); + + $response = JobServiceConnector::get_job_service()->jobs->search($searchJobsRequest); + var_export($response); + return $response; + } + # [END custom_attribute_filter_long_value] + + # [START custom_attribute_filter_multi_attributes] + /** + * CustomAttributeFilter on multiple CustomAttributes + * + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function filters_on_multi_custom_attribute() + { + // Make sure to set the requestMetadata the same as the associated search request + $requestMetadata = new Google_Service_JobService_RequestMetadata(); + // Make sure to hash your userID + $requestMetadata->setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + $customAttributeFilter = '(someFieldName1 = "value1") AND ((255 <= someFieldName2) OR (someFieldName2 <= 213))'; + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCustomAttributeFilter($customAttributeFilter); + + $searchJobsRequest = new Google_Service_JobService_SearchJobsRequest(); + $searchJobsRequest->setQuery($jobQuery); + $searchJobsRequest->setRequestMetadata($requestMetadata); + $searchJobsRequest->setJobView('FULL'); + + $response = JobServiceConnector::get_job_service()->jobs->search($searchJobsRequest); + var_export($response); + return $response; + } + + # [END custom_attribute_filter_multi_attributes] + + protected function configure() + { + $this + ->setName('custom-attribute') + ->setDescription('Run custom attribute sample script to search on custom attributes.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + $jobToBeCreated = self::generate_job_with_a_custom_attribute($companyName); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing + sleep(10); + self::filters_on_string_value_custom_attribute(); + self::filters_on_long_value_custom_attribute(); + self::filters_on_multi_custom_attribute(); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/src/histogram_sample.php b/jobs/cjd_sample/src/histogram_sample.php new file mode 100644 index 0000000000..f0ef7eb0e4 --- /dev/null +++ b/jobs/cjd_sample/src/histogram_sample.php @@ -0,0 +1,95 @@ +setUserId('HashedUserId'); + // Make sure to hash the sessionID + $requestMetadata->setSessionId('HashedSessionId'); + // Domain of the website where the search is conducted + $requestMetadata->setDomain('www.google.com'); + + // Constructs HistogramFacets. + $histogramFacets = new Google_Service_JobService_HistogramFacets(); + $histogramFacets->setSimpleHistogramFacets(array('COMPANY_ID')); + $customAttributeHistogramRequest = new Google_Service_JobService_CustomAttributeHistogramRequest(); + $customAttributeHistogramRequest->setKey('someFieldName1'); + $customAttributeHistogramRequest->setStringValueHistogram(true); + $histogramFacets->setCustomAttributeHistogramFacets($customAttributeHistogramRequest); + + // Send search request. + $request = new Google_Service_JobService_SearchJobsRequest(); + $request->setRequestMetadata($requestMetadata); + $request->setMode('JOB_SEARCH'); + $request->setHistogramFacets($histogramFacets); + if (isset($companyName)) { + $jobQuery = new Google_Service_JobService_JobQuery(); + $jobQuery->setCompanyNames(array($companyName)); + $request->setQuery($jobQuery); + } + + $response = JobServiceConnector::get_job_service()->jobs->search($request); + var_export($response); + return $response; + } + + # [END histogram_search] + + protected function configure() + { + $this + ->setName('histogram') + ->setDescription('Run histogram sample script.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $companyToBeCreated = BasicCompanySample::generate_company(); + $companyName = BasicCompanySample::create_company($companyToBeCreated)->getName(); + + $jobToBeCreated = CustomAttributeSample::generate_job_with_a_custom_attribute($companyName); + $jobName = BasicJobSample::create_job($jobToBeCreated)->getName(); + + // Wait several seconds for post processing + sleep(10); + self::histogram_search($companyName); + + BasicJobSample::delete_job($jobName); + BasicCompanySample::delete_company($companyName); + } +} \ No newline at end of file diff --git a/jobs/cjd_sample/test/CustomAttributeSampleTest.php b/jobs/cjd_sample/test/CustomAttributeSampleTest.php new file mode 100644 index 0000000000..fd06e149e6 --- /dev/null +++ b/jobs/cjd_sample/test/CustomAttributeSampleTest.php @@ -0,0 +1,43 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('custom-attribute')); + } + + public function testCustomAttributeSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/Job created:.*jobWithACustomAttribute.*matchingJobs.*jobWithACustomAttribute' + . '.*matchingJobs.*jobWithACustomAttribute.*matchingJobs.*jobWithACustomAttribute/s'); + } +} diff --git a/jobs/cjd_sample/test/HistogramSampleTest.php b/jobs/cjd_sample/test/HistogramSampleTest.php new file mode 100644 index 0000000000..0a1dddd09a --- /dev/null +++ b/jobs/cjd_sample/test/HistogramSampleTest.php @@ -0,0 +1,43 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../cjd_sample.php'; + $this->commandTester = new CommandTester($application->get('histogram')); + } + + public function testHistogramSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/COMPANY_ID/'); + $this->expectOutputRegex('/someFieldName1/'); + } +} From 5cf5d4c69ded708ee347c4dacb023b5a35278f94 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 18:08:24 -0700 Subject: [PATCH 10/17] clean PHP doc --- jobs/cjd_sample/src/auto_complete_sample.php | 15 +++++++++++++++ jobs/cjd_sample/src/basic_company_sample.php | 8 +++++++- .../src/featured_jobs_search_sample.php | 2 +- jobs/cjd_sample/src/general_search_sample.php | 14 +++++++------- jobs/cjd_sample/src/histogram_sample.php | 7 +++++++ jobs/cjd_sample/src/job_service_connector.php | 5 +++++ jobs/cjd_sample/src/location_search_sample.php | 16 +++++++++------- 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/jobs/cjd_sample/src/auto_complete_sample.php b/jobs/cjd_sample/src/auto_complete_sample.php index 5416fca4ca..022767b324 100644 --- a/jobs/cjd_sample/src/auto_complete_sample.php +++ b/jobs/cjd_sample/src/auto_complete_sample.php @@ -17,6 +17,7 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Service_JobService_CompleteQueryResponse; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -31,6 +32,13 @@ final class AutoCompleteSample extends Command { # [START auto_complete_job_title] + /** + * Auto completes job titles within given companyName. + * + * @param string|null $companyName + * @param string $query + * @return Google_Service_JobService_CompleteQueryResponse + */ public static function job_title_auto_complete(string $companyName = null, string $query) { $optParams = array( @@ -52,6 +60,13 @@ public static function job_title_auto_complete(string $companyName = null, strin # [END auto_complete_job_title] # [START auto_complete_default] + /** + * Auto completes job titles within given companyName. + * + * @param string|null $companyName + * @param string $query + * @return Google_Service_JobService_CompleteQueryResponse + */ public static function default_auto_complete(string $companyName = null, string $query) { $optParams = array( diff --git a/jobs/cjd_sample/src/basic_company_sample.php b/jobs/cjd_sample/src/basic_company_sample.php index f24a8c2d09..f51063308c 100644 --- a/jobs/cjd_sample/src/basic_company_sample.php +++ b/jobs/cjd_sample/src/basic_company_sample.php @@ -125,7 +125,8 @@ public static function update_company_with_field_mask( string $companyName, string $fieldMask, Google_Service_JobService_Company $companyToBeUpdated - ) { + ) + { $jobService = JobServiceConnector::get_job_service(); $optParams = array('updateCompanyFields' => $fieldMask); @@ -136,6 +137,11 @@ public static function update_company_with_field_mask( # [END update_company_with_field_mask] # [START delete_company] + /** + * Deletes a company. + * + * @param string $companyName + */ public static function delete_company(string $companyName) { $jobService = JobServiceConnector::get_job_service(); diff --git a/jobs/cjd_sample/src/featured_jobs_search_sample.php b/jobs/cjd_sample/src/featured_jobs_search_sample.php index f31d884be7..c2b61237bb 100644 --- a/jobs/cjd_sample/src/featured_jobs_search_sample.php +++ b/jobs/cjd_sample/src/featured_jobs_search_sample.php @@ -64,7 +64,7 @@ public static function generate_featured_job(string $companyName) /** * Searches featured jobs. * - * @param string $companyName + * @param string|null $companyName * @return Google_Service_JobService_SearchJobsResponse */ public static function search_featured_jobs(string $companyName = null) diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/cjd_sample/src/general_search_sample.php index fd8cf678ab..d8b360a0bc 100644 --- a/jobs/cjd_sample/src/general_search_sample.php +++ b/jobs/cjd_sample/src/general_search_sample.php @@ -53,7 +53,7 @@ final class GeneralSearchSample extends Command /** * Simple job search with keyword. * - * @param string $companyName + * @param string|null $companyName * @param string $query * @return Google_Service_JobService_SearchJobsResponse */ @@ -92,7 +92,7 @@ public static function basic_search_jobs(string $companyName = null, string $que /** * Search on category filter. * - * @param string $companyName + * @param string|null $companyName * @param string ...$categories * @return Google_Service_JobService_SearchJobsResponse */ @@ -130,7 +130,7 @@ public static function category_filter_search(string $companyName = null, string /** * Search on employment types. * - * @param string $companyName + * @param string|null $companyName * @param string ...$employmentTypes * @return Google_Service_JobService_SearchJobsResponse */ @@ -168,7 +168,7 @@ public static function employment_types_search(string $companyName = null, strin /** * Search by date range. * - * @param string $companyName + * @param string|null $companyName * @param string $dateRange * @return Google_Service_JobService_SearchJobsResponse */ @@ -206,7 +206,7 @@ public static function date_range_search(string $companyName = null, string $dat /** * Search by language code. * - * @param string $companyName + * @param string|null $companyName * @param string ...$languageCodes * @return Google_Service_JobService_SearchJobsResponse */ @@ -244,7 +244,7 @@ public static function language_code_search(string $companyName = null, string . /** * Search on company display name. * - * @param string $companyName + * @param string|null $companyName * @param string ...$companyDisplayNames * @return Google_Service_JobService_SearchJobsResponse */ @@ -282,7 +282,7 @@ public static function company_display_name_search(string $companyName = null, s /** * Search on compensation. * - * @param string $companyName + * @param string|null $companyName * @return Google_Service_JobService_SearchJobsResponse */ public static function compensation_search(string $companyName = null) diff --git a/jobs/cjd_sample/src/histogram_sample.php b/jobs/cjd_sample/src/histogram_sample.php index f0ef7eb0e4..f510c12055 100644 --- a/jobs/cjd_sample/src/histogram_sample.php +++ b/jobs/cjd_sample/src/histogram_sample.php @@ -23,6 +23,7 @@ use Google_Service_JobService_JobQuery; use Google_Service_JobService_RequestMetadata; use Google_Service_JobService_SearchJobsRequest; +use Google_Service_JobService_SearchJobsResponse; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -33,6 +34,12 @@ final class HistogramSample extends Command { # [START histogram_search] + /** + * Histogram search. + * + * @param string|null $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ public static function histogram_search(string $companyName = null) { // Make sure to set the requestMetadata the same as the associated search request diff --git a/jobs/cjd_sample/src/job_service_connector.php b/jobs/cjd_sample/src/job_service_connector.php index cac4a99d57..aac302bcc4 100644 --- a/jobs/cjd_sample/src/job_service_connector.php +++ b/jobs/cjd_sample/src/job_service_connector.php @@ -30,6 +30,11 @@ private static function create_job_service() return $jobService; } + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ public static function get_job_service() { if (!isset($jobService)) { diff --git a/jobs/cjd_sample/src/location_search_sample.php b/jobs/cjd_sample/src/location_search_sample.php index eb1bca555f..f845870908 100644 --- a/jobs/cjd_sample/src/location_search_sample.php +++ b/jobs/cjd_sample/src/location_search_sample.php @@ -46,7 +46,7 @@ final class LocationSearchSample extends Command /** * Basic location search. * - * @param string $companyName + * @param string|null $companyName * @param string $location * @param float $distance * @return Google_Service_JobService_SearchJobsResponse @@ -88,7 +88,7 @@ public static function basic_location_search(string $companyName = null, string /** * Keyword location search. * - * @param string $companyName + * @param string|null $companyName * @param string $location * @param float $distance * @param string $keyword @@ -99,7 +99,8 @@ public static function keyword_location_search( string $location, float $distance, string $keyword - ) { + ) + { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); // Make sure to hash your userID @@ -137,7 +138,7 @@ public static function keyword_location_search( /** * City location search. * - * @param string $companyName + * @param string|null $companyName * @param string $location * @return Google_Service_JobService_SearchJobsResponse */ @@ -178,7 +179,7 @@ public static function city_location_search(string $companyName = null, string $ /** * Multiple locations search. * - * @param string $companyName + * @param string|null $companyName * @param string $location1 * @param float $distance1 * @param string $location2 @@ -189,7 +190,8 @@ public static function multi_locations_search( string $location1, float $distance1, string $location2 - ) { + ) + { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); // Make sure to hash your userID @@ -229,7 +231,7 @@ public static function multi_locations_search( /** * Broadening location search. * - * @param string $companyName + * @param string|null $companyName * @param string $location * @return Google_Service_JobService_SearchJobsResponse */ From a4326246c517b7e9b1cec282144410904a0e51a4 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Wed, 11 Jul 2018 19:35:28 -0700 Subject: [PATCH 11/17] Fix one test --- jobs/cjd_sample/test/BatchOperationSampleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jobs/cjd_sample/test/BatchOperationSampleTest.php b/jobs/cjd_sample/test/BatchOperationSampleTest.php index bebff03800..20cb7d0b65 100644 --- a/jobs/cjd_sample/test/BatchOperationSampleTest.php +++ b/jobs/cjd_sample/test/BatchOperationSampleTest.php @@ -39,6 +39,6 @@ public function testBatchOperationSample() $this->commandTester->execute([], ['interactive' => false]); $this->expectOutputRegex('/Company generated:.*Company created:.*Create Job:.*Create Job:.*' . 'Update Job:.*Engineer in Mountain View.*Update Job:.*Engineer in Mountain View.*' - . 'Job deleted.*Job Deleted.*Company deleted./s'); + . 'Job deleted.*Job deleted.*Company deleted./s'); } } From ed263176d93410f122a4896192a5244138af883d Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Thu, 12 Jul 2018 16:07:09 -0700 Subject: [PATCH 12/17] Remove cjd_sample directory, move all files under jobs --- jobs/{cjd_sample => }/README.md | 0 jobs/{cjd_sample => }/cjd_sample.php | 0 jobs/{cjd_sample => }/composer.json | 0 jobs/{cjd_sample => }/composer.lock | 0 jobs/{cjd_sample => }/phpunit.xml.dist | 0 jobs/{cjd_sample => }/quickstart.php | 0 jobs/{cjd_sample => }/src/auto_complete_sample.php | 0 jobs/{cjd_sample => }/src/basic_company_sample.php | 0 jobs/{cjd_sample => }/src/basic_job_sample.php | 0 jobs/{cjd_sample => }/src/batch_operation_sample.php | 0 jobs/{cjd_sample => }/src/commute_search_sample.php | 0 jobs/{cjd_sample => }/src/custom_attribute_sample.php | 0 jobs/{cjd_sample => }/src/email_alert_search_sample.php | 0 jobs/{cjd_sample => }/src/featured_jobs_search_sample.php | 0 jobs/{cjd_sample => }/src/general_search_sample.php | 0 jobs/{cjd_sample => }/src/histogram_sample.php | 0 jobs/{cjd_sample => }/src/job_service_connector.php | 0 jobs/{cjd_sample => }/src/location_search_sample.php | 0 jobs/{cjd_sample => }/test/AutoCompleteSampleTest.php | 0 jobs/{cjd_sample => }/test/BasicCompanySampleTest.php | 0 jobs/{cjd_sample => }/test/BasicJobSampleTest.php | 0 jobs/{cjd_sample => }/test/BatchOperationSampleTest.php | 0 jobs/{cjd_sample => }/test/CommuteSearchSampleTest.php | 0 jobs/{cjd_sample => }/test/CustomAttributeSampleTest.php | 0 jobs/{cjd_sample => }/test/EmailAlertSearchSampleTest.php | 0 jobs/{cjd_sample => }/test/FeaturedJobsSearchSampleTest.php | 0 jobs/{cjd_sample => }/test/GeneralSearchSampleTest.php | 0 jobs/{cjd_sample => }/test/HistogramSampleTest.php | 0 jobs/{cjd_sample => }/test/LocationSearchSampleTest.php | 0 29 files changed, 0 insertions(+), 0 deletions(-) rename jobs/{cjd_sample => }/README.md (100%) rename jobs/{cjd_sample => }/cjd_sample.php (100%) rename jobs/{cjd_sample => }/composer.json (100%) rename jobs/{cjd_sample => }/composer.lock (100%) rename jobs/{cjd_sample => }/phpunit.xml.dist (100%) rename jobs/{cjd_sample => }/quickstart.php (100%) rename jobs/{cjd_sample => }/src/auto_complete_sample.php (100%) rename jobs/{cjd_sample => }/src/basic_company_sample.php (100%) rename jobs/{cjd_sample => }/src/basic_job_sample.php (100%) rename jobs/{cjd_sample => }/src/batch_operation_sample.php (100%) rename jobs/{cjd_sample => }/src/commute_search_sample.php (100%) rename jobs/{cjd_sample => }/src/custom_attribute_sample.php (100%) rename jobs/{cjd_sample => }/src/email_alert_search_sample.php (100%) rename jobs/{cjd_sample => }/src/featured_jobs_search_sample.php (100%) rename jobs/{cjd_sample => }/src/general_search_sample.php (100%) rename jobs/{cjd_sample => }/src/histogram_sample.php (100%) rename jobs/{cjd_sample => }/src/job_service_connector.php (100%) rename jobs/{cjd_sample => }/src/location_search_sample.php (100%) rename jobs/{cjd_sample => }/test/AutoCompleteSampleTest.php (100%) rename jobs/{cjd_sample => }/test/BasicCompanySampleTest.php (100%) rename jobs/{cjd_sample => }/test/BasicJobSampleTest.php (100%) rename jobs/{cjd_sample => }/test/BatchOperationSampleTest.php (100%) rename jobs/{cjd_sample => }/test/CommuteSearchSampleTest.php (100%) rename jobs/{cjd_sample => }/test/CustomAttributeSampleTest.php (100%) rename jobs/{cjd_sample => }/test/EmailAlertSearchSampleTest.php (100%) rename jobs/{cjd_sample => }/test/FeaturedJobsSearchSampleTest.php (100%) rename jobs/{cjd_sample => }/test/GeneralSearchSampleTest.php (100%) rename jobs/{cjd_sample => }/test/HistogramSampleTest.php (100%) rename jobs/{cjd_sample => }/test/LocationSearchSampleTest.php (100%) diff --git a/jobs/cjd_sample/README.md b/jobs/README.md similarity index 100% rename from jobs/cjd_sample/README.md rename to jobs/README.md diff --git a/jobs/cjd_sample/cjd_sample.php b/jobs/cjd_sample.php similarity index 100% rename from jobs/cjd_sample/cjd_sample.php rename to jobs/cjd_sample.php diff --git a/jobs/cjd_sample/composer.json b/jobs/composer.json similarity index 100% rename from jobs/cjd_sample/composer.json rename to jobs/composer.json diff --git a/jobs/cjd_sample/composer.lock b/jobs/composer.lock similarity index 100% rename from jobs/cjd_sample/composer.lock rename to jobs/composer.lock diff --git a/jobs/cjd_sample/phpunit.xml.dist b/jobs/phpunit.xml.dist similarity index 100% rename from jobs/cjd_sample/phpunit.xml.dist rename to jobs/phpunit.xml.dist diff --git a/jobs/cjd_sample/quickstart.php b/jobs/quickstart.php similarity index 100% rename from jobs/cjd_sample/quickstart.php rename to jobs/quickstart.php diff --git a/jobs/cjd_sample/src/auto_complete_sample.php b/jobs/src/auto_complete_sample.php similarity index 100% rename from jobs/cjd_sample/src/auto_complete_sample.php rename to jobs/src/auto_complete_sample.php diff --git a/jobs/cjd_sample/src/basic_company_sample.php b/jobs/src/basic_company_sample.php similarity index 100% rename from jobs/cjd_sample/src/basic_company_sample.php rename to jobs/src/basic_company_sample.php diff --git a/jobs/cjd_sample/src/basic_job_sample.php b/jobs/src/basic_job_sample.php similarity index 100% rename from jobs/cjd_sample/src/basic_job_sample.php rename to jobs/src/basic_job_sample.php diff --git a/jobs/cjd_sample/src/batch_operation_sample.php b/jobs/src/batch_operation_sample.php similarity index 100% rename from jobs/cjd_sample/src/batch_operation_sample.php rename to jobs/src/batch_operation_sample.php diff --git a/jobs/cjd_sample/src/commute_search_sample.php b/jobs/src/commute_search_sample.php similarity index 100% rename from jobs/cjd_sample/src/commute_search_sample.php rename to jobs/src/commute_search_sample.php diff --git a/jobs/cjd_sample/src/custom_attribute_sample.php b/jobs/src/custom_attribute_sample.php similarity index 100% rename from jobs/cjd_sample/src/custom_attribute_sample.php rename to jobs/src/custom_attribute_sample.php diff --git a/jobs/cjd_sample/src/email_alert_search_sample.php b/jobs/src/email_alert_search_sample.php similarity index 100% rename from jobs/cjd_sample/src/email_alert_search_sample.php rename to jobs/src/email_alert_search_sample.php diff --git a/jobs/cjd_sample/src/featured_jobs_search_sample.php b/jobs/src/featured_jobs_search_sample.php similarity index 100% rename from jobs/cjd_sample/src/featured_jobs_search_sample.php rename to jobs/src/featured_jobs_search_sample.php diff --git a/jobs/cjd_sample/src/general_search_sample.php b/jobs/src/general_search_sample.php similarity index 100% rename from jobs/cjd_sample/src/general_search_sample.php rename to jobs/src/general_search_sample.php diff --git a/jobs/cjd_sample/src/histogram_sample.php b/jobs/src/histogram_sample.php similarity index 100% rename from jobs/cjd_sample/src/histogram_sample.php rename to jobs/src/histogram_sample.php diff --git a/jobs/cjd_sample/src/job_service_connector.php b/jobs/src/job_service_connector.php similarity index 100% rename from jobs/cjd_sample/src/job_service_connector.php rename to jobs/src/job_service_connector.php diff --git a/jobs/cjd_sample/src/location_search_sample.php b/jobs/src/location_search_sample.php similarity index 100% rename from jobs/cjd_sample/src/location_search_sample.php rename to jobs/src/location_search_sample.php diff --git a/jobs/cjd_sample/test/AutoCompleteSampleTest.php b/jobs/test/AutoCompleteSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/AutoCompleteSampleTest.php rename to jobs/test/AutoCompleteSampleTest.php diff --git a/jobs/cjd_sample/test/BasicCompanySampleTest.php b/jobs/test/BasicCompanySampleTest.php similarity index 100% rename from jobs/cjd_sample/test/BasicCompanySampleTest.php rename to jobs/test/BasicCompanySampleTest.php diff --git a/jobs/cjd_sample/test/BasicJobSampleTest.php b/jobs/test/BasicJobSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/BasicJobSampleTest.php rename to jobs/test/BasicJobSampleTest.php diff --git a/jobs/cjd_sample/test/BatchOperationSampleTest.php b/jobs/test/BatchOperationSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/BatchOperationSampleTest.php rename to jobs/test/BatchOperationSampleTest.php diff --git a/jobs/cjd_sample/test/CommuteSearchSampleTest.php b/jobs/test/CommuteSearchSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/CommuteSearchSampleTest.php rename to jobs/test/CommuteSearchSampleTest.php diff --git a/jobs/cjd_sample/test/CustomAttributeSampleTest.php b/jobs/test/CustomAttributeSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/CustomAttributeSampleTest.php rename to jobs/test/CustomAttributeSampleTest.php diff --git a/jobs/cjd_sample/test/EmailAlertSearchSampleTest.php b/jobs/test/EmailAlertSearchSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/EmailAlertSearchSampleTest.php rename to jobs/test/EmailAlertSearchSampleTest.php diff --git a/jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php b/jobs/test/FeaturedJobsSearchSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/FeaturedJobsSearchSampleTest.php rename to jobs/test/FeaturedJobsSearchSampleTest.php diff --git a/jobs/cjd_sample/test/GeneralSearchSampleTest.php b/jobs/test/GeneralSearchSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/GeneralSearchSampleTest.php rename to jobs/test/GeneralSearchSampleTest.php diff --git a/jobs/cjd_sample/test/HistogramSampleTest.php b/jobs/test/HistogramSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/HistogramSampleTest.php rename to jobs/test/HistogramSampleTest.php diff --git a/jobs/cjd_sample/test/LocationSearchSampleTest.php b/jobs/test/LocationSearchSampleTest.php similarity index 100% rename from jobs/cjd_sample/test/LocationSearchSampleTest.php rename to jobs/test/LocationSearchSampleTest.php From b36f61bc961319255599c5826a1a3701ab950c64 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Thu, 12 Jul 2018 16:09:20 -0700 Subject: [PATCH 13/17] Remove unnesseary lines from composer.json --- jobs/composer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jobs/composer.json b/jobs/composer.json index 8d74b60dd6..9f796723c2 100644 --- a/jobs/composer.json +++ b/jobs/composer.json @@ -1,16 +1,12 @@ { "require": { "google/apiclient": "^2.1", - "google/apiclient-services": "^0.64", "symfony/console": " ^3.0" }, "require-dev": { "phpunit/phpunit": "~4.0" }, "autoload": { - "psr-4": { - "Google\\Cloud\\Samples\\Language\\": "src/" - }, "files": [ "src/auto_complete_sample.php", "src/basic_company_sample.php", From 9aedd31a5dee7b8ae59d79485043066f3051737d Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Fri, 13 Jul 2018 10:05:12 -0700 Subject: [PATCH 14/17] Rename cjd_sample.php to jobs.php --- jobs/README.md | 10 +++++----- jobs/composer.lock | 2 +- jobs/{cjd_sample.php => jobs.php} | 0 jobs/test/AutoCompleteSampleTest.php | 2 +- jobs/test/BasicCompanySampleTest.php | 2 +- jobs/test/BasicJobSampleTest.php | 2 +- jobs/test/BatchOperationSampleTest.php | 2 +- jobs/test/CommuteSearchSampleTest.php | 2 +- jobs/test/CustomAttributeSampleTest.php | 2 +- jobs/test/EmailAlertSearchSampleTest.php | 2 +- jobs/test/FeaturedJobsSearchSampleTest.php | 2 +- jobs/test/GeneralSearchSampleTest.php | 2 +- jobs/test/HistogramSampleTest.php | 2 +- jobs/test/LocationSearchSampleTest.php | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) rename jobs/{cjd_sample.php => jobs.php} (100%) diff --git a/jobs/README.md b/jobs/README.md index e0a4f82aac..67cae5ad11 100644 --- a/jobs/README.md +++ b/jobs/README.md @@ -9,16 +9,16 @@ These samples show how to use the [Google Cloud Job Discovery API] 1. **Enable APIs** - [Enable the Job Discovery API](https://console.cloud.google.com/flows/enableapi?apiid=jobs.googleapis.com) and create a new project or select an existing project. 2. **Activate your Credentials** - If you do not already have an active set of credentials, create and download a [JSON Service Account key](https://pantheon.corp.google.com/apis/credentials/serviceaccountkey). Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` as the path to the downloaded JSON file. -4. **Clone the repo** and cd into this directory +3. **Clone the repo** and cd into this directory ``` $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples - $ cd php-docs-samples/jobs/cjd_sample -``` -5. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md). + $ cd php-docs-samples/jobs + ``` +4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md). Run `php composer.phar install` (if composer is installed locally) or `composer install` (if composer is installed globally). -6. Run `php quickstart.php`. +5. Run `php quickstart.php`. ## Contributing changes diff --git a/jobs/composer.lock b/jobs/composer.lock index 979f5aa9fe..235d14fd2f 100644 --- a/jobs/composer.lock +++ b/jobs/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4190f32a9bdb93d261931a5f6bcfa366", + "content-hash": "216c1e5029f1c5f992c9178895aba355", "packages": [ { "name": "firebase/php-jwt", diff --git a/jobs/cjd_sample.php b/jobs/jobs.php similarity index 100% rename from jobs/cjd_sample.php rename to jobs/jobs.php diff --git a/jobs/test/AutoCompleteSampleTest.php b/jobs/test/AutoCompleteSampleTest.php index 7f7b47d85d..94d8935b01 100644 --- a/jobs/test/AutoCompleteSampleTest.php +++ b/jobs/test/AutoCompleteSampleTest.php @@ -29,7 +29,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('auto-complete')); } diff --git a/jobs/test/BasicCompanySampleTest.php b/jobs/test/BasicCompanySampleTest.php index a56e1d6328..0ae68ee159 100644 --- a/jobs/test/BasicCompanySampleTest.php +++ b/jobs/test/BasicCompanySampleTest.php @@ -29,7 +29,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('basic-company')); } diff --git a/jobs/test/BasicJobSampleTest.php b/jobs/test/BasicJobSampleTest.php index f6b209015e..86ccc9b3f0 100644 --- a/jobs/test/BasicJobSampleTest.php +++ b/jobs/test/BasicJobSampleTest.php @@ -29,7 +29,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('basic-job')); } diff --git a/jobs/test/BatchOperationSampleTest.php b/jobs/test/BatchOperationSampleTest.php index 20cb7d0b65..b46020f3fd 100644 --- a/jobs/test/BatchOperationSampleTest.php +++ b/jobs/test/BatchOperationSampleTest.php @@ -30,7 +30,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('batch-operation')); } diff --git a/jobs/test/CommuteSearchSampleTest.php b/jobs/test/CommuteSearchSampleTest.php index 59e5e98610..a418d0d443 100644 --- a/jobs/test/CommuteSearchSampleTest.php +++ b/jobs/test/CommuteSearchSampleTest.php @@ -30,7 +30,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('commute-search')); } diff --git a/jobs/test/CustomAttributeSampleTest.php b/jobs/test/CustomAttributeSampleTest.php index fd06e149e6..b77d85c803 100644 --- a/jobs/test/CustomAttributeSampleTest.php +++ b/jobs/test/CustomAttributeSampleTest.php @@ -30,7 +30,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('custom-attribute')); } diff --git a/jobs/test/EmailAlertSearchSampleTest.php b/jobs/test/EmailAlertSearchSampleTest.php index 48aaf36e66..26382655b9 100644 --- a/jobs/test/EmailAlertSearchSampleTest.php +++ b/jobs/test/EmailAlertSearchSampleTest.php @@ -30,7 +30,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('email-alert-search')); } diff --git a/jobs/test/FeaturedJobsSearchSampleTest.php b/jobs/test/FeaturedJobsSearchSampleTest.php index 1ed52f38db..db216190b8 100644 --- a/jobs/test/FeaturedJobsSearchSampleTest.php +++ b/jobs/test/FeaturedJobsSearchSampleTest.php @@ -29,7 +29,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('featured-jobs-search')); } diff --git a/jobs/test/GeneralSearchSampleTest.php b/jobs/test/GeneralSearchSampleTest.php index 784640e172..41fd3a22d3 100644 --- a/jobs/test/GeneralSearchSampleTest.php +++ b/jobs/test/GeneralSearchSampleTest.php @@ -29,7 +29,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('general-search')); } diff --git a/jobs/test/HistogramSampleTest.php b/jobs/test/HistogramSampleTest.php index 0a1dddd09a..dfbf5b0bb3 100644 --- a/jobs/test/HistogramSampleTest.php +++ b/jobs/test/HistogramSampleTest.php @@ -30,7 +30,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('histogram')); } diff --git a/jobs/test/LocationSearchSampleTest.php b/jobs/test/LocationSearchSampleTest.php index 16a61d0260..db04b570a8 100644 --- a/jobs/test/LocationSearchSampleTest.php +++ b/jobs/test/LocationSearchSampleTest.php @@ -29,7 +29,7 @@ public function setUp() return $this->markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); } - $application = require __DIR__ . '/../cjd_sample.php'; + $application = require __DIR__ . '/../jobs.php'; $this->commandTester = new CommandTester($application->get('location-search')); } From 16ace968718c3047fcead142379fd78f54065457 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Fri, 13 Jul 2018 10:15:16 -0700 Subject: [PATCH 15/17] Remove job_service_connector.php, repeat creating jobService in each sample --- jobs/jobs.php | 2 +- jobs/src/auto_complete_sample.php | 41 +++++++++++++++++- jobs/src/basic_company_sample.php | 49 ++++++++++++++++++---- jobs/src/basic_job_sample.php | 47 ++++++++++++++++++--- jobs/src/batch_operation_sample.php | 43 +++++++++++++++++-- jobs/src/commute_search_sample.php | 41 +++++++++++++++++- jobs/src/custom_attribute_sample.php | 46 +++++++++++++++++--- jobs/src/email_alert_search_sample.php | 42 +++++++++++++++++-- jobs/src/featured_jobs_search_sample.php | 39 ++++++++++++++++- jobs/src/general_search_sample.php | 50 ++++++++++++++++++---- jobs/src/histogram_sample.php | 42 +++++++++++++++++-- jobs/src/job_service_connector.php | 45 -------------------- jobs/src/location_search_sample.php | 53 ++++++++++++++++++++---- jobs/test/BatchOperationSampleTest.php | 1 - jobs/test/CommuteSearchSampleTest.php | 1 - jobs/test/CustomAttributeSampleTest.php | 1 - jobs/test/EmailAlertSearchSampleTest.php | 1 - jobs/test/HistogramSampleTest.php | 1 - 18 files changed, 448 insertions(+), 97 deletions(-) delete mode 100644 jobs/src/job_service_connector.php diff --git a/jobs/jobs.php b/jobs/jobs.php index ccd316cc12..83c166ae68 100644 --- a/jobs/jobs.php +++ b/jobs/jobs.php @@ -40,4 +40,4 @@ return $application; } -$application->run(); \ No newline at end of file +$application->run(); diff --git a/jobs/src/auto_complete_sample.php b/jobs/src/auto_complete_sample.php index 022767b324..6d0875379e 100644 --- a/jobs/src/auto_complete_sample.php +++ b/jobs/src/auto_complete_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_CompleteQueryResponse; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -31,7 +33,42 @@ */ final class AutoCompleteSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START auto_complete_job_title] + /** * Auto completes job titles within given companyName. * @@ -50,7 +87,7 @@ public static function job_title_auto_complete(string $companyName = null, strin $optParams['companyName'] = $companyName; } - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $results = $jobService->v2->complete($optParams); var_export($results); @@ -77,7 +114,7 @@ public static function default_auto_complete(string $companyName = null, string $optParams['companyName'] = $companyName; } - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $results = $jobService->v2->complete($optParams); var_export($results); diff --git a/jobs/src/basic_company_sample.php b/jobs/src/basic_company_sample.php index f51063308c..157e1bc152 100644 --- a/jobs/src/basic_company_sample.php +++ b/jobs/src/basic_company_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_Company; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -39,8 +41,42 @@ */ final class BasicCompanySample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } # [START basic_company] + /** * Generates a company. * @@ -69,7 +105,7 @@ public static function generate_company() */ public static function create_company(Google_Service_JobService_Company $companyToBeCreated) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $companyCreated = $jobService->companies->create($companyToBeCreated); printf("Company created:\n%s\n", var_export($companyCreated, true)); @@ -86,7 +122,7 @@ public static function create_company(Google_Service_JobService_Company $company */ public static function get_company(string $companyName) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $companyExisted = $jobService->companies->get($companyName); printf("Company existed:\n%s\n", var_export($companyExisted, true)); @@ -104,7 +140,7 @@ public static function get_company(string $companyName) */ public static function update_company(string $companyName, Google_Service_JobService_Company $companyToBeUpdated) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $companyUpdated = $jobService->companies->patch($companyName, $companyToBeUpdated); printf("Company updated:\n%s\n", var_export($companyUpdated, true)); @@ -125,9 +161,8 @@ public static function update_company_with_field_mask( string $companyName, string $fieldMask, Google_Service_JobService_Company $companyToBeUpdated - ) - { - $jobService = JobServiceConnector::get_job_service(); + ) { + $jobService = self::get_job_service(); $optParams = array('updateCompanyFields' => $fieldMask); $companyUpdated = $jobService->companies->patch($companyName, $companyToBeUpdated, $optParams); @@ -144,7 +179,7 @@ public static function update_company_with_field_mask( */ public static function delete_company(string $companyName) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $jobService->companies->delete($companyName); echo 'Company deleted' . PHP_EOL; diff --git a/jobs/src/basic_job_sample.php b/jobs/src/basic_job_sample.php index 7fbc5158a6..93995c5883 100644 --- a/jobs/src/basic_job_sample.php +++ b/jobs/src/basic_job_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_CreateJobRequest; use Google_Service_JobService_Job; use Google_Service_JobService_UpdateJobRequest; @@ -41,7 +43,42 @@ */ final class BasicJobSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START basic_job] + /** * Generates a basic job with given companyName. * @@ -73,7 +110,7 @@ public static function generate_job_with_required_fields(string $companyName) */ public static function create_job(Google_Service_JobService_Job $jobToBeCreated) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $createJobRequest = new Google_Service_JobService_CreateJobRequest(); $createJobRequest->setJob($jobToBeCreated); @@ -92,7 +129,7 @@ public static function create_job(Google_Service_JobService_Job $jobToBeCreated) */ public static function get_job(string $jobName) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $jobExisted = $jobService->jobs->get($jobName); printf("Job existed:\n%s\n", var_export($jobExisted, true)); @@ -110,7 +147,7 @@ public static function get_job(string $jobName) */ public static function update_job(string $jobName, Google_Service_JobService_Job $jobToBeUpdated) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $updateJobRequest = new Google_Service_JobService_UpdateJobRequest(); $updateJobRequest->setJob($jobToBeUpdated); @@ -134,7 +171,7 @@ public static function update_job_with_field_mask( string $fieldMask, Google_Service_JobService_Job $jobToBeUpdated ) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $updateJobRequest = new Google_Service_JobService_UpdateJobRequest(); $updateJobRequest->setJob($jobToBeUpdated); @@ -149,7 +186,7 @@ public static function update_job_with_field_mask( # [START delete_job] public static function delete_job(string $jobName) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $jobService->jobs->delete($jobName); echo 'Job deleted' . PHP_EOL; diff --git a/jobs/src/batch_operation_sample.php b/jobs/src/batch_operation_sample.php index e2c3db260f..10850b9aca 100644 --- a/jobs/src/batch_operation_sample.php +++ b/jobs/src/batch_operation_sample.php @@ -17,7 +17,9 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; use Google_Service_Exception; +use Google_Service_JobService; use Google_Service_JobService_CreateJobRequest; use Google_Service_JobService_Job; use Google_Service_JobService_UpdateJobRequest; @@ -39,7 +41,42 @@ */ final class BatchOperationSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START batch_job_create] + /** * Creates jobs in batch. * @@ -48,7 +85,7 @@ final class BatchOperationSample extends Command */ public static function batch_create_jobs(string $companyName) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $jobService->getClient()->setUseBatch(true); $softwareEngineerJob = new Google_Service_JobService_Job(); @@ -105,7 +142,7 @@ public static function batch_create_jobs(string $companyName) */ public static function batch_job_update(Google_Service_JobService_Job ...$jobsToBeUpdated) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $jobService->getClient()->setUseBatch(true); // Creates batch request. @@ -156,7 +193,7 @@ public static function batch_job_update(Google_Service_JobService_Job ...$jobsTo */ public static function batch_delete_jobs(Google_Service_JobService_Job ...$jobsToBeDeleted) { - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $jobService->getClient()->setUseBatch(true); // Creates batch request. diff --git a/jobs/src/commute_search_sample.php b/jobs/src/commute_search_sample.php index 777d3311ce..7a27d90eb8 100644 --- a/jobs/src/commute_search_sample.php +++ b/jobs/src/commute_search_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_CommutePreference; use Google_Service_JobService_JobQuery; use Google_Service_JobService_LatLng; @@ -35,7 +37,42 @@ */ final class CommuteSearchSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START commute_search] + /** * Search jobs based on commute location and time. * @@ -75,13 +112,15 @@ public static function commute_search(string $companyName = null) $searchRequest->setJobView('FULL'); $searchRequest->setEnablePreciseResultSize(true); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); return $response; } + # [END commute_search] + protected function configure() { $this diff --git a/jobs/src/custom_attribute_sample.php b/jobs/src/custom_attribute_sample.php index cb35aed7c1..f6ed8e333b 100644 --- a/jobs/src/custom_attribute_sample.php +++ b/jobs/src/custom_attribute_sample.php @@ -17,7 +17,8 @@ namespace Google\Cloud\Samples\Jobs; - +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_CustomAttribute; use Google_Service_JobService_Job; use Google_Service_JobService_JobQuery; @@ -38,7 +39,42 @@ */ final class CustomAttributeSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START custom_attribute_job] + /** * Generates a job with a custom attribute. * @@ -100,7 +136,7 @@ public static function filters_on_string_value_custom_attribute() $searchJobsRequest->setRequestMetadata($requestMetadata); $searchJobsRequest->setJobView('FULL'); - $response = JobServiceConnector::get_job_service()->jobs->search($searchJobsRequest); + $response = self::get_job_service()->jobs->search($searchJobsRequest); var_export($response); return $response; } @@ -132,7 +168,7 @@ public static function filters_on_long_value_custom_attribute() $searchJobsRequest->setRequestMetadata($requestMetadata); $searchJobsRequest->setJobView('FULL'); - $response = JobServiceConnector::get_job_service()->jobs->search($searchJobsRequest); + $response = self::get_job_service()->jobs->search($searchJobsRequest); var_export($response); return $response; } @@ -164,7 +200,7 @@ public static function filters_on_multi_custom_attribute() $searchJobsRequest->setRequestMetadata($requestMetadata); $searchJobsRequest->setJobView('FULL'); - $response = JobServiceConnector::get_job_service()->jobs->search($searchJobsRequest); + $response = self::get_job_service()->jobs->search($searchJobsRequest); var_export($response); return $response; } @@ -195,4 +231,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/src/email_alert_search_sample.php b/jobs/src/email_alert_search_sample.php index cb9ce26d5a..5f15ed6dd3 100644 --- a/jobs/src/email_alert_search_sample.php +++ b/jobs/src/email_alert_search_sample.php @@ -17,7 +17,8 @@ namespace Google\Cloud\Samples\Jobs; - +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_JobQuery; use Google_Service_JobService_RequestMetadata; use Google_Service_JobService_SearchJobsRequest; @@ -31,7 +32,42 @@ */ final class EmailAlertSearchSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START search_for_alerts] + /** * Search jobs for alert. * @@ -58,7 +94,7 @@ public static function search_for_alerts(string $companyName = null) $request->setQuery($jobQuery); } - $response = JobServiceConnector::get_job_service()->jobs->searchForAlert($request); + $response = self::get_job_service()->jobs->searchForAlert($request); var_export($response); return $response; } @@ -87,4 +123,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/src/featured_jobs_search_sample.php b/jobs/src/featured_jobs_search_sample.php index c2b61237bb..bcd76928a7 100644 --- a/jobs/src/featured_jobs_search_sample.php +++ b/jobs/src/featured_jobs_search_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_Job; use Google_Service_JobService_JobQuery; use Google_Service_JobService_RequestMetadata; @@ -35,7 +37,42 @@ */ final class FeaturedJobsSearchSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START featured_job] + /** * Creates a job ad featured. * @@ -91,7 +128,7 @@ public static function search_featured_jobs(string $companyName = null) // which would only search the jobs with positive promotion value. $searchRequest->setMode('FEATURED_JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); diff --git a/jobs/src/general_search_sample.php b/jobs/src/general_search_sample.php index d8b360a0bc..b584de12f0 100644 --- a/jobs/src/general_search_sample.php +++ b/jobs/src/general_search_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_CompensationEntry; use Google_Service_JobService_CompensationFilter; use Google_Service_JobService_CompensationInfo; @@ -49,7 +51,41 @@ */ final class GeneralSearchSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } # [START basic_keyword_search] + /** * Simple job search with keyword. * @@ -80,7 +116,7 @@ public static function basic_search_jobs(string $companyName = null, string $que $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -118,7 +154,7 @@ public static function category_filter_search(string $companyName = null, string $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -156,7 +192,7 @@ public static function employment_types_search(string $companyName = null, strin $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -194,7 +230,7 @@ public static function date_range_search(string $companyName = null, string $dat $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -232,7 +268,7 @@ public static function language_code_search(string $companyName = null, string . $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -270,7 +306,7 @@ public static function company_display_name_search(string $companyName = null, s $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -323,7 +359,7 @@ public static function compensation_search(string $companyName = null) $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); diff --git a/jobs/src/histogram_sample.php b/jobs/src/histogram_sample.php index f510c12055..da4118fc6c 100644 --- a/jobs/src/histogram_sample.php +++ b/jobs/src/histogram_sample.php @@ -17,7 +17,8 @@ namespace Google\Cloud\Samples\Jobs; - +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_CustomAttributeHistogramRequest; use Google_Service_JobService_HistogramFacets; use Google_Service_JobService_JobQuery; @@ -33,7 +34,42 @@ */ final class HistogramSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START histogram_search] + /** * Histogram search. * @@ -70,7 +106,7 @@ public static function histogram_search(string $companyName = null) $request->setQuery($jobQuery); } - $response = JobServiceConnector::get_job_service()->jobs->search($request); + $response = self::get_job_service()->jobs->search($request); var_export($response); return $response; } @@ -99,4 +135,4 @@ protected function execute(InputInterface $input, OutputInterface $output) BasicJobSample::delete_job($jobName); BasicCompanySample::delete_company($companyName); } -} \ No newline at end of file +} diff --git a/jobs/src/job_service_connector.php b/jobs/src/job_service_connector.php deleted file mode 100644 index aac302bcc4..0000000000 --- a/jobs/src/job_service_connector.php +++ /dev/null @@ -1,45 +0,0 @@ -useApplicationDefaultCredentials(); - $client->setScopes(array('https://www.googleapis.com/auth/jobs')); - - // Instantiate the Cloud Job Discovery Service API - $jobService = new Google_Service_JobService($client); - return $jobService; - } - - /** - * Gets Google_Service_JobService. - * - * @return Google_Service_JobService - */ - public static function get_job_service() - { - if (!isset($jobService)) { - self::$jobService = self::create_job_service(); - } - return self::$jobService; - } -} diff --git a/jobs/src/location_search_sample.php b/jobs/src/location_search_sample.php index f845870908..d175cbf037 100644 --- a/jobs/src/location_search_sample.php +++ b/jobs/src/location_search_sample.php @@ -17,6 +17,8 @@ namespace Google\Cloud\Samples\Jobs; +use Google_Client; +use Google_Service_JobService; use Google_Service_JobService_JobQuery; use Google_Service_JobService_LocationFilter; use Google_Service_JobService_RequestMetadata; @@ -42,7 +44,42 @@ */ final class LocationSearchSample extends Command { + private static $jobService; + + /** + * Creates a Google_Service_JobService with default application credentials. + * @return Google_Service_JobService + */ + private static function create_job_service() + { + // Instantiate the client + $client = new Google_Client(); + + // Authorize the client using Application Default Credentials + // @see https://developers.google.com/identity/protocols/application-default-credentials + $client->useApplicationDefaultCredentials(); + $client->setScopes(array('https://www.googleapis.com/auth/jobs')); + + // Instantiate the Cloud Job Discovery Service API + $jobService = new Google_Service_JobService($client); + return $jobService; + } + + /** + * Gets Google_Service_JobService. + * + * @return Google_Service_JobService + */ + private static function get_job_service() + { + if (!isset(self::$jobService)) { + self::$jobService = self::create_job_service(); + } + return self::$jobService; + } + # [START basic_location_search] + /** * Basic location search. * @@ -76,7 +113,7 @@ public static function basic_location_search(string $companyName = null, string $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -99,8 +136,7 @@ public static function keyword_location_search( string $location, float $distance, string $keyword - ) - { + ) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); // Make sure to hash your userID @@ -126,7 +162,7 @@ public static function keyword_location_search( $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -167,7 +203,7 @@ public static function city_location_search(string $companyName = null, string $ $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -190,8 +226,7 @@ public static function multi_locations_search( string $location1, float $distance1, string $location2 - ) - { + ) { // Make sure to set the requestMetadata the same as the associated search request $requestMetadata = new Google_Service_JobService_RequestMetadata(); // Make sure to hash your userID @@ -219,7 +254,7 @@ public static function multi_locations_search( $searchRequest->setQuery($jobQuery); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); @@ -262,7 +297,7 @@ public static function broadening_location_search(string $companyName = null, st $searchRequest->setEnableBroadening(true); $searchRequest->setMode('JOB_SEARCH'); - $jobService = JobServiceConnector::get_job_service(); + $jobService = self::get_job_service(); $response = $jobService->jobs->search($searchRequest); var_export($response); diff --git a/jobs/test/BatchOperationSampleTest.php b/jobs/test/BatchOperationSampleTest.php index b46020f3fd..70fe9aebdc 100644 --- a/jobs/test/BatchOperationSampleTest.php +++ b/jobs/test/BatchOperationSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class BatchOperationSampleTest extends \PHPUnit_Framework_TestCase diff --git a/jobs/test/CommuteSearchSampleTest.php b/jobs/test/CommuteSearchSampleTest.php index a418d0d443..1aadb6b9c7 100644 --- a/jobs/test/CommuteSearchSampleTest.php +++ b/jobs/test/CommuteSearchSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class CommuteSearchSampleTest extends \PHPUnit_Framework_TestCase diff --git a/jobs/test/CustomAttributeSampleTest.php b/jobs/test/CustomAttributeSampleTest.php index b77d85c803..802ff9fdc0 100644 --- a/jobs/test/CustomAttributeSampleTest.php +++ b/jobs/test/CustomAttributeSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class CustomAttributeSampleTest extends \PHPUnit_Framework_TestCase diff --git a/jobs/test/EmailAlertSearchSampleTest.php b/jobs/test/EmailAlertSearchSampleTest.php index 26382655b9..99773489d3 100644 --- a/jobs/test/EmailAlertSearchSampleTest.php +++ b/jobs/test/EmailAlertSearchSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class EmailAlertSearchSampleTest extends \PHPUnit_Framework_TestCase diff --git a/jobs/test/HistogramSampleTest.php b/jobs/test/HistogramSampleTest.php index dfbf5b0bb3..cd44dd9259 100644 --- a/jobs/test/HistogramSampleTest.php +++ b/jobs/test/HistogramSampleTest.php @@ -17,7 +17,6 @@ namespace Google\Cloud\Samples\Jobs; - use Symfony\Component\Console\Tester\CommandTester; class HistogramSampleTest extends \PHPUnit_Framework_TestCase From 15874b29cf8097f6b1410f6bd0f11451a933f177 Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Fri, 13 Jul 2018 10:20:33 -0700 Subject: [PATCH 16/17] Cleanup composer.json --- jobs/composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/jobs/composer.json b/jobs/composer.json index 9f796723c2..d7f47d5785 100644 --- a/jobs/composer.json +++ b/jobs/composer.json @@ -18,7 +18,6 @@ "src/featured_jobs_search_sample.php", "src/general_search_sample.php", "src/histogram_sample.php", - "src/job_service_connector.php", "src/location_search_sample.php" ] } From 04114fabc4bb3e24eadb6aa9f48b5d5917a3eccb Mon Sep 17 00:00:00 2001 From: Yu Yu Date: Fri, 13 Jul 2018 10:23:22 -0700 Subject: [PATCH 17/17] Change to the application name --- jobs/jobs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jobs/jobs.php b/jobs/jobs.php index 83c166ae68..1dcef90574 100644 --- a/jobs/jobs.php +++ b/jobs/jobs.php @@ -21,7 +21,7 @@ use Symfony\Component\Console\Application; -$application = new Application('Cloud Job Discovery'); +$application = new Application('Google Cloud Job Discovery'); $application->add(new AutoCompleteSample()); $application->add(new BasicCompanySample());