Skip to content

Commit

Permalink
Check in Cloud Job Discovery quick start (#684)
Browse files Browse the repository at this point in the history
* First CJD sample

* Add README

* fix the lint issue

* Add test

* Modify the sample

* Modify the copyright
  • Loading branch information
xinyunh0929 authored and happyhuman committed Jul 17, 2018
1 parent bfdbab3 commit 022055e
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
44 changes: 44 additions & 0 deletions jobs/cjd_sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<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 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
31 changes: 31 additions & 0 deletions jobs/cjd_sample/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
62 changes: 62 additions & 0 deletions jobs/cjd_sample/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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';

// [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;
}

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.name));
} else {
console.log(`No companies found.`);
}
});
});
// [END quickstart]
24 changes: 24 additions & 0 deletions jobs/cjd_sample/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 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`));
});

0 comments on commit 022055e

Please sign in to comment.