Skip to content

Commit 022055e

Browse files
xinyunh0929happyhuman
authored andcommitted
Check in Cloud Job Discovery quick start (GoogleCloudPlatform#684)
* First CJD sample * Add README * fix the lint issue * Add test * Modify the sample * Modify the copyright
1 parent bfdbab3 commit 022055e

4 files changed

Lines changed: 161 additions & 0 deletions

File tree

jobs/cjd_sample/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
2+
3+
# Google Cloud Job Discovery API Samples
4+
5+
Cloud Job Discovery is part of Google for Jobs - a Google-wide commitment to help
6+
people find jobs more easily. Job Discovery provides plug and play access to
7+
Google’s search and machine learning capabilities, enabling the entire recruiting
8+
ecosystem - company career sites, job boards, applicant tracking systems, and
9+
staffing agencies to improve job site engagement and candidate conversion.
10+
11+
## Table of Contents
12+
13+
* [Setup](#setup)
14+
* [Running the tests](#running-the-tests)
15+
16+
## Setup
17+
18+
1. Read [Prerequisites][prereq] and [How to run a sample][run] first.
19+
1. Install dependencies:
20+
21+
With **npm**:
22+
23+
npm install
24+
25+
With **yarn**:
26+
27+
yarn install
28+
29+
[prereq]: ../README.md#prerequisites
30+
[run]: ../README.md#how-to-run-a-sample
31+
32+
## Running the tests
33+
34+
1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables.
35+
36+
1. Run the tests:
37+
38+
With **npm**:
39+
40+
npm test
41+
42+
With **yarn**:
43+
44+
yarn test

jobs/cjd_sample/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "nodejs-docs-samples-jobs",
3+
"version": "0.0.1",
4+
"private": true,
5+
"license": "Apache-2.0",
6+
"author": "Google Inc.",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
10+
},
11+
"engines": {
12+
"node": ">=4.3.2"
13+
},
14+
"scripts": {
15+
"lint": "repo-tools lint",
16+
"pretest": "npm run lint",
17+
"test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js"
18+
},
19+
"dependencies": {
20+
"googleapis": "27.0.0",
21+
"safe-buffer": "5.1.1",
22+
"uuid": "^3.2.1",
23+
"yargs": "11.0.0"
24+
},
25+
"devDependencies": {
26+
"@google-cloud/nodejs-repo-tools": "2.2.5",
27+
"ava": "0.25.0",
28+
"proxyquire": "2.0.1",
29+
"semistandard": "^12.0.1"
30+
}
31+
}

jobs/cjd_sample/quickstart.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2018, Google, LLC.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
// [START quickstart]
19+
20+
// Imports the Google APIs client library
21+
const {google} = require('googleapis');
22+
23+
// Acquires credentials
24+
google.auth.getApplicationDefault((err, authClient) => {
25+
if (err) {
26+
console.error('Failed to acquire credentials');
27+
console.error(err);
28+
return;
29+
}
30+
31+
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
32+
authClient = authClient.createScoped([
33+
'https://www.googleapis.com/auth/jobs'
34+
]);
35+
}
36+
37+
// Instantiates an authorized client
38+
const jobs = google.jobs({
39+
version: 'v2',
40+
auth: authClient
41+
});
42+
43+
// Lists companies
44+
jobs.companies.list((err, result) => {
45+
if (err) {
46+
console.error(err);
47+
return;
48+
}
49+
50+
console.log(`Request ID: ${result.data.metadata.requestId}`);
51+
52+
const companies = result.data.companies || [];
53+
54+
if (companies.length) {
55+
console.log('Companies:');
56+
companies.forEach((company) => console.log(company.name));
57+
} else {
58+
console.log(`No companies found.`);
59+
}
60+
});
61+
});
62+
// [END quickstart]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2018, Google, LLC.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
const test = require(`ava`);
19+
const tools = require(`@google-cloud/nodejs-repo-tools`);
20+
21+
test(`should list companies`, async t => {
22+
const output = await tools.runAsync(`node quickstart.js`);
23+
t.true(output.includes(`Request ID`));
24+
});

0 commit comments

Comments
 (0)