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

samples(talent): migrate code from googleapis/nodejs-talent #2813

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
94 changes: 94 additions & 0 deletions talent/snippets/job_search_autocomplete_job_title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2020 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
//
// https://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 job_search_autocomplete_job_title]

const talent = require('@google-cloud/talent').v4;

/**
* Complete job title given partial text (autocomplete)
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the TenantId
*/
function sampleCompleteQuery(
projectId,
tenantId,
query,
numResults,
languageCode
) {
const client = new talent.CompletionClient();
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
// const query = '[partially typed job title]';
// const numResults = 5;
// const languageCode = 'en-US';
const formattedParent = client.tenantPath(projectId, tenantId);
const languageCodes = [languageCode];
const request = {
parent: formattedParent,
query: query,
pageSize: numResults,
languageCodes: languageCodes,
};
client
.completeQuery(request)
.then(responses => {
const response = responses[0];
for (const result of response.completionResults) {
console.log(`Suggested title: ${result.suggestion}`);
// Suggestion type is JOB_TITLE or COMPANY_TITLE
console.log(`Suggestion type: ${result.type}`);
}
})
.catch(err => {
console.error(err);
});
}

// [END job_search_autocomplete_job_title]
// tslint:disable-next-line:no-any

const argv = require('yargs')
.option('project_id', {
default: 'Your Google Cloud Project ID',
string: true,
})
.option('tenant_id', {
default: 'Your Tenant ID (using tenancy is optional)',
string: true,
})
.option('query', {
default: '[partially typed job title]',
string: true,
})
.option('num_results', {
default: 5,
number: true,
})
.option('language_code', {
default: 'en-US',
string: true,
}).argv;

sampleCompleteQuery(
argv.project_id,
argv.tenant_id,
argv.query,
argv.num_results,
argv.language_code
);
63 changes: 63 additions & 0 deletions talent/snippets/job_search_batch_delete_job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2020 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
//
// https://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 job_search_batch_delete_job]

const talent = require('@google-cloud/talent').v4;

/**
* Batch delete jobs using a filter
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the Tenantd
* @param filter {string} The filter string specifies the jobs to be deleted.
* For example:
* companyName = "projects/api-test-project/companies/123" AND equisitionId = "req-1"
*/
function sampleBatchDeleteJobs(projectId, tenantId, filter) {
const client = new talent.JobServiceClient();
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
// const filter = '[Query]';
const formattedParent = client.tenantPath(projectId, tenantId);
const request = {
parent: formattedParent,
filter: filter,
};
client.batchDeleteJobs(request).catch(err => {
console.error(err);
});
console.log('Batch deleted jobs from filter');
}

// [END job_search_batch_delete_job]
// tslint:disable-next-line:no-any

const argv = require('yargs')
.option('project_id', {
default: 'Your Google Cloud Project ID',
string: true,
})
.option('tenant_id', {
default: 'Your Tenant ID (using tenancy is optional)',
string: true,
})
.option('filter', {
default: '[Query]',
string: true,
}).argv;

sampleBatchDeleteJobs(argv.project_id, argv.tenant_id, argv.filter);
91 changes: 91 additions & 0 deletions talent/snippets/job_search_commute_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2020 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
//
// https://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 job_search_commute_search]

const talent = require('@google-cloud/talent').v4;

/** Search Jobs using commute distance */
function sampleSearchJobs(projectId, tenantId) {
const client = new talent.JobServiceClient();
// Iterate over all elements.
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
const formattedParent = client.tenantPath(projectId, tenantId);
const domain = 'www.example.com';
const sessionId = 'Hashed session identifier';
const userId = 'Hashed user identifier';
const requestMetadata = {
domain: domain,
sessionId: sessionId,
userId: userId,
};
const commuteMethod = 'TRANSIT';
const seconds = 1800;
const travelDuration = {
seconds: seconds,
};
const latitude = 37.422408;
const longitude = 122.084068;
const startCoordinates = {
latitude: latitude,
longitude: longitude,
};
const commuteFilter = {
commuteMethod: commuteMethod,
travelDuration: travelDuration,
startCoordinates: startCoordinates,
};
const jobQuery = {
commuteFilter: commuteFilter,
};
const request = {
parent: formattedParent,
requestMetadata: requestMetadata,
jobQuery: jobQuery,
};

client
.searchJobs(request)
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
console.log(`Job summary: ${resource.jobSummary}`);
console.log(`Job title snippet: ${resource.jobTitleSnippet}`);
const job = resource.job;
console.log(`Job name: ${job.name}`);
console.log(`Job title: ${job.title}`);
}
})
.catch(err => {
console.error(err);
});
}

// [END job_search_commute_search]
// tslint:disable-next-line:no-any

const argv = require('yargs')
.option('project_id', {
default: 'Your Google Cloud Project ID',
string: true,
})
.option('tenant_id', {
default: 'Your Tenant ID (using tenancy is optional)',
string: true,
}).argv;

sampleSearchJobs(argv.project_id, argv.tenant_id);
106 changes: 106 additions & 0 deletions talent/snippets/job_search_create_client_event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2020 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
//
// https://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 job_search_create_client_event]

const talent = require('@google-cloud/talent').v4;

/**
* Creates a client event
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the Tenant
* @param requestId {string} A unique ID generated in the API responses.
* Value should be set to the request_id from an API response.
* @param eventId {string} A unique identifier, generated by the client application
*/
function sampleCreateClientEvent(projectId, tenantId, requestId, eventId) {
const client = new talent.EventServiceClient();
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
// const requestId = '[request_id from ResponseMetadata]';
// const eventId = '[Set this to a unique identifier]';
const formattedParent = client.tenantPath(projectId, tenantId);

// The timestamp of the event as seconds of UTC time since Unix epoch
// For more information on how to create google.protobuf.Timestamps
// See: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
const seconds = 0;
const createTime = {
seconds: seconds,
};

// The type of event attributed to the behavior of the end user
const type = 'VIEW';

// List of job names associated with this event
const jobsElement = 'projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]';
const jobsElement2 =
'projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]';
const jobs = [jobsElement, jobsElement2];
const jobEvent = {
type: type,
jobs: jobs,
};
const clientEvent = {
requestId: requestId,
eventId: eventId,
createTime: createTime,
jobEvent: jobEvent,
};
const request = {
parent: formattedParent,
clientEvent: clientEvent,
};
client
.createClientEvent(request)
.then(responses => {
const response = responses[0];
console.log('Created client event');
console.log(`Response: ${response}`);
})
.catch(err => {
console.error(err);
});
}

// [END job_search_create_client_event]
// tslint:disable-next-line:no-any

const argv = require('yargs')
.option('project_id', {
default: 'Your Google Cloud Project ID',
string: true,
})
.option('tenant_id', {
default: 'Your Tenant ID (using tenancy is optional)',
string: true,
})
.option('request_id', {
default: '[request_id from ResponseMetadata]',
string: true,
})
.option('event_id', {
default: '[Set this to a unique identifier]',
string: true,
}).argv;

sampleCreateClientEvent(
argv.project_id,
argv.tenant_id,
argv.request_id,
argv.event_id
);
Loading