Skip to content

Commit

Permalink
code demo for jobs api v3 (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenlongZ authored and fhinkel committed Dec 7, 2018
1 parent 43cb78c commit 7d5b05b
Show file tree
Hide file tree
Showing 30 changed files with 2,523 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions jobs/v3/README.md
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
125 changes: 125 additions & 0 deletions jobs/v3/auto-complete-sample.js
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;
}
})();
Loading

0 comments on commit 7d5b05b

Please sign in to comment.