diff --git a/README.md b/README.md index fca1b48c749..5171ae39576 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ The are three primary ways to authenticate to Google APIs. Some service support To learn more about the authentication client, see the [Google Auth Library](https://github.com/googleapis/google-auth-library-nodejs). ### OAuth2 client -This client comes with an [OAuth2][oauth] client that allows you to retrieve an access token and refreshes the token and retry the request seamlessly The basics of Google's OAuth2 implementation is explained on [Google Authorization and Authentication documentation][authdocs]. +This client comes with an [OAuth2][oauth] client that allows you to retrieve an access token, refresh it, and retry the request seamlessly. The basics of Google's OAuth2 implementation is explained on [Google Authorization and Authentication documentation][authdocs]. In the following examples, you may need a `CLIENT_ID`, `CLIENT_SECRET` and `REDIRECT_URL`. You can find these pieces of information by going to the [Developer Console][devconsole], clicking your project --> APIs & auth --> credentials. diff --git a/samples/jobs/jobs.js b/samples/jobs/jobs.js new file mode 100644 index 00000000000..673d7e0c9e8 --- /dev/null +++ b/samples/jobs/jobs.js @@ -0,0 +1,53 @@ +// Copyright 2016, Google, Inc. +// 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 {google} = require('googleapis'); +const sampleClient = require('../sampleclient'); + +const jobService = google.jobs({ + version: 'v3', + auth: sampleClient.oAuth2Client, +}); + +async function runSample() { + const projectId = await google.auth.getProjectId(); + const res = await jobService.projects.companies.create({ + parent: `project/${projectId}`, + requestBody: { + company: { + displayName: 'ABC co.', + externalId: '12345', + }, + }, + }); + console.log(res.data); + return res.data; +} + +if (module === require.main) { + const scopes = [ + 'https://www.googleapis.com/auth/jobs', + 'https://www.googleapis.com/auth/cloud-platform', + ]; + sampleClient + .authenticate(scopes) + .then(runSample) + .catch(console.error); +} + +module.exports = { + runSample, + client: sampleClient.oAuth2Client, +}; diff --git a/src/apis/jobs/README.md b/src/apis/jobs/README.md index 621f306363b..891a8591f56 100644 --- a/src/apis/jobs/README.md +++ b/src/apis/jobs/README.md @@ -33,6 +33,10 @@ const { jobs, auth } = Jobs; ``` +## v3 Samples + +You can find samples of v3 of the Talent Solution API [here](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/jobs/v3) + ## License This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/googleapis/google-api-nodejs-client/blob/master/LICENSE). diff --git a/test/samples/test.samples.jobs.ts b/test/samples/test.samples.jobs.ts new file mode 100644 index 00000000000..5bbd9ffd0ef --- /dev/null +++ b/test/samples/test.samples.jobs.ts @@ -0,0 +1,45 @@ +// 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. + +import * as assert from 'assert'; +import * as nock from 'nock'; +import {Utils} from '../utils'; + +nock.disableNetConnect(); + +// tslint:disable: no-any +const samples: any = { + jobs: require('../../../samples/jobs/jobs.js'), +}; + +for (const p in samples) { + if (samples[p]) { + samples.jobs.client.credentials = {access_token: 'not-a-token'}; + } +} + +describe.skip('Talent API Samples', () => { + afterEach(() => { + nock.cleanAll(); + }); + + it('should create a company', async () => { + const scope = + nock(Utils.baseUrl) + .post(`/v3/jobs/project/${process.env.GCLOUD_PROJECT}/companies`) + .reply(200, {}); + const data = await samples.jobs.runSample(); + assert(data); + scope.done(); + }); +});