google-cloud-recaptcha_enterprise 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ # Copyright 2019 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Protobuf
18
+ # A Timestamp represents a point in time independent of any time zone or local
19
+ # calendar, encoded as a count of seconds and fractions of seconds at
20
+ # nanosecond resolution. The count is relative to an epoch at UTC midnight on
21
+ # January 1, 1970, in the proleptic Gregorian calendar which extends the
22
+ # Gregorian calendar backwards to year one.
23
+ #
24
+ # All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
25
+ # second table is needed for interpretation, using a [24-hour linear
26
+ # smear](https://developers.google.com/time/smear).
27
+ #
28
+ # The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
29
+ # restricting to that range, we ensure that we can convert to and from [RFC
30
+ # 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
31
+ #
32
+ # = Examples
33
+ #
34
+ # Example 1: Compute Timestamp from POSIX `time()`.
35
+ #
36
+ # Timestamp timestamp;
37
+ # timestamp.set_seconds(time(NULL));
38
+ # timestamp.set_nanos(0);
39
+ #
40
+ # Example 2: Compute Timestamp from POSIX `gettimeofday()`.
41
+ #
42
+ # struct timeval tv;
43
+ # gettimeofday(&tv, NULL);
44
+ #
45
+ # Timestamp timestamp;
46
+ # timestamp.set_seconds(tv.tv_sec);
47
+ # timestamp.set_nanos(tv.tv_usec * 1000);
48
+ #
49
+ # Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
50
+ #
51
+ # FILETIME ft;
52
+ # GetSystemTimeAsFileTime(&ft);
53
+ # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
54
+ #
55
+ # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
56
+ # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
57
+ # Timestamp timestamp;
58
+ # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
59
+ # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
60
+ #
61
+ # Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
62
+ #
63
+ # long millis = System.currentTimeMillis();
64
+ #
65
+ # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
66
+ # .setNanos((int) ((millis % 1000) * 1000000)).build();
67
+ #
68
+ #
69
+ # Example 5: Compute Timestamp from current time in Python.
70
+ #
71
+ # timestamp = Timestamp()
72
+ # timestamp.GetCurrentTime()
73
+ #
74
+ # = JSON Mapping
75
+ #
76
+ # In JSON format, the Timestamp type is encoded as a string in the
77
+ # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
78
+ # format is "\\{year}-\\{month}-\\{day}T\\{hour}:\\{min}:\\{sec}[.\\{frac_sec}]Z"
79
+ # where \\{year} is always expressed using four digits while \\{month}, \\{day},
80
+ # \\{hour}, \\{min}, and \\{sec} are zero-padded to two digits each. The fractional
81
+ # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
82
+ # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
83
+ # is required. A proto3 JSON serializer should always use UTC (as indicated by
84
+ # "Z") when printing the Timestamp type and a proto3 JSON parser should be
85
+ # able to accept both UTC and other timezones (as indicated by an offset).
86
+ #
87
+ # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
88
+ # 01:30 UTC on January 15, 2017.
89
+ #
90
+ # In JavaScript, one can convert a Date object to this format using the
91
+ # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
92
+ # method. In Python, a standard `datetime.datetime` object can be converted
93
+ # to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
94
+ # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
95
+ # can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
96
+ # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
97
+ # ) to obtain a formatter capable of generating timestamps in this format.
98
+ # @!attribute [rw] seconds
99
+ # @return [Integer]
100
+ # Represents seconds of UTC time since Unix epoch
101
+ # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
102
+ # 9999-12-31T23:59:59Z inclusive.
103
+ # @!attribute [rw] nanos
104
+ # @return [Integer]
105
+ # Non-negative fractions of a second at nanosecond resolution. Negative
106
+ # second values with fractions must still have non-negative nanos values
107
+ # that count forward in time. Must be from 0 to 999,999,999
108
+ # inclusive.
109
+ class Timestamp; end
110
+ end
111
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # # limitations under the License.
14
+
15
+ module Google
16
+ module Cloud
17
+ module RecaptchaEnterprise
18
+ module V1beta1
19
+ class RecaptchaEnterpriseClient
20
+
21
+ # Alias for Google::Cloud::RecaptchaEnterprise::V1beta1::RecaptchaEnterpriseClient.assessment_path.
22
+ # @param project [String]
23
+ # @param assessment [String]
24
+ # @return [String]
25
+ def assessment_path project, assessment
26
+ self.class.assessment_path project, assessment
27
+ end
28
+
29
+ # Alias for Google::Cloud::RecaptchaEnterprise::V1beta1::RecaptchaEnterpriseClient.project_path.
30
+ # @param project [String]
31
+ # @return [String]
32
+ def project_path project
33
+ self.class.project_path project
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,297 @@
1
+ # Copyright 2019 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # EDITING INSTRUCTIONS
16
+ # This file was generated from the file
17
+ # https://github.com/googleapis/googleapis/blob/master/google/cloud/recaptchaenterprise/v1beta1/recaptchaenterprise.proto,
18
+ # and updates to that file get reflected here through a refresh process.
19
+ # For the short term, the refresh process will only be runnable by Google
20
+ # engineers.
21
+
22
+
23
+ require "json"
24
+ require "pathname"
25
+
26
+ require "google/gax"
27
+
28
+ require "google/cloud/recaptchaenterprise/v1beta1/recaptchaenterprise_pb"
29
+ require "google/cloud/recaptcha_enterprise/v1beta1/credentials"
30
+
31
+ module Google
32
+ module Cloud
33
+ module RecaptchaEnterprise
34
+ module V1beta1
35
+ # Service to determine the likelihood an event is legitimate.
36
+ #
37
+ # @!attribute [r] recaptcha_enterprise_stub
38
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::RecaptchaEnterprise::Stub]
39
+ class RecaptchaEnterpriseClient
40
+ # @private
41
+ attr_reader :recaptcha_enterprise_stub
42
+
43
+ # The default address of the service.
44
+ SERVICE_ADDRESS = "recaptchaenterprise.googleapis.com".freeze
45
+
46
+ # The default port of the service.
47
+ DEFAULT_SERVICE_PORT = 443
48
+
49
+ # The default set of gRPC interceptors.
50
+ GRPC_INTERCEPTORS = []
51
+
52
+ DEFAULT_TIMEOUT = 30
53
+
54
+ # The scopes needed to make gRPC calls to all of the methods defined in
55
+ # this service.
56
+ ALL_SCOPES = [
57
+ "https://www.googleapis.com/auth/cloud-platform"
58
+ ].freeze
59
+
60
+
61
+ ASSESSMENT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
62
+ "projects/{project}/assessments/{assessment}"
63
+ )
64
+
65
+ private_constant :ASSESSMENT_PATH_TEMPLATE
66
+
67
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
68
+ "projects/{project}"
69
+ )
70
+
71
+ private_constant :PROJECT_PATH_TEMPLATE
72
+
73
+ # Returns a fully-qualified assessment resource name string.
74
+ # @param project [String]
75
+ # @param assessment [String]
76
+ # @return [String]
77
+ def self.assessment_path project, assessment
78
+ ASSESSMENT_PATH_TEMPLATE.render(
79
+ :"project" => project,
80
+ :"assessment" => assessment
81
+ )
82
+ end
83
+
84
+ # Returns a fully-qualified project resource name string.
85
+ # @param project [String]
86
+ # @return [String]
87
+ def self.project_path project
88
+ PROJECT_PATH_TEMPLATE.render(
89
+ :"project" => project
90
+ )
91
+ end
92
+
93
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
94
+ # Provides the means for authenticating requests made by the client. This parameter can
95
+ # be many types.
96
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
97
+ # authenticating requests made by this client.
98
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
99
+ # credentials for this client.
100
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
101
+ # credentials for this client.
102
+ # A `GRPC::Core::Channel` will be used to make calls through.
103
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
104
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
105
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
106
+ # metadata for requests, generally, to give OAuth credentials.
107
+ # @param scopes [Array<String>]
108
+ # The OAuth scopes for this service. This parameter is ignored if
109
+ # an updater_proc is supplied.
110
+ # @param client_config [Hash]
111
+ # A Hash for call options for each method. See
112
+ # Google::Gax#construct_settings for the structure of
113
+ # this data. Falls back to the default config if not specified
114
+ # or the specified config is missing data points.
115
+ # @param timeout [Numeric]
116
+ # The default timeout, in seconds, for calls made through this client.
117
+ # @param metadata [Hash]
118
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
119
+ # @param exception_transformer [Proc]
120
+ # An optional proc that intercepts any exceptions raised during an API call to inject
121
+ # custom error handling.
122
+ def initialize \
123
+ credentials: nil,
124
+ scopes: ALL_SCOPES,
125
+ client_config: {},
126
+ timeout: DEFAULT_TIMEOUT,
127
+ metadata: nil,
128
+ exception_transformer: nil,
129
+ lib_name: nil,
130
+ lib_version: ""
131
+ # These require statements are intentionally placed here to initialize
132
+ # the gRPC module only when it's required.
133
+ # See https://github.com/googleapis/toolkit/issues/446
134
+ require "google/gax/grpc"
135
+ require "google/cloud/recaptchaenterprise/v1beta1/recaptchaenterprise_services_pb"
136
+
137
+ credentials ||= Google::Cloud::RecaptchaEnterprise::V1beta1::Credentials.default
138
+
139
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
140
+ updater_proc = Google::Cloud::RecaptchaEnterprise::V1beta1::Credentials.new(credentials).updater_proc
141
+ end
142
+ if credentials.is_a?(GRPC::Core::Channel)
143
+ channel = credentials
144
+ end
145
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
146
+ chan_creds = credentials
147
+ end
148
+ if credentials.is_a?(Proc)
149
+ updater_proc = credentials
150
+ end
151
+ if credentials.is_a?(Google::Auth::Credentials)
152
+ updater_proc = credentials.updater_proc
153
+ end
154
+
155
+ package_version = Gem.loaded_specs['google-cloud-recaptcha_enterprise'].version.version
156
+
157
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
158
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
159
+ google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
160
+ google_api_client << " grpc/#{GRPC::VERSION}"
161
+ google_api_client.freeze
162
+
163
+ headers = { :"x-goog-api-client" => google_api_client }
164
+ headers.merge!(metadata) unless metadata.nil?
165
+ client_config_file = Pathname.new(__dir__).join(
166
+ "recaptcha_enterprise_client_config.json"
167
+ )
168
+ defaults = client_config_file.open do |f|
169
+ Google::Gax.construct_settings(
170
+ "google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1",
171
+ JSON.parse(f.read),
172
+ client_config,
173
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
174
+ timeout,
175
+ errors: Google::Gax::Grpc::API_ERRORS,
176
+ metadata: headers
177
+ )
178
+ end
179
+
180
+ # Allow overriding the service path/port in subclasses.
181
+ service_path = self.class::SERVICE_ADDRESS
182
+ port = self.class::DEFAULT_SERVICE_PORT
183
+ interceptors = self.class::GRPC_INTERCEPTORS
184
+ @recaptcha_enterprise_stub = Google::Gax::Grpc.create_stub(
185
+ service_path,
186
+ port,
187
+ chan_creds: chan_creds,
188
+ channel: channel,
189
+ updater_proc: updater_proc,
190
+ scopes: scopes,
191
+ interceptors: interceptors,
192
+ &Google::Cloud::Recaptchaenterprise::V1beta1::RecaptchaEnterprise::Stub.method(:new)
193
+ )
194
+
195
+ @create_assessment = Google::Gax.create_api_call(
196
+ @recaptcha_enterprise_stub.method(:create_assessment),
197
+ defaults["create_assessment"],
198
+ exception_transformer: exception_transformer,
199
+ params_extractor: proc do |request|
200
+ {'parent' => request.parent}
201
+ end
202
+ )
203
+ @annotate_assessment = Google::Gax.create_api_call(
204
+ @recaptcha_enterprise_stub.method(:annotate_assessment),
205
+ defaults["annotate_assessment"],
206
+ exception_transformer: exception_transformer,
207
+ params_extractor: proc do |request|
208
+ {'name' => request.name}
209
+ end
210
+ )
211
+ end
212
+
213
+ # Service calls
214
+
215
+ # Creates an Assessment of the likelihood an event is legitimate.
216
+ #
217
+ # @param parent [String]
218
+ # Required. The name of the project in which the assessment will be created,
219
+ # in the format "projects/\\{project_number}".
220
+ # @param assessment [Google::Cloud::Recaptchaenterprise::V1beta1::Assessment | Hash]
221
+ # The asessment details.
222
+ # A hash of the same form as `Google::Cloud::Recaptchaenterprise::V1beta1::Assessment`
223
+ # can also be provided.
224
+ # @param options [Google::Gax::CallOptions]
225
+ # Overrides the default settings for this call, e.g, timeout,
226
+ # retries, etc.
227
+ # @yield [result, operation] Access the result along with the RPC operation
228
+ # @yieldparam result [Google::Cloud::Recaptchaenterprise::V1beta1::Assessment]
229
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
230
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::Assessment]
231
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
232
+ # @example
233
+ # require "google/cloud/recaptcha_enterprise"
234
+ #
235
+ # recaptcha_enterprise_client = Google::Cloud::RecaptchaEnterprise.new(version: :v1beta1)
236
+ # formatted_parent = Google::Cloud::RecaptchaEnterprise::V1beta1::RecaptchaEnterpriseClient.project_path("[PROJECT]")
237
+ #
238
+ # # TODO: Initialize `assessment`:
239
+ # assessment = {}
240
+ # response = recaptcha_enterprise_client.create_assessment(formatted_parent, assessment)
241
+
242
+ def create_assessment \
243
+ parent,
244
+ assessment,
245
+ options: nil,
246
+ &block
247
+ req = {
248
+ parent: parent,
249
+ assessment: assessment
250
+ }.delete_if { |_, v| v.nil? }
251
+ req = Google::Gax::to_proto(req, Google::Cloud::Recaptchaenterprise::V1beta1::CreateAssessmentRequest)
252
+ @create_assessment.call(req, options, &block)
253
+ end
254
+
255
+ # Annotates a previously created Assessment to provide additional information
256
+ # on whether the event turned out to be authentic or fradulent.
257
+ #
258
+ # @param name [String]
259
+ # Required. The resource name of the Assessment, in the format
260
+ # "projects/\\{project_number}/assessments/\\{assessment_id}".
261
+ # @param annotation [Google::Cloud::Recaptchaenterprise::V1beta1::AnnotateAssessmentRequest::Annotation]
262
+ # The annotation that will be assigned to the Event.
263
+ # @param options [Google::Gax::CallOptions]
264
+ # Overrides the default settings for this call, e.g, timeout,
265
+ # retries, etc.
266
+ # @yield [result, operation] Access the result along with the RPC operation
267
+ # @yieldparam result [Google::Cloud::Recaptchaenterprise::V1beta1::AnnotateAssessmentResponse]
268
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
269
+ # @return [Google::Cloud::Recaptchaenterprise::V1beta1::AnnotateAssessmentResponse]
270
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
271
+ # @example
272
+ # require "google/cloud/recaptcha_enterprise"
273
+ #
274
+ # recaptcha_enterprise_client = Google::Cloud::RecaptchaEnterprise.new(version: :v1beta1)
275
+ # formatted_name = Google::Cloud::RecaptchaEnterprise::V1beta1::RecaptchaEnterpriseClient.assessment_path("[PROJECT]", "[ASSESSMENT]")
276
+ #
277
+ # # TODO: Initialize `annotation`:
278
+ # annotation = :ANNOTATION_UNSPECIFIED
279
+ # response = recaptcha_enterprise_client.annotate_assessment(formatted_name, annotation)
280
+
281
+ def annotate_assessment \
282
+ name,
283
+ annotation,
284
+ options: nil,
285
+ &block
286
+ req = {
287
+ name: name,
288
+ annotation: annotation
289
+ }.delete_if { |_, v| v.nil? }
290
+ req = Google::Gax::to_proto(req, Google::Cloud::Recaptchaenterprise::V1beta1::AnnotateAssessmentRequest)
291
+ @annotate_assessment.call(req, options, &block)
292
+ end
293
+ end
294
+ end
295
+ end
296
+ end
297
+ end
@@ -0,0 +1,36 @@
1
+ {
2
+ "interfaces": {
3
+ "google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1": {
4
+ "retry_codes": {
5
+ "idempotent": [
6
+ "DEADLINE_EXCEEDED",
7
+ "UNAVAILABLE"
8
+ ],
9
+ "non_idempotent": []
10
+ },
11
+ "retry_params": {
12
+ "default": {
13
+ "initial_retry_delay_millis": 100,
14
+ "retry_delay_multiplier": 1.3,
15
+ "max_retry_delay_millis": 60000,
16
+ "initial_rpc_timeout_millis": 20000,
17
+ "rpc_timeout_multiplier": 1.0,
18
+ "max_rpc_timeout_millis": 20000,
19
+ "total_timeout_millis": 600000
20
+ }
21
+ },
22
+ "methods": {
23
+ "CreateAssessment": {
24
+ "timeout_millis": 60000,
25
+ "retry_codes_name": "non_idempotent",
26
+ "retry_params_name": "default"
27
+ },
28
+ "AnnotateAssessment": {
29
+ "timeout_millis": 60000,
30
+ "retry_codes_name": "non_idempotent",
31
+ "retry_params_name": "default"
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }