diff --git a/jobs/v2/README.md b/jobs/v2/README.md new file mode 100755 index 0000000000..26e505da65 --- /dev/null +++ b/jobs/v2/README.md @@ -0,0 +1,44 @@ +Google Cloud Platform logo + +# Google Cloud Talent Solution API Samples + +Cloud Talent Solution is part of Google for Jobs - a Google-wide commitment to help +people find jobs more easily. Talent Solution provides plug and play access to +Google’s search and machine learning capabilities, enabling the entire recruiting +ecosystem - company career sites, job boards, applicant tracking systems, and +staffing agencies to improve job site engagement and candidate conversion. + +## Table of Contents + +* [Setup](#setup) +* [Running the tests](#running-the-tests) + +## Setup + +1. Read [Prerequisites][prereq] and [How to run a sample][run] first. +1. Install dependencies: + + With **npm**: + + npm install + + With **yarn**: + + yarn install + +[prereq]: ../README.md#prerequisites +[run]: ../README.md#how-to-run-a-sample + +## Running the tests + +1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. + +1. Run the tests: + + With **npm**: + + npm test + + With **yarn**: + + yarn test diff --git a/jobs/v2/package.json b/jobs/v2/package.json new file mode 100644 index 0000000000..6a88737938 --- /dev/null +++ b/jobs/v2/package.json @@ -0,0 +1,31 @@ +{ + "name": "nodejs-docs-samples-jobs", + "version": "0.0.1", + "private": true, + "license": "Apache-2.0", + "author": "Google Inc.", + "repository": { + "type": "git", + "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" + }, + "engines": { + "node": ">=4.3.2" + }, + "scripts": { + "lint": "repo-tools lint", + "pretest": "npm run lint", + "test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js" + }, + "dependencies": { + "googleapis": "27.0.0", + "safe-buffer": "5.1.1", + "uuid": "^3.2.1", + "yargs": "11.0.0" + }, + "devDependencies": { + "@google-cloud/nodejs-repo-tools": "2.2.5", + "ava": "0.25.0", + "proxyquire": "2.0.1", + "semistandard": "^12.0.1" + } +} diff --git a/jobs/v2/quickstart.js b/jobs/v2/quickstart.js new file mode 100755 index 0000000000..8d9729a75e --- /dev/null +++ b/jobs/v2/quickstart.js @@ -0,0 +1,62 @@ +/** + * Copyright 2018, Google, LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +// [START quickstart] + +// Imports the Google APIs client library +const {google} = require('googleapis'); + +// Acquires credentials +google.auth.getApplicationDefault((err, authClient) => { + if (err) { + console.error('Failed to acquire credentials'); + console.error(err); + return; + } + + if (authClient.createScopedRequired && authClient.createScopedRequired()) { + authClient = authClient.createScoped([ + 'https://www.googleapis.com/auth/jobs' + ]); + } + + // Instantiates an authorized client + const jobs = google.jobs({ + version: 'v2', + auth: authClient + }); + + // Lists companies + jobs.companies.list((err, result) => { + if (err) { + console.error(err); + return; + } + + console.log(`Request ID: ${result.data.metadata.requestId}`); + + const companies = result.data.companies || []; + + if (companies.length) { + console.log('Companies:'); + companies.forEach((company) => console.log(company.name)); + } else { + console.log(`No companies found.`); + } + }); +}); +// [END quickstart] diff --git a/jobs/v2/system-test/quickstart.test.js b/jobs/v2/system-test/quickstart.test.js new file mode 100644 index 0000000000..2d0b70096f --- /dev/null +++ b/jobs/v2/system-test/quickstart.test.js @@ -0,0 +1,24 @@ +/** + * Copyright 2018, Google, LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const test = require(`ava`); +const tools = require(`@google-cloud/nodejs-repo-tools`); + +test(`should list companies`, async t => { + const output = await tools.runAsync(`node quickstart.js`); + t.true(output.includes(`Request ID`)); +}); diff --git a/jobs/v3/README.md b/jobs/v3/README.md new file mode 100755 index 0000000000..26e505da65 --- /dev/null +++ b/jobs/v3/README.md @@ -0,0 +1,44 @@ +Google Cloud Platform logo + +# Google Cloud Talent Solution API Samples + +Cloud Talent Solution is part of Google for Jobs - a Google-wide commitment to help +people find jobs more easily. Talent Solution provides plug and play access to +Google’s search and machine learning capabilities, enabling the entire recruiting +ecosystem - company career sites, job boards, applicant tracking systems, and +staffing agencies to improve job site engagement and candidate conversion. + +## Table of Contents + +* [Setup](#setup) +* [Running the tests](#running-the-tests) + +## Setup + +1. Read [Prerequisites][prereq] and [How to run a sample][run] first. +1. Install dependencies: + + With **npm**: + + npm install + + With **yarn**: + + yarn install + +[prereq]: ../README.md#prerequisites +[run]: ../README.md#how-to-run-a-sample + +## Running the tests + +1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. + +1. Run the tests: + + With **npm**: + + npm test + + With **yarn**: + + yarn test diff --git a/jobs/v3/package.json b/jobs/v3/package.json new file mode 100644 index 0000000000..6a88737938 --- /dev/null +++ b/jobs/v3/package.json @@ -0,0 +1,31 @@ +{ + "name": "nodejs-docs-samples-jobs", + "version": "0.0.1", + "private": true, + "license": "Apache-2.0", + "author": "Google Inc.", + "repository": { + "type": "git", + "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" + }, + "engines": { + "node": ">=4.3.2" + }, + "scripts": { + "lint": "repo-tools lint", + "pretest": "npm run lint", + "test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js" + }, + "dependencies": { + "googleapis": "27.0.0", + "safe-buffer": "5.1.1", + "uuid": "^3.2.1", + "yargs": "11.0.0" + }, + "devDependencies": { + "@google-cloud/nodejs-repo-tools": "2.2.5", + "ava": "0.25.0", + "proxyquire": "2.0.1", + "semistandard": "^12.0.1" + } +} diff --git a/jobs/v3/quickstart.js b/jobs/v3/quickstart.js new file mode 100755 index 0000000000..f71c31a65f --- /dev/null +++ b/jobs/v3/quickstart.js @@ -0,0 +1,67 @@ +/** + * Copyright 2018, Google, LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +// [START quickstart] + +// Imports the Google APIs client library +const {google} = require('googleapis'); +const projectId = process.env.GOOGLE_CLOUD_PROJECT; + +// Acquires credentials +google.auth.getApplicationDefault((err, authClient) => { + if (err) { + console.error('Failed to acquire credentials'); + console.error(err); + return; + } + + if (authClient.createScopedRequired && authClient.createScopedRequired()) { + authClient = authClient.createScoped([ + 'https://www.googleapis.com/auth/jobs' + ]); + } + + // Instantiates an authorized client + const jobService = google.jobs({ + version: 'v3', + auth: authClient + }); + + const request = { + parent: `projects/${projectId}`, + }; + + // Lists companies + jobService.projects.companies.list(request, function (err, result) { + if (err) { + console.error('Failed to retrieve companies! ' + err); + throw err; + } + console.log(`Request ID: ${result.data.metadata.requestId}`); + + const companies = result.data.companies || []; + + if (companies.length) { + console.log('Companies:'); + companies.forEach((company) => console.log(company.name)); + } else { + console.log(`No companies found.`); + } + }); +}); + +// [END quickstart] diff --git a/jobs/v3/system-test/quickstart.test.js b/jobs/v3/system-test/quickstart.test.js new file mode 100644 index 0000000000..2d0b70096f --- /dev/null +++ b/jobs/v3/system-test/quickstart.test.js @@ -0,0 +1,24 @@ +/** + * Copyright 2018, Google, LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const test = require(`ava`); +const tools = require(`@google-cloud/nodejs-repo-tools`); + +test(`should list companies`, async t => { + const output = await tools.runAsync(`node quickstart.js`); + t.true(output.includes(`Request ID`)); +});