From 5d3df7ce9cf095dfce2dc351a1c38f9bbf3f4945 Mon Sep 17 00:00:00 2001 From: xinyunh0929 Date: Tue, 3 Jul 2018 16:39:25 -0700 Subject: [PATCH 1/6] First CJD sample --- jobs/cjd_sample/quickstart.js | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 jobs/cjd_sample/quickstart.js diff --git a/jobs/cjd_sample/quickstart.js b/jobs/cjd_sample/quickstart.js new file mode 100644 index 0000000000..4c16afbfd9 --- /dev/null +++ b/jobs/cjd_sample/quickstart.js @@ -0,0 +1,59 @@ +/** + * Copyright 2017, Google, Inc. + * 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; + } + + const companies = result.data.companies || []; + + if (companies.length) { + console.log('Companies:'); + companies.forEach((company) => console.log(company)); + } else { + console.log(`No companies found.`); + } + }); +}); +// [END quickstart] From 9f38e5d76827b7825a168905052a8ab389e389a9 Mon Sep 17 00:00:00 2001 From: xinyunh0929 Date: Thu, 12 Jul 2018 11:09:30 -0700 Subject: [PATCH 2/6] Add README --- jobs/cjd_sample/README.md | 44 +++++++++++++++++++++++++++++++++++ jobs/cjd_sample/quickstart.js | 6 +++-- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 jobs/cjd_sample/README.md mode change 100644 => 100755 jobs/cjd_sample/quickstart.js diff --git a/jobs/cjd_sample/README.md b/jobs/cjd_sample/README.md new file mode 100755 index 0000000000..bd329ba4da --- /dev/null +++ b/jobs/cjd_sample/README.md @@ -0,0 +1,44 @@ +Google Cloud Platform logo + +# Google Cloud Job Discovery API Samples + +Cloud Job Discovery is part of Google for Jobs - a Google-wide commitment to help +people find jobs more easily. Job Discovery 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/cjd_sample/quickstart.js b/jobs/cjd_sample/quickstart.js old mode 100644 new mode 100755 index 4c16afbfd9..9371159492 --- a/jobs/cjd_sample/quickstart.js +++ b/jobs/cjd_sample/quickstart.js @@ -23,7 +23,7 @@ const {google} = require('googleapis'); google.auth.getApplicationDefault((err, authClient) => { if (err) { console.error('Failed to acquire credentials'); - console.error(err) + console.error(err); return; } @@ -46,11 +46,13 @@ google.auth.getApplicationDefault((err, authClient) => { 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)); + companies.forEach((company) => console.log(company.name)); } else { console.log(`No companies found.`); } From 5e89d3a3d268ad9ab48c52cfa483a62c0336ee91 Mon Sep 17 00:00:00 2001 From: xinyunh0929 Date: Thu, 12 Jul 2018 11:13:45 -0700 Subject: [PATCH 3/6] fix the lint issue --- jobs/cjd_sample/quickstart.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jobs/cjd_sample/quickstart.js b/jobs/cjd_sample/quickstart.js index 9371159492..9c4009670d 100755 --- a/jobs/cjd_sample/quickstart.js +++ b/jobs/cjd_sample/quickstart.js @@ -16,6 +16,7 @@ 'use strict'; // [START quickstart] + // Imports the Google APIs client library const {google} = require('googleapis'); @@ -29,7 +30,7 @@ google.auth.getApplicationDefault((err, authClient) => { if (authClient.createScopedRequired && authClient.createScopedRequired()) { authClient = authClient.createScoped([ - "https://www.googleapis.com/auth/jobs" + 'https://www.googleapis.com/auth/jobs' ]); } From 6945b24d7b7fee063582938090315ac180382cd7 Mon Sep 17 00:00:00 2001 From: xinyunh0929 Date: Thu, 12 Jul 2018 13:55:53 -0700 Subject: [PATCH 4/6] Add test --- jobs/cjd_sample/package.json | 31 +++++++++++++++++++ jobs/cjd_sample/quickstart.js | 2 +- .../cjd_sample/system-test/quickstart.test.js | 24 ++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 jobs/cjd_sample/package.json create mode 100644 jobs/cjd_sample/system-test/quickstart.test.js diff --git a/jobs/cjd_sample/package.json b/jobs/cjd_sample/package.json new file mode 100644 index 0000000000..6a88737938 --- /dev/null +++ b/jobs/cjd_sample/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/cjd_sample/quickstart.js b/jobs/cjd_sample/quickstart.js index 9c4009670d..4feaa84c27 100755 --- a/jobs/cjd_sample/quickstart.js +++ b/jobs/cjd_sample/quickstart.js @@ -47,7 +47,7 @@ google.auth.getApplicationDefault((err, authClient) => { return; } - console.log("Request ID: " + result.data.metadata.requestId); + console.log('Request ID: ' + result.data.metadata.requestId); const companies = result.data.companies || []; diff --git a/jobs/cjd_sample/system-test/quickstart.test.js b/jobs/cjd_sample/system-test/quickstart.test.js new file mode 100644 index 0000000000..8420f860e7 --- /dev/null +++ b/jobs/cjd_sample/system-test/quickstart.test.js @@ -0,0 +1,24 @@ +/** + * Copyright 2017, Google, Inc. + * 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`)); +}); From 6a410374bd6ca4fadccbc3e1b51ae4ee612ea177 Mon Sep 17 00:00:00 2001 From: xinyunh0929 Date: Fri, 13 Jul 2018 14:05:03 -0700 Subject: [PATCH 5/6] Modify the sample --- jobs/cjd_sample/quickstart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jobs/cjd_sample/quickstart.js b/jobs/cjd_sample/quickstart.js index 4feaa84c27..59f0ac32cf 100755 --- a/jobs/cjd_sample/quickstart.js +++ b/jobs/cjd_sample/quickstart.js @@ -47,7 +47,7 @@ google.auth.getApplicationDefault((err, authClient) => { return; } - console.log('Request ID: ' + result.data.metadata.requestId); + console.log(`Request ID: ${result.data.metadata.requestId}`); const companies = result.data.companies || []; From 91318268d47eaaa0897a1b611765cfc213765a48 Mon Sep 17 00:00:00 2001 From: xinyunh0929 Date: Mon, 16 Jul 2018 14:56:25 -0700 Subject: [PATCH 6/6] Modify the copyright --- jobs/cjd_sample/quickstart.js | 2 +- jobs/cjd_sample/system-test/quickstart.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jobs/cjd_sample/quickstart.js b/jobs/cjd_sample/quickstart.js index 59f0ac32cf..8d9729a75e 100755 --- a/jobs/cjd_sample/quickstart.js +++ b/jobs/cjd_sample/quickstart.js @@ -1,5 +1,5 @@ /** - * Copyright 2017, Google, Inc. + * 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 diff --git a/jobs/cjd_sample/system-test/quickstart.test.js b/jobs/cjd_sample/system-test/quickstart.test.js index 8420f860e7..2d0b70096f 100644 --- a/jobs/cjd_sample/system-test/quickstart.test.js +++ b/jobs/cjd_sample/system-test/quickstart.test.js @@ -1,5 +1,5 @@ /** - * Copyright 2017, Google, Inc. + * 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