Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check in Cloud Job Discovery quick start #684

Merged
merged 9 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this autogenerated using repo-tools generate? If not, it should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the README should be generated from repo-tools generate?
Current README is written by myself. Should I remove it then run repo-tools generate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate: Generating lib_readme in: /usr/local/google/home/xinyunh/githubCode/nodeJsPersonalFork/nodejs-docs-samples/jobs/cjd_sample
generate: Compiling: /usr/local/google/home/xinyunh/githubCode/nodeJsPersonalFork/nodejs-docs-samples/jobs/cjd_sample/README.md
generate: Failed to generate: /usr/local/google/home/xinyunh/githubCode/nodeJsPersonalFork/nodejs-docs-samples/jobs/cjd_sample/README.md
generate: Oh no! Generating failed after 0.0230s.
generate: TypeError: Cannot read property 'toUpperCase' of undefined
at Object.exports.createReleaseQualityBadge (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/cjs/utils/index.js:222:35)
at Object.eval [as main] (eval at createFunctionContext (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), :12:88)
at main (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
at ret (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
at ret (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
at /usr/lib/node_modules/@google-cloud/nodejs-repo-tools/cjs/cli/commands/generate.js:276:46
at Array.forEach ()
at Object.exports.handler (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/cjs/cli/commands/generate.js:238:16)
at Object.runCommand (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/node_modules/yargs/lib/command.js:235:44)
at Object.parseArgs [as _parseArgs] (/usr/lib/node_modules/@google-cloud/nodejs-repo-tools/node_modules/yargs/yargs.js:1014:30)

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a client library specifically for this, as opposed to googleapis? (Paging @theacodes)


// Acquires credentials
google.auth.getApplicationDefault((err, authClient) => {
if (err) {
console.error('Failed to acquire credentials');
console.error(err);
return;
}

if (authClient.createScopedRequired && authClient.createScopedRequired()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with authClient object. Does it have a field and a method both named createScopedRequired? Is it needed to check both of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. I just the follow the same way 'kms' did in their samples for authentication.

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`));
});