diff --git a/jobs/cjd_sample/README.md b/jobs/README.md similarity index 84% rename from jobs/cjd_sample/README.md rename to jobs/README.md index e0a4f82aac..67cae5ad11 100644 --- a/jobs/cjd_sample/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/cjd_sample/composer.json b/jobs/cjd_sample/composer.json deleted file mode 100644 index d203050d00..0000000000 --- a/jobs/cjd_sample/composer.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "require": { - "google/apiclient": "^2.1", - "symfony/console": " ^3.0", - "symfony/event-dispatcher": "^3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4" - } -} diff --git a/jobs/composer.json b/jobs/composer.json new file mode 100644 index 0000000000..d7f47d5785 --- /dev/null +++ b/jobs/composer.json @@ -0,0 +1,24 @@ +{ + "require": { + "google/apiclient": "^2.1", + "symfony/console": " ^3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "autoload": { + "files": [ + "src/auto_complete_sample.php", + "src/basic_company_sample.php", + "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/location_search_sample.php" + ] + } +} diff --git a/jobs/cjd_sample/composer.lock b/jobs/composer.lock similarity index 92% rename from jobs/cjd_sample/composer.lock rename to jobs/composer.lock index 0ac29b0cc6..235d14fd2f 100644 --- a/jobs/cjd_sample/composer.lock +++ b/jobs/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": "216c1e5029f1c5f992c9178895aba355", "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": [ @@ -1048,29 +985,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 +1032,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 +1083,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,7 +1142,7 @@ "spy", "stub" ], - "time": "2017-11-24T13:59:53+00:00" + "time": "2018-04-18T13:57:24+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1949,22 +1892,78 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2015-06-21T13:59:46+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 +2004,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 +2054,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2018-01-29T19:49:41+00:00" } ], "aliases": [], diff --git a/jobs/jobs.php b/jobs/jobs.php new file mode 100644 index 0000000000..1dcef90574 --- /dev/null +++ b/jobs/jobs.php @@ -0,0 +1,43 @@ +add(new AutoCompleteSample()); +$application->add(new BasicCompanySample()); +$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()); + +// for testing +if (getenv('PHPUNIT_TESTS') === '1') { + return $application; +} + +$application->run(); diff --git a/jobs/phpunit.xml.dist b/jobs/phpunit.xml.dist new file mode 100644 index 0000000000..bc37699374 --- /dev/null +++ b/jobs/phpunit.xml.dist @@ -0,0 +1,34 @@ + + + + + + test + + + + + + + + ./src + + + + + + diff --git a/jobs/cjd_sample/quickstart.php b/jobs/quickstart.php similarity index 93% rename from jobs/cjd_sample/quickstart.php rename to jobs/quickstart.php index a61a05eabb..50a949ba87 100644 --- a/jobs/cjd_sample/quickstart.php +++ b/jobs/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/src/auto_complete_sample.php b/jobs/src/auto_complete_sample.php new file mode 100644 index 0000000000..6d0875379e --- /dev/null +++ b/jobs/src/auto_complete_sample.php @@ -0,0 +1,152 @@ +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. + * + * @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( + 'query' => $query, + 'languageCode' => 'en-US', + 'type' => 'JOB_TITLE', + 'pageSize' => 10); + if (isset($companyName)) { + $optParams['companyName'] = $companyName; + } + + $jobService = self::get_job_service(); + $results = $jobService->v2->complete($optParams); + + var_export($results); + return $results; + } + + # [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( + 'query' => $query, + 'languageCode' => 'en-US', + 'pageSize' => 10); + if (isset($companyName)) { + $optParams['companyName'] = $companyName; + } + + $jobService = self::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); + } +} diff --git a/jobs/src/basic_company_sample.php b/jobs/src/basic_company_sample.php new file mode 100644 index 0000000000..157e1bc152 --- /dev/null +++ b/jobs/src/basic_company_sample.php @@ -0,0 +1,222 @@ +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. + * + * @return Google_Service_JobService_Company + */ + public static function generate_company() + { + $distributorCompanyId = 'company:' . rand(); + + $company = new Google_Service_JobService_Company(); + $company->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 = self::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 = self::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 = self::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 = self::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] + /** + * Deletes a company. + * + * @param string $companyName + */ + public static function delete_company(string $companyName) + { + $jobService = self::get_job_service(); + + $jobService->companies->delete($companyName); + echo 'Company deleted' . PHP_EOL; + } + + # [END delete_company] + + protected function configure() + { + $this + ->setName('basic-company') + ->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); + } +} diff --git a/jobs/src/basic_job_sample.php b/jobs/src/basic_job_sample.php new file mode 100644 index 0000000000..93995c5883 --- /dev/null +++ b/jobs/src/basic_job_sample.php @@ -0,0 +1,238 @@ +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. + * + * @param string $companyName + * @return Google_Service_JobService_Job + */ + public static function generate_job_with_required_fields(string $companyName) + { + $requisitionId = 'jobWithRequiredFields:' . rand(); + + $job = new Google_Service_JobService_Job(); + $job->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 = self::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 = self::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 = self::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 = self::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 = self::get_job_service(); + + $jobService->jobs->delete($jobName); + echo 'Job deleted' . PHP_EOL; + } + + # [END delete_job] + + + protected function configure() + { + $this + ->setName('basic-job') + ->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); + } +} diff --git a/jobs/src/batch_operation_sample.php b/jobs/src/batch_operation_sample.php new file mode 100644 index 0000000000..10850b9aca --- /dev/null +++ b/jobs/src/batch_operation_sample.php @@ -0,0 +1,244 @@ +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. + * + * @param string $companyName + * @return array + */ + public static function batch_create_jobs(string $companyName) + { + $jobService = self::get_job_service(); + $jobService->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 = self::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 = self::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/src/commute_search_sample.php b/jobs/src/commute_search_sample.php new file mode 100644 index 0000000000..7a27d90eb8 --- /dev/null +++ b/jobs/src/commute_search_sample.php @@ -0,0 +1,148 @@ +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. + * + * @param string|null $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function commute_search(string $companyName = null) + { + // 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'); + + // 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 = self::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [END commute_search] + + 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/src/custom_attribute_sample.php b/jobs/src/custom_attribute_sample.php new file mode 100644 index 0000000000..f6ed8e333b --- /dev/null +++ b/jobs/src/custom_attribute_sample.php @@ -0,0 +1,234 @@ +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. + * + * @param string $companyName + * @return Google_Service_JobService_Job + */ + public static function generate_job_with_a_custom_attribute(string $companyName) + { + $requisitionId = 'jobWithACustomAttribute:' . rand(); + + // Constructs custom attributes array. + $customAttribute1 = new Google_Service_JobService_CustomAttribute(); + $stringValues = new Google_Service_JobService_StringValues(); + $stringValues->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 = self::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 = self::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 = self::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); + } +} diff --git a/jobs/src/email_alert_search_sample.php b/jobs/src/email_alert_search_sample.php new file mode 100644 index 0000000000..5f15ed6dd3 --- /dev/null +++ b/jobs/src/email_alert_search_sample.php @@ -0,0 +1,126 @@ +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. + * + * @param string|null $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ + public static function search_for_alerts(string $companyName = null) + { + // 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'); + + $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 = self::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); + } +} diff --git a/jobs/src/featured_jobs_search_sample.php b/jobs/src/featured_jobs_search_sample.php new file mode 100644 index 0000000000..bcd76928a7 --- /dev/null +++ b/jobs/src/featured_jobs_search_sample.php @@ -0,0 +1,162 @@ +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. + * + * @param string $companyName + * @return Google_Service_JobService_Job + */ + public static function generate_featured_job(string $companyName) + { + $requisitionId = 'featuredJob:' . rand(); + + $job = new Google_Service_JobService_Job(); + $job->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|null $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::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); + } +} diff --git a/jobs/src/general_search_sample.php b/jobs/src/general_search_sample.php new file mode 100644 index 0000000000..b584de12f0 --- /dev/null +++ b/jobs/src/general_search_sample.php @@ -0,0 +1,414 @@ +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. + * + * @param string|null $companyName + * @param string $query + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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'); + + // 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 = self::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|null $companyName + * @param string ...$categories + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [START employment_types_filter] + + /** + * Search on employment types. + * + * @param string|null $companyName + * @param string ...$employmentTypes + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::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|null $companyName + * @param string $dateRange + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::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|null $companyName + * @param string ...$languageCodes + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::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|null $companyName + * @param string ...$companyDisplayNames + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::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|null $companyName + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [END compensation_filter] + + protected function configure() + { + $this + ->setName('general-search') + ->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(10); + 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); + } +} diff --git a/jobs/src/histogram_sample.php b/jobs/src/histogram_sample.php new file mode 100644 index 0000000000..da4118fc6c --- /dev/null +++ b/jobs/src/histogram_sample.php @@ -0,0 +1,138 @@ +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. + * + * @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 + $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'); + + // 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 = self::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); + } +} diff --git a/jobs/src/location_search_sample.php b/jobs/src/location_search_sample.php new file mode 100644 index 0000000000..d175cbf037 --- /dev/null +++ b/jobs/src/location_search_sample.php @@ -0,0 +1,368 @@ +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. + * + * @param string|null $companyName + * @param string $location + * @param float $distance + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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->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 = self::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|null $companyName + * @param string $location + * @param float $distance + * @param string $keyword + * @return Google_Service_JobService_SearchJobsResponse + */ + 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 + $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 = self::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|null $companyName + * @param string $location + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::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|null $companyName + * @param string $location1 + * @param float $distance1 + * @param string $location2 + * @return Google_Service_JobService_SearchJobsResponse + */ + 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 + $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 = self::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|null $companyName + * @param string $location + * @return Google_Service_JobService_SearchJobsResponse + */ + 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(); + // 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 = self::get_job_service(); + $response = $jobService->jobs->search($searchRequest); + + var_export($response); + return $response; + } + + # [END broadening_location_search] + + protected function configure() + { + $this + ->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) + ->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); + } +} diff --git a/jobs/test/AutoCompleteSampleTest.php b/jobs/test/AutoCompleteSampleTest.php new file mode 100644 index 0000000000..94d8935b01 --- /dev/null +++ b/jobs/test/AutoCompleteSampleTest.php @@ -0,0 +1,43 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.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'); + } +} diff --git a/jobs/test/BasicCompanySampleTest.php b/jobs/test/BasicCompanySampleTest.php new file mode 100644 index 0000000000..0ae68ee159 --- /dev/null +++ b/jobs/test/BasicCompanySampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('basic-company')); + } + + 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/test/BasicJobSampleTest.php b/jobs/test/BasicJobSampleTest.php new file mode 100644 index 0000000000..86ccc9b3f0 --- /dev/null +++ b/jobs/test/BasicJobSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('basic-job')); + } + + public function testBasicJobSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/Job generated:.*Job created:.*Job existed:.*Job updated:' + . '.*changedDescription.*Job updated:.*changedJobTitle.*Job deleted/s'); + } +} diff --git a/jobs/test/BatchOperationSampleTest.php b/jobs/test/BatchOperationSampleTest.php new file mode 100644 index 0000000000..70fe9aebdc --- /dev/null +++ b/jobs/test/BatchOperationSampleTest.php @@ -0,0 +1,43 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.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/test/CommuteSearchSampleTest.php b/jobs/test/CommuteSearchSampleTest.php new file mode 100644 index 0000000000..1aadb6b9c7 --- /dev/null +++ b/jobs/test/CommuteSearchSampleTest.php @@ -0,0 +1,41 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('commute-search')); + } + + public function testFeaturedJobsSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/.*appliedCommuteFilter.*1600 Amphitheatre Pkwy.*/s'); + } +} diff --git a/jobs/test/CustomAttributeSampleTest.php b/jobs/test/CustomAttributeSampleTest.php new file mode 100644 index 0000000000..802ff9fdc0 --- /dev/null +++ b/jobs/test/CustomAttributeSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.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/test/EmailAlertSearchSampleTest.php b/jobs/test/EmailAlertSearchSampleTest.php new file mode 100644 index 0000000000..99773489d3 --- /dev/null +++ b/jobs/test/EmailAlertSearchSampleTest.php @@ -0,0 +1,41 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('email-alert-search')); + } + + public function testFeaturedJobsSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/matchingJobs/'); + } +} diff --git a/jobs/test/FeaturedJobsSearchSampleTest.php b/jobs/test/FeaturedJobsSearchSampleTest.php new file mode 100644 index 0000000000..db216190b8 --- /dev/null +++ b/jobs/test/FeaturedJobsSearchSampleTest.php @@ -0,0 +1,41 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.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/test/GeneralSearchSampleTest.php b/jobs/test/GeneralSearchSampleTest.php new file mode 100644 index 0000000000..41fd3a22d3 --- /dev/null +++ b/jobs/test/GeneralSearchSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('general-search')); + } + + public function testGeneralSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/matchingJobs.*matchingJobs.*matchingJobs.*matchingJobs.*' + . 'matchingJobs.*matchingJobs.*matchingJobs.*/s'); + } +} diff --git a/jobs/test/HistogramSampleTest.php b/jobs/test/HistogramSampleTest.php new file mode 100644 index 0000000000..cd44dd9259 --- /dev/null +++ b/jobs/test/HistogramSampleTest.php @@ -0,0 +1,42 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('histogram')); + } + + public function testHistogramSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/COMPANY_ID/'); + $this->expectOutputRegex('/someFieldName1/'); + } +} diff --git a/jobs/test/LocationSearchSampleTest.php b/jobs/test/LocationSearchSampleTest.php new file mode 100644 index 0000000000..db04b570a8 --- /dev/null +++ b/jobs/test/LocationSearchSampleTest.php @@ -0,0 +1,45 @@ +markTestSkipped("Set the GOOGLE_APPLICATION_CREDENTIALS environment variable."); + } + + $application = require __DIR__ . '/../jobs.php'; + $this->commandTester = new CommandTester($application->get('location-search')); + } + + public function testLocationSearchSample() + { + $this->commandTester->execute([], ['interactive' => false]); + $this->expectOutputRegex('/appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*' + . 'appliedJobLocationFilters.*matchingJobs.*/s'); + } +}