uni-sdk 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d98dcd92ba7b6133a759719b91c85310bef8aa82cdbe1f24f5aa23434f9b43a0
4
- data.tar.gz: 5bbc4980ac4a9b81be41607ac010d513e491e129a5800f474a0b34593617398e
3
+ metadata.gz: 3cb626b3043c1497ec5732f0d0d86507c269a0ec30cad9cbacf48beb6cb531b0
4
+ data.tar.gz: 0cf681f5fb70e49bac70024ed0d1f9a25738387ddac907f36cb9abcb0f8dd0a4
5
5
  SHA512:
6
- metadata.gz: e01c4e43e705b69a6b9f0376a3957c705801103c96a8f626ef9de3d8ebeca05a618e37781b69f2271a4b320c8acc7b717f3de56a2af3c44fcbc2a389e6861483
7
- data.tar.gz: f96bc1df810aca1e93caf8c89c82fb755a22ab5bdcb5a353ec330857e72af02aa8fc3d280e5f5607b49c97078155880b6702372adcf99c461bf680a11e742b9d
6
+ metadata.gz: 71390fa7276f0a95ebdd5db4334371401b3a2127b53168e65aced5e27ed07c5f04d61221fc87b7e0f5e2308ba5b8462bb7ee803f695a6f40b02f6da1209a053e
7
+ data.tar.gz: fa7cbd789c467a8c8ded1c699372f884e4535c93a782005951a5ece86d4160274dea9debd2cd721a148d2469c02c64d7bec5a9d8980285592928531acc539f9a
data/README.md CHANGED
@@ -32,6 +32,21 @@ gem 'uni-sdk'
32
32
 
33
33
  The following example shows how to use the Unimatrix Ruby SDK to interact with Unimatrix services.
34
34
 
35
+ ### Initialize a client
36
+
37
+ ```ruby
38
+ require 'uni-sdk'
39
+
40
+ client = Uni::Client.new('your access key id', 'your access key secret')
41
+ ```
42
+
43
+ or you can configure your credentials by environment variables:
44
+
45
+ ```sh
46
+ export UNIMTX_ACCESS_KEY_ID=your_access_key_id
47
+ export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secret
48
+ ```
49
+
35
50
  ### Send SMS
36
51
 
37
52
  Send a text message to a single recipient.
@@ -44,15 +59,44 @@ client = Uni::Client.new('your access key id', 'your access key secret')
44
59
 
45
60
  begin
46
61
  resp = client.messages.send({
47
- to: 'your phone number', # in E.164 format
48
- signature: 'your sender name',
49
- content: 'Your verification code is 2048.'
62
+ to: '+1206880xxxx', # in E.164 format
63
+ text: 'Your verification code is 2048.'
50
64
  })
51
65
  puts resp.data
52
66
  rescue Uni::UniError => e
53
67
  puts 'Exception: ' + e.message
54
68
  end
69
+ ```
70
+
71
+ ### Send verification code
72
+
73
+ Send a one-time passcode (OTP) to a recipient. The following example will automatically generate a verification code.
74
+
75
+ ```ruby
76
+ require 'uni-sdk'
77
+
78
+ client = Uni::Client.new()
79
+
80
+ resp = client.otp.send({
81
+ to: '+1206880xxxx'
82
+ })
83
+ puts resp.data
84
+ ```
85
+
86
+ ### Check verification code
87
+
88
+ Verify the one-time passcode (OTP) that a user provided. The following example will check whether the user-provided verification code is correct.
89
+
90
+ ```ruby
91
+ require 'uni-sdk'
92
+
93
+ client = Uni::Client.new()
55
94
 
95
+ resp = client.otp.verify({
96
+ to: '+1206880xxxx',
97
+ code: '123456' # the code user provided
98
+ })
99
+ puts resp.valid
56
100
  ```
57
101
 
58
102
  ## Reference
data/examples/otp.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'uni-sdk'
2
+
3
+ client = Uni::Client.new('your access key id', 'your access key secret')
4
+
5
+ # send a verification code to a recipient
6
+ begin
7
+ resp = client.otp.send({
8
+ to: 'your phone number' # in E.164 format
9
+ })
10
+ puts resp.data
11
+ rescue Uni::UniError => e
12
+ puts 'Exception: ' + e.message
13
+ end
14
+
15
+ # verify a verification code
16
+ begin
17
+ resp = client.otp.verify({
18
+ to: 'your phone number', # in E.164 format
19
+ code: 'the code you received'
20
+ })
21
+ puts resp.valid
22
+ rescue Uni::UniError => e
23
+ puts 'Exception: ' + e.message
24
+ end
data/examples/send.rb CHANGED
@@ -5,8 +5,7 @@ client = Uni::Client.new('your access key id', 'your access key secret')
5
5
  begin
6
6
  resp = client.messages.send({
7
7
  to: 'your phone number', # in E.164 format
8
- signature: 'your sender name',
9
- content: 'Your verification code is 2048.'
8
+ text: 'Your verification code is 2048.'
10
9
  })
11
10
  puts resp.data
12
11
  rescue Uni::UniError => e
@@ -9,9 +9,9 @@ module Uni
9
9
  attr_accessor :access_key_id, :access_key_secret, :endpoint, :signing_algorithm
10
10
 
11
11
  def initialize(access_key_id=nil, access_key_secret=nil, endpoint=nil, signing_algorithm=nil)
12
- @access_key_id = access_key_id
13
- @access_key_secret = access_key_secret
14
- @endpoint = endpoint || @@default_endpoint
12
+ @access_key_id = access_key_id || ENV['UNIMTX_ACCESS_KEY_ID']
13
+ @access_key_secret = access_key_secret || ENV['UNIMTX_ACCESS_KEY_SECRET']
14
+ @endpoint = endpoint || ENV['UNIMTX_ENDPOINT'] || @@default_endpoint
15
15
  @signing_algorithm = signing_algorithm || @@default_signing_algorithm
16
16
  @user_agent = @@name + '/' + Uni::VERSION
17
17
  end
@@ -58,5 +58,9 @@ module Uni
58
58
  def messages()
59
59
  Uni::Modal::Message.new(self)
60
60
  end
61
+
62
+ def otp()
63
+ Uni::Modal::Otp.new(self)
64
+ end
61
65
  end
62
66
  end
@@ -0,0 +1,19 @@
1
+ module Uni
2
+ module Modal
3
+ class Otp
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def send(data={})
9
+ @client.request('otp.send', data)
10
+ end
11
+
12
+ def verify(data={})
13
+ resp = @client.request('otp.verify', data)
14
+ resp.valid = resp.data.nil? ? false : resp.data['valid']
15
+ resp
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/uni-sdk/modal.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'modal/message'
2
+ require_relative 'modal/otp'
2
3
 
3
4
  module Uni
4
5
  module Model
@@ -3,6 +3,7 @@ module Uni
3
3
  @@request_id_header_key = 'x-uni-request-id'
4
4
 
5
5
  attr_reader :raw, :status, :request_id, :code, :message, :data
6
+ attr_accessor :valid
6
7
 
7
8
  def initialize(response)
8
9
  @raw = response
@@ -13,6 +14,7 @@ module Uni
13
14
  @code = @body['code']
14
15
  @message = @body['message']
15
16
  @data = @body['data']
17
+ @valid = false
16
18
 
17
19
  if @status < 200 || @status >= 300 || @code != '0'
18
20
  raise UniError.new(@message || response.reason_phrase, self)
@@ -1,3 +1,3 @@
1
1
  module Uni
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uni-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unimatrix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-22 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -45,12 +45,14 @@ files:
45
45
  - LICENSE
46
46
  - README.md
47
47
  - Rakefile
48
+ - examples/otp.rb
48
49
  - examples/send.rb
49
50
  - lib/uni-sdk.rb
50
51
  - lib/uni-sdk/client.rb
51
52
  - lib/uni-sdk/error.rb
52
53
  - lib/uni-sdk/modal.rb
53
54
  - lib/uni-sdk/modal/message.rb
55
+ - lib/uni-sdk/modal/otp.rb
54
56
  - lib/uni-sdk/response.rb
55
57
  - lib/uni-sdk/version.rb
56
58
  - uni-sdk.gemspec