-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,523 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<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"/> | ||
|
||
# Google Cloud Job Discovery API Node.js 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: | ||
|
||
npm 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 all tests: | ||
|
||
npm test | ||
1. Run test one by one: | ||
|
||
cd system-test | ||
ava quickstart.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* 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 basicCompanySample = require(`./basic-company-sample`); | ||
const basicJobSample = require(`./basic-job-sample`); | ||
const createAuthCredential = require('./create-auth-credential'); | ||
|
||
const PROJECT_ID = process.env.GOOGLE_CLOUD_PROJECT; | ||
|
||
/** | ||
* The samples in this file introduced how to do the auto complete, including: | ||
* | ||
* - Default auto complete (on both company display name and job title) | ||
* | ||
* - Auto complete on job title only | ||
*/ | ||
|
||
//[START auto_complete_job_title] | ||
|
||
/** | ||
* Auto completes job titles within given companyName. | ||
*/ | ||
const jobTitleAutoComplete = async (jobServiceClient, query, companyName) => { | ||
try { | ||
const request = { | ||
name: `projects/${PROJECT_ID}`, | ||
query: query, | ||
languageCode: 'en-US', | ||
type: 'JOB_TITLE', | ||
pageSize: 10, | ||
}; | ||
|
||
if (companyName) { | ||
request.companyName = companyName; | ||
} | ||
|
||
const complete = await jobServiceClient.projects.complete(request); | ||
|
||
console.log(JSON.stringify(complete.data)); | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
}; | ||
// [END auto_complete_job_title] | ||
|
||
// [START auto_complete_default] | ||
|
||
/** | ||
* Auto completes job titles within given companyName. | ||
*/ | ||
const defaultAutoComplete = async (jobServiceClient, query, companyName) => { | ||
try { | ||
const request = { | ||
name: `projects/${PROJECT_ID}`, | ||
query: query, | ||
languageCode: 'en-US', | ||
pageSize: 10, | ||
}; | ||
|
||
if (companyName) { | ||
request.companyName = companyName; | ||
} | ||
|
||
const complete = await jobServiceClient.projects.complete(request); | ||
|
||
console.log(JSON.stringify(complete.data)); | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
}; | ||
// [END auto_complete_default] | ||
|
||
// Run Sample | ||
(async () => { | ||
try { | ||
// Create an authorized client | ||
const jobServiceClient = await createAuthCredential(); | ||
|
||
// Create a company | ||
const companyToBeCreated = basicCompanySample.generateCompany(); | ||
const companyCreated = await basicCompanySample.createCompany( | ||
jobServiceClient, | ||
companyToBeCreated | ||
); | ||
const companyName = companyCreated.name; | ||
|
||
// Construct a job | ||
const jobToBeCreated = basicJobSample.generateJobWithRequiredFields( | ||
companyName | ||
); | ||
jobToBeCreated.title = 'Software engineer'; | ||
const jobCreated = await basicJobSample.createJob( | ||
jobServiceClient, | ||
jobToBeCreated | ||
); | ||
const jobName = jobCreated.name; | ||
|
||
await defaultAutoComplete(jobServiceClient, 'goo', companyName); | ||
await defaultAutoComplete(jobServiceClient, 'sof', companyName); | ||
await jobTitleAutoComplete(jobServiceClient, 'sof', companyName); | ||
|
||
// Delete job and company | ||
await basicJobSample.deleteJob(jobServiceClient, jobName); | ||
await basicCompanySample.deleteCompany(jobServiceClient, companyName); | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
})(); |
Oops, something went wrong.