Skip to content

Commit 7d5b05b

Browse files
RenlongZfhinkel
authored andcommitted
code demo for jobs api v3 (GoogleCloudPlatform#1007)
1 parent 43cb78c commit 7d5b05b

30 files changed

Lines changed: 2523 additions & 0 deletions
File renamed without changes.
File renamed without changes.

jobs/v3/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 Node.js 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+
npm install
22+
23+
[prereq]: ../../README.md#prerequisites
24+
[run]: ../../README.md#how-to-run-a-sample
25+
26+
## Running the tests
27+
28+
1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables.
29+
30+
1. Run all tests:
31+
32+
npm test
33+
1. Run test one by one:
34+
35+
cd system-test
36+
ava quickstart.test.js

jobs/v3/auto-complete-sample.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 basicCompanySample = require(`./basic-company-sample`);
19+
const basicJobSample = require(`./basic-job-sample`);
20+
const createAuthCredential = require('./create-auth-credential');
21+
22+
const PROJECT_ID = process.env.GOOGLE_CLOUD_PROJECT;
23+
24+
/**
25+
* The samples in this file introduced how to do the auto complete, including:
26+
*
27+
* - Default auto complete (on both company display name and job title)
28+
*
29+
* - Auto complete on job title only
30+
*/
31+
32+
//[START auto_complete_job_title]
33+
34+
/**
35+
* Auto completes job titles within given companyName.
36+
*/
37+
const jobTitleAutoComplete = async (jobServiceClient, query, companyName) => {
38+
try {
39+
const request = {
40+
name: `projects/${PROJECT_ID}`,
41+
query: query,
42+
languageCode: 'en-US',
43+
type: 'JOB_TITLE',
44+
pageSize: 10,
45+
};
46+
47+
if (companyName) {
48+
request.companyName = companyName;
49+
}
50+
51+
const complete = await jobServiceClient.projects.complete(request);
52+
53+
console.log(JSON.stringify(complete.data));
54+
} catch (e) {
55+
console.error(e);
56+
throw e;
57+
}
58+
};
59+
// [END auto_complete_job_title]
60+
61+
// [START auto_complete_default]
62+
63+
/**
64+
* Auto completes job titles within given companyName.
65+
*/
66+
const defaultAutoComplete = async (jobServiceClient, query, companyName) => {
67+
try {
68+
const request = {
69+
name: `projects/${PROJECT_ID}`,
70+
query: query,
71+
languageCode: 'en-US',
72+
pageSize: 10,
73+
};
74+
75+
if (companyName) {
76+
request.companyName = companyName;
77+
}
78+
79+
const complete = await jobServiceClient.projects.complete(request);
80+
81+
console.log(JSON.stringify(complete.data));
82+
} catch (e) {
83+
console.error(e);
84+
throw e;
85+
}
86+
};
87+
// [END auto_complete_default]
88+
89+
// Run Sample
90+
(async () => {
91+
try {
92+
// Create an authorized client
93+
const jobServiceClient = await createAuthCredential();
94+
95+
// Create a company
96+
const companyToBeCreated = basicCompanySample.generateCompany();
97+
const companyCreated = await basicCompanySample.createCompany(
98+
jobServiceClient,
99+
companyToBeCreated
100+
);
101+
const companyName = companyCreated.name;
102+
103+
// Construct a job
104+
const jobToBeCreated = basicJobSample.generateJobWithRequiredFields(
105+
companyName
106+
);
107+
jobToBeCreated.title = 'Software engineer';
108+
const jobCreated = await basicJobSample.createJob(
109+
jobServiceClient,
110+
jobToBeCreated
111+
);
112+
const jobName = jobCreated.name;
113+
114+
await defaultAutoComplete(jobServiceClient, 'goo', companyName);
115+
await defaultAutoComplete(jobServiceClient, 'sof', companyName);
116+
await jobTitleAutoComplete(jobServiceClient, 'sof', companyName);
117+
118+
// Delete job and company
119+
await basicJobSample.deleteJob(jobServiceClient, jobName);
120+
await basicCompanySample.deleteCompany(jobServiceClient, companyName);
121+
} catch (e) {
122+
console.error(e);
123+
throw e;
124+
}
125+
})();

0 commit comments

Comments
 (0)