reach-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +1 -0
  3. data/.gitignore +18 -0
  4. data/.rubocop.yml +58 -0
  5. data/.rubocop_todo.yml +193 -0
  6. data/AUTHORS.md +52 -0
  7. data/CHANGES.md +3 -0
  8. data/CODE_OF_CONDUCT.md +73 -0
  9. data/CONTRIBUTING.md +163 -0
  10. data/Dockerfile +9 -0
  11. data/Gemfile +3 -0
  12. data/ISSUE_TEMPLATE.md +30 -0
  13. data/LICENSE +21 -0
  14. data/Makefile +34 -0
  15. data/PULL_REQUEST_TEMPLATE.md +31 -0
  16. data/README.md +237 -0
  17. data/Rakefile +10 -0
  18. data/UPGRADE.md +5 -0
  19. data/VERSIONS.md +35 -0
  20. data/advanced-examples/custom-http-client.md +166 -0
  21. data/examples/examples.rb +23 -0
  22. data/githooks/pre-commit +1 -0
  23. data/lib/rack/reach_webhook_authentication.rb +72 -0
  24. data/lib/reach-ruby/framework/reach_response.rb +19 -0
  25. data/lib/reach-ruby/framework/request.rb +41 -0
  26. data/lib/reach-ruby/framework/response.rb +18 -0
  27. data/lib/reach-ruby/framework/rest/domain.rb +39 -0
  28. data/lib/reach-ruby/framework/rest/error.rb +51 -0
  29. data/lib/reach-ruby/framework/rest/helper.rb +11 -0
  30. data/lib/reach-ruby/framework/rest/page.rb +144 -0
  31. data/lib/reach-ruby/framework/rest/resource.rb +23 -0
  32. data/lib/reach-ruby/framework/rest/version.rb +240 -0
  33. data/lib/reach-ruby/framework/serialize.rb +81 -0
  34. data/lib/reach-ruby/framework/values.rb +9 -0
  35. data/lib/reach-ruby/http/http_client.rb +82 -0
  36. data/lib/reach-ruby/http.rb +5 -0
  37. data/lib/reach-ruby/rest/api/authentix/.openapi-generator/FILES +10 -0
  38. data/lib/reach-ruby/rest/api/authentix/.openapi-generator/VERSION +1 -0
  39. data/lib/reach-ruby/rest/api/authentix/.openapi-generator-ignore +23 -0
  40. data/lib/reach-ruby/rest/api/authentix/authentication_trial_item.rb +418 -0
  41. data/lib/reach-ruby/rest/api/authentix/authentication_trial_stat_item.rb +279 -0
  42. data/lib/reach-ruby/rest/api/authentix/configuration_item/authentication_control_item.rb +214 -0
  43. data/lib/reach-ruby/rest/api/authentix/configuration_item/authentication_item.rb +449 -0
  44. data/lib/reach-ruby/rest/api/authentix/configuration_item.rb +583 -0
  45. data/lib/reach-ruby/rest/api/authentix.rb +72 -0
  46. data/lib/reach-ruby/rest/api/messaging/.openapi-generator/FILES +2 -0
  47. data/lib/reach-ruby/rest/api/messaging/.openapi-generator/VERSION +1 -0
  48. data/lib/reach-ruby/rest/api/messaging/.openapi-generator-ignore +23 -0
  49. data/lib/reach-ruby/rest/api/messaging/messaging_item.rb +582 -0
  50. data/lib/reach-ruby/rest/api/messaging.rb +51 -0
  51. data/lib/reach-ruby/rest/api.rb +50 -0
  52. data/lib/reach-ruby/rest/client.rb +130 -0
  53. data/lib/reach-ruby/rest.rb +13 -0
  54. data/lib/reach-ruby/security/request_validator.rb +149 -0
  55. data/lib/reach-ruby/util/configuration.rb +25 -0
  56. data/lib/reach-ruby/version.rb +3 -0
  57. data/lib/reach-ruby.rb +44 -0
  58. data/reach-ruby.gemspec +38 -0
  59. data/sonar-project.properties +13 -0
  60. metadata +267 -0
@@ -0,0 +1,449 @@
1
+ ##
2
+ # This code was generated by
3
+ # ___ ___ _ ___ _ _ _____ _ _ _ ___ ___ _ ___ ___ ___ _ ___ ___ ___ _ _ ___ ___ _ _____ ___ ___
4
+ # | _ \ __| /_\ / __| || |__|_ _/_\ | | | |/ | \ / / | /_\ | _ ) __|___ / _ \ /_\ |_ _|__ / __| __| \| | __| _ \ /_\_ _/ _ \| _ \
5
+ # | / _| / _ \ (__| __ |___|| |/ _ \| |__| ' < \ V /| |__ / _ \| _ \__ \___| (_) / _ \ | |___| (_ | _|| .` | _|| / / _ \| || (_) | /
6
+ # |_|_\___/_/ \_\___|_||_| |_/_/ \_\____|_|\_\ |_| |____/_/ \_\___/___/ \___/_/ \_\___| \___|___|_|\_|___|_|_\/_/ \_\_| \___/|_|_\
7
+ #
8
+ # Reach Authentix API
9
+ # Reach Authentix API helps you easily integrate user authentification in your application. The authentification allows to verify that a user is indeed at the origin of a request from your application. At the moment, the Reach Authentix API supports the following channels: * SMS * Email We are continuously working to add additionnal channels. ## Base URL All endpoints described in this documentation are relative to the following base URL: ``` https://api.reach.talkylabs.com/rest/authentix/v1/ ``` The API is provided over HTTPS protocol to ensure data privacy. ## API Authentication Requests made to the API must be authenticated. You need to provide the `ApiUser` and `ApiKey` associated with your applet. This information could be found in the settings of the applet. ```curl curl -X GET [BASE_URL]/configurations -H \"ApiUser:[Your_Api_User]\" -H \"ApiKey:[Your_Api_Key]\" ``` ## Reach Authentix API Workflow Three steps are needed in order to authenticate a given user using the Reach Authentix API. ### Step 1: Create an Authentix configuration A configuration is a set of settings used to define and send an authentication code to a user. This includes, for example: ``` - the length of the authentication code, - the message template, - and so on... ``` A configuaration could be created via the web application or directly using the Reach Authentix API. This step does not need to be performed every time one wants to use the Reach Authentix API. Indeed, once created, a configuartion could be used to authenticate several users in the future. ### Step 2: Send an authentication code A configuration is used to send an authentication code via a selected channel to a user. For now, the supported channels are `sms`, and `email`. We are working hard to support additional channels. Newly created authentications will have a status of `awaiting`. ### Step 3: Verify the authentication code This step allows to verify that the code submitted by the user matched the one sent previously. If, there is a match, then the status of the authentication changes from `awaiting` to `passed`. Otherwise, the status remains `awaiting` until either it is verified or it expires. In the latter case, the status becomes `expired`.
10
+ #
11
+ # NOTE: This class is auto generated by OpenAPI Generator.
12
+ # https://openapi-generator.tech
13
+ # Do not edit the class manually.
14
+ #
15
+
16
+
17
+ module Reach
18
+ module REST
19
+ class Api
20
+ class Authentix < Version
21
+ class ConfigurationItemContext < InstanceContext
22
+
23
+ class AuthenticationItemList < ListResource
24
+ ##
25
+ # Initialize the AuthenticationItemList
26
+ # @param [Version] version Version that contains the resource
27
+ # @return [AuthenticationItemList] AuthenticationItemList
28
+ def initialize(version, configuration_id: nil)
29
+ super(version)
30
+ # Path Solution
31
+ @solution = { configuration_id: configuration_id }
32
+ @uri = "/authentix/v1/configurations/#{@solution[:configuration_id]}/authentications"
33
+
34
+ end
35
+ ##
36
+ # Start the AuthenticationItemInstance
37
+ # @param [String] dest The phone number or email where to send the authentication code. Phone numbers must be in E.164 format.
38
+ # @param [String] channel The channel by which the authentication code is sent.
39
+ # @param [String] service_name a service name overwriting the one defined in the configuration.
40
+ # @param [String] custom_code the pre-generated code to be sent. Its length should be between 4 and 10 inclusive.
41
+ # @param [String] payment_info Information related to the digital payment to authenticate. It is required when `usedForDigitalPayment` is true. It is ignored otherwise. It is a stringfied JSON map where keys are `payee`, `amount`, and `currency` and the associated values are respectively the payee, the amount, and the currency of a financial transaction.
42
+ # @param [String] template_id This is the ID of the message template to use for sending the authenetication code. It could be an sms or email template depending on the channel being used. It overwirites the template ID defined in the configuration if any.
43
+ # @param [String] template_data_map A stringfied JSON map where keys are message template parameters and the values are the parameter values to be used when sending the authentication code. It may also be used to provide additional parameters for sending email based authentications such as the email used for sending the code.
44
+ # @return [AuthenticationItemInstance] Startd AuthenticationItemInstance
45
+ def start(
46
+ dest: nil,
47
+ channel: nil,
48
+ service_name: :unset,
49
+ custom_code: :unset,
50
+ payment_info: :unset,
51
+ template_id: :unset,
52
+ template_data_map: :unset
53
+ )
54
+
55
+ baseParams = {
56
+ }
57
+ data = Reach::Values.of(baseParams.merge({
58
+ 'dest' => dest,
59
+ 'channel' => channel,
60
+ 'serviceName' => service_name,
61
+ 'customCode' => custom_code,
62
+ 'paymentInfo' => payment_info,
63
+ 'templateId' => template_id,
64
+ 'templateDataMap' => template_data_map,
65
+ }))
66
+
67
+
68
+
69
+ payload = @version.start('POST', @uri, data: data)
70
+ AuthenticationItemInstance.new(
71
+ @version,
72
+ payload,
73
+ configuration_id: @solution[:configuration_id],
74
+ )
75
+ end
76
+
77
+
78
+ ##
79
+ # Lists AuthenticationItemInstance records from the API as a list.
80
+ # Unlike stream(), this operation is eager and will load `limit` records into
81
+ # memory before returning.
82
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
83
+ # guarantees to never return more than limit. Default is no limit
84
+ # @param [Integer] page_size Number of records to fetch per request, when
85
+ # not set will use the default value of 50 records. If no page_size is defined
86
+ # but a limit is defined, stream() will attempt to read the limit with the most
87
+ # efficient page size, i.e. min(limit, 1000)
88
+ # @return [Array] Array of up to limit results
89
+ def list(limit: nil, page_size: nil)
90
+ self.stream(
91
+ limit: limit,
92
+ page_size: page_size
93
+ ).entries
94
+ end
95
+
96
+ ##
97
+ # Streams Instance records from the API as an Enumerable.
98
+ # This operation lazily loads records as efficiently as possible until the limit
99
+ # is reached.
100
+ # @param [Integer] limit Upper limit for the number of records to return. stream()
101
+ # guarantees to never return more than limit. Default is no limit
102
+ # @param [Integer] page_size Number of records to fetch per request, when
103
+ # not set will use the default value of 50 records. If no page_size is defined
104
+ # but a limit is defined, stream() will attempt to read the limit with the most
105
+ # efficient page size, i.e. min(limit, 1000)
106
+ # @return [Enumerable] Enumerable that will yield up to limit results
107
+ def stream(limit: nil, page_size: nil)
108
+ limits = @version.read_limits(limit, page_size)
109
+
110
+ page = self.page(
111
+ page_size: limits[:page_size], )
112
+
113
+ @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
114
+ end
115
+
116
+ ##
117
+ # When passed a block, yields AuthenticationItemInstance records from the API.
118
+ # This operation lazily loads records as efficiently as possible until the limit
119
+ # is reached.
120
+ def each
121
+ limits = @version.read_limits
122
+
123
+ page = self.page(page_size: limits[:page_size], )
124
+
125
+ @version.stream(page,
126
+ limit: limits[:limit],
127
+ page_limit: limits[:page_limit]).each {|x| yield x}
128
+ end
129
+
130
+ ##
131
+ # Retrieve a single page of AuthenticationItemInstance records from the API.
132
+ # Request is executed immediately.
133
+ # @param [Integer] page_number Page Number, this value is simply for client state
134
+ # @param [Integer] page_size Number of records to return, defaults to 20
135
+ # @return [Page] Page of AuthenticationItemInstance
136
+ def page(page_token: :unset, page_number: :unset, page_size: :unset)
137
+ params = Reach::Values.of({
138
+
139
+ 'page' => page_number,
140
+ 'pageSize' => page_size,
141
+ })
142
+
143
+ baseUrl = @version.url_without_pagination_info(@version.absolute_url(@uri), params)
144
+ response = @version.page('GET', @uri, params: params)
145
+
146
+ AuthenticationItemPage.new(baseUrl, @version, response, @solution)
147
+ end
148
+
149
+ ##
150
+ # Retrieve a single page of AuthenticationItemInstance records from the API.
151
+ # Request is executed immediately.
152
+ # @param [String] target_url API-generated URL for the requested results page
153
+ # @return [Page] Page of AuthenticationItemInstance
154
+ def get_page(target_url)
155
+ baseUrl = @version.url_without_pagination_info(target_url)
156
+ response = @version.domain.request(
157
+ 'GET',
158
+ target_url
159
+ )
160
+ AuthenticationItemPage.new(baseUrl, @version, response, @solution)
161
+ end
162
+
163
+
164
+
165
+ # Provide a user friendly representation
166
+ def to_s
167
+ '#<Reach.Api.Authentix.AuthenticationItemList>'
168
+ end
169
+ end
170
+
171
+
172
+ class AuthenticationItemContext < InstanceContext
173
+ ##
174
+ # Initialize the AuthenticationItemContext
175
+ # @param [Version] version Version that contains the resource
176
+ # @param [String] configuration_id The identifier of the configuration being used.
177
+ # @param [String] authentication_id The identifier of the authentication to be updated.
178
+ # @return [AuthenticationItemContext] AuthenticationItemContext
179
+ def initialize(version, configuration_id, authentication_id)
180
+ super(version)
181
+
182
+ # Path Solution
183
+ @solution = { configuration_id: configuration_id, authentication_id: authentication_id, }
184
+ @uri = "/authentix/v1/configurations/#{@solution[:configuration_id]}/authentications/#{@solution[:authentication_id]}"
185
+
186
+
187
+ end
188
+ ##
189
+ # Fetch the AuthenticationItemInstance
190
+ # @return [AuthenticationItemInstance] Fetched AuthenticationItemInstance
191
+ def fetch
192
+
193
+ baseParams = {
194
+ }
195
+
196
+
197
+ payload = @version.fetch('GET', @uri)
198
+ AuthenticationItemInstance.new(
199
+ @version,
200
+ payload,
201
+ configuration_id: @solution[:configuration_id],
202
+ authentication_id: @solution[:authentication_id],
203
+ )
204
+ end
205
+
206
+ ##
207
+ # Update the AuthenticationItemInstance
208
+ # @param [String] status The new status of the authentication.
209
+ # @return [AuthenticationItemInstance] Updated AuthenticationItemInstance
210
+ def update(
211
+ status: nil
212
+ )
213
+
214
+ baseParams = {
215
+ }
216
+ data = Reach::Values.of(baseParams.merge({
217
+ 'status' => status,
218
+ }))
219
+
220
+
221
+
222
+ payload = @version.update('POST', @uri, data: data)
223
+ AuthenticationItemInstance.new(
224
+ @version,
225
+ payload,
226
+ configuration_id: @solution[:configuration_id],
227
+ authentication_id: @solution[:authentication_id],
228
+ )
229
+ end
230
+
231
+
232
+ ##
233
+ # Provide a user friendly representation
234
+ def to_s
235
+ context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
236
+ "#<Reach.Api.Authentix.AuthenticationItemContext #{context}>"
237
+ end
238
+
239
+ ##
240
+ # Provide a detailed, user friendly representation
241
+ def inspect
242
+ context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
243
+ "#<Reach.Api.Authentix.AuthenticationItemContext #{context}>"
244
+ end
245
+ end
246
+
247
+ class AuthenticationItemPage < Page
248
+ ##
249
+ # Initialize the AuthenticationItemPage
250
+ # @param [String] baseUrl url without pagination info
251
+ # @param [Version] version Version that contains the resource
252
+ # @param [Response] response Response from the API
253
+ # @param [Hash] solution Path solution for the resource
254
+ # @return [AuthenticationItemPage] AuthenticationItemPage
255
+ def initialize(baseUrl, version, response, solution)
256
+ super(baseUrl, version, response)
257
+
258
+ # Path Solution
259
+ @solution = solution
260
+ end
261
+
262
+ ##
263
+ # Build an instance of AuthenticationItemInstance
264
+ # @param [Hash] payload Payload response from the API
265
+ # @return [AuthenticationItemInstance] AuthenticationItemInstance
266
+ def get_instance(payload)
267
+ AuthenticationItemInstance.new(@version, payload, configuration_id: @solution[:configuration_id])
268
+ end
269
+
270
+ ##
271
+ # Provide a user friendly representation
272
+ def to_s
273
+ '<Reach.Api.Authentix.AuthenticationItemPage>'
274
+ end
275
+ end
276
+ class AuthenticationItemInstance < InstanceResource
277
+ ##
278
+ # Initialize the AuthenticationItemInstance
279
+ # @param [Version] version Version that contains the resource
280
+ # @param [Hash] payload payload that contains response from Reach(TalkyLabs)
281
+ # @param [String] account_sid The SID of the
282
+ # Account that created this AuthenticationItem
283
+ # resource.
284
+ # @param [String] sid The SID of the Call resource to fetch.
285
+ # @return [AuthenticationItemInstance] AuthenticationItemInstance
286
+ def initialize(version, payload , configuration_id: nil, authentication_id: nil)
287
+ super(version)
288
+
289
+ # Marshaled Properties
290
+ @properties = {
291
+ 'appletId' => payload['appletId'],
292
+ 'apiVersion' => payload['apiVersion'],
293
+ 'configurationId' => payload['configurationId'],
294
+ 'authenticationId' => payload['authenticationId'],
295
+ 'status' => payload['status'],
296
+ 'dest' => payload['dest'],
297
+ 'channel' => payload['channel'],
298
+ 'expiryTime' => payload['expiryTime'] == nil ? payload['expiryTime'] : payload['expiryTime'].to_i,
299
+ 'maxTrials' => payload['maxTrials'] == nil ? payload['maxTrials'] : payload['maxTrials'].to_i,
300
+ 'maxControls' => payload['maxControls'] == nil ? payload['maxControls'] : payload['maxControls'].to_i,
301
+ 'paymentInfo' => payload['paymentInfo'],
302
+ 'trials' => payload['trials'],
303
+ 'dateCreated' => Reach.deserialize_iso8601_datetime(payload['dateCreated']),
304
+ 'dateUpdated' => Reach.deserialize_iso8601_datetime(payload['dateUpdated']),
305
+ }
306
+
307
+ # Context
308
+ @instance_context = nil
309
+ @params = { 'configuration_id' => configuration_id || @properties['configurationId'] ,'authentication_id' => authentication_id || @properties['authenticationId'] , }
310
+ end
311
+
312
+ ##
313
+ # Generate an instance context for the instance, the context is capable of
314
+ # performing various actions. All instance actions are proxied to the context
315
+ # @return [AuthenticationItemContext] CallContext for this CallInstance
316
+ def context
317
+ unless @instance_context
318
+ @instance_context = AuthenticationItemContext.new(@version , @params['configuration_id'], @params['authentication_id'])
319
+ end
320
+ @instance_context
321
+ end
322
+
323
+ ##
324
+ # @return [String] The identifier of the applet.
325
+ def appletId
326
+ @properties['appletId']
327
+ end
328
+
329
+ ##
330
+ # @return [String] The API version.
331
+ def apiVersion
332
+ @properties['apiVersion']
333
+ end
334
+
335
+ ##
336
+ # @return [String] The identifier of the configuration.
337
+ def configurationId
338
+ @properties['configurationId']
339
+ end
340
+
341
+ ##
342
+ # @return [String] The identifier of the authentication.
343
+ def authenticationId
344
+ @properties['authenticationId']
345
+ end
346
+
347
+ ##
348
+ # @return [String] The status of the authentication.
349
+ def status
350
+ @properties['status']
351
+ end
352
+
353
+ ##
354
+ # @return [String] The destination of the authentication code. Phone numbers must be in E.164 format.
355
+ def dest
356
+ @properties['dest']
357
+ end
358
+
359
+ ##
360
+ # @return [String] The channel used.
361
+ def channel
362
+ @properties['channel']
363
+ end
364
+
365
+ ##
366
+ # @return [String] An expiry time in minutes.
367
+ def expiryTime
368
+ @properties['expiryTime']
369
+ end
370
+
371
+ ##
372
+ # @return [String] The maximum number of trials.
373
+ def maxTrials
374
+ @properties['maxTrials']
375
+ end
376
+
377
+ ##
378
+ # @return [String] The maximum number of code controls.
379
+ def maxControls
380
+ @properties['maxControls']
381
+ end
382
+
383
+ ##
384
+ # @return [PaymentInfo]
385
+ def paymentInfo
386
+ @properties['paymentInfo']
387
+ end
388
+
389
+ ##
390
+ # @return [Array<TrialQuickInfo>] An array of authentication trials containing channel-specific information about each trial.
391
+ def trials
392
+ @properties['trials']
393
+ end
394
+
395
+ ##
396
+ # @return [Time] The date and time in GMT that the authentication was created.
397
+ def dateCreated
398
+ @properties['dateCreated']
399
+ end
400
+
401
+ ##
402
+ # @return [Time] The date and time in GMT that the authentication was last updated.
403
+ def dateUpdated
404
+ @properties['dateUpdated']
405
+ end
406
+
407
+ ##
408
+ # Fetch the AuthenticationItemInstance
409
+ # @return [AuthenticationItemInstance] Fetched AuthenticationItemInstance
410
+ def fetch
411
+
412
+ context.fetch
413
+ end
414
+
415
+ ##
416
+ # Update the AuthenticationItemInstance
417
+ # @param [String] status The new status of the authentication.
418
+ # @return [AuthenticationItemInstance] Updated AuthenticationItemInstance
419
+ def update(
420
+ status: nil
421
+ )
422
+
423
+ context.update(
424
+ status: status,
425
+ )
426
+ end
427
+
428
+ ##
429
+ # Provide a user friendly representation
430
+ def to_s
431
+ values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
432
+ "<Reach.Api.Authentix.AuthenticationItemInstance #{values}>"
433
+ end
434
+
435
+ ##
436
+ # Provide a detailed, user friendly representation
437
+ def inspect
438
+ values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
439
+ "<Reach.Api.Authentix.AuthenticationItemInstance #{values}>"
440
+ end
441
+ end
442
+
443
+ end
444
+ end
445
+ end
446
+ end
447
+ end
448
+
449
+