|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2019 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# DO NOT EDIT! This is a generated sample ("Request", "job_search_create_client_event") |
| 18 | + |
| 19 | +# To install the latest published package dependency, execute the following: |
| 20 | +# pip install google-cloud-talent |
| 21 | + |
| 22 | +import sys |
| 23 | + |
| 24 | +# [START job_search_create_client_event] |
| 25 | + |
| 26 | +from google.cloud import talent_v4beta1 |
| 27 | +from google.cloud.talent_v4beta1 import enums |
| 28 | +import six |
| 29 | + |
| 30 | + |
| 31 | +def sample_create_client_event(project_id, tenant_id, request_id, event_id): |
| 32 | + """ |
| 33 | + Creates a client event |
| 34 | +
|
| 35 | + Args: |
| 36 | + project_id Your Google Cloud Project ID |
| 37 | + tenant_id Identifier of the Tenant |
| 38 | + request_id A unique ID generated in the API responses. |
| 39 | + Value should be set to the request_id from an API response. |
| 40 | + event_id A unique identifier, generated by the client application |
| 41 | + """ |
| 42 | + # [START job_search_create_client_event_core] |
| 43 | + |
| 44 | + client = talent_v4beta1.EventServiceClient() |
| 45 | + |
| 46 | + # project_id = 'Your Google Cloud Project ID' |
| 47 | + # tenant_id = 'Your Tenant ID (using tenancy is optional)' |
| 48 | + # request_id = '[request_id from ResponseMetadata]' |
| 49 | + # event_id = '[Set this to a unique identifier]' |
| 50 | + |
| 51 | + if isinstance(project_id, six.binary_type): |
| 52 | + project_id = project_id.decode('utf-8') |
| 53 | + if isinstance(tenant_id, six.binary_type): |
| 54 | + tenant_id = tenant_id.decode('utf-8') |
| 55 | + if isinstance(request_id, six.binary_type): |
| 56 | + request_id = request_id.decode('utf-8') |
| 57 | + if isinstance(event_id, six.binary_type): |
| 58 | + event_id = event_id.decode('utf-8') |
| 59 | + parent = client.tenant_path(project_id, tenant_id) |
| 60 | + |
| 61 | + # The timestamp of the event as seconds of UTC time since Unix epoch |
| 62 | + # For more information on how to create google.protobuf.Timestamps |
| 63 | + # See: |
| 64 | + # https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto |
| 65 | + seconds = 0 |
| 66 | + create_time = {'seconds': seconds} |
| 67 | + |
| 68 | + # The type of event attributed to the behavior of the end user |
| 69 | + type_ = enums.JobEvent.JobEventType.VIEW |
| 70 | + |
| 71 | + # List of job names associated with this event |
| 72 | + jobs_element = 'projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]' |
| 73 | + jobs_element_2 = 'projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]' |
| 74 | + jobs = [jobs_element, jobs_element_2] |
| 75 | + job_event = {'type': type_, 'jobs': jobs} |
| 76 | + client_event = { |
| 77 | + 'request_id': request_id, |
| 78 | + 'event_id': event_id, |
| 79 | + 'create_time': create_time, |
| 80 | + 'job_event': job_event |
| 81 | + } |
| 82 | + |
| 83 | + response = client.create_client_event(parent, client_event) |
| 84 | + print(response) |
| 85 | + |
| 86 | + # [END job_search_create_client_event_core] |
| 87 | + |
| 88 | + |
| 89 | +# [END job_search_create_client_event] |
| 90 | + |
| 91 | + |
| 92 | +def main(): |
| 93 | + import argparse |
| 94 | + |
| 95 | + parser = argparse.ArgumentParser() |
| 96 | + parser.add_argument('--project_id', |
| 97 | + type=str, |
| 98 | + default='Your Google Cloud Project ID') |
| 99 | + parser.add_argument('--tenant_id', |
| 100 | + type=str, |
| 101 | + default='Your Tenant ID (using tenancy is optional)') |
| 102 | + parser.add_argument('--request_id', |
| 103 | + type=str, |
| 104 | + default='[request_id from ResponseMetadata]') |
| 105 | + parser.add_argument('--event_id', |
| 106 | + type=str, |
| 107 | + default='[Set this to a unique identifier]') |
| 108 | + args = parser.parse_args() |
| 109 | + |
| 110 | + sample_create_client_event(args.project_id, args.tenant_id, |
| 111 | + args.request_id, args.event_id) |
| 112 | + |
| 113 | + |
| 114 | +if __name__ == '__main__': |
| 115 | + main() |
0 commit comments