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 +4 -4
- data/README.md +47 -3
- data/examples/otp.rb +24 -0
- data/examples/send.rb +1 -2
- data/lib/uni-sdk/client.rb +7 -3
- data/lib/uni-sdk/modal/otp.rb +19 -0
- data/lib/uni-sdk/modal.rb +1 -0
- data/lib/uni-sdk/response.rb +2 -0
- data/lib/uni-sdk/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb626b3043c1497ec5732f0d0d86507c269a0ec30cad9cbacf48beb6cb531b0
|
4
|
+
data.tar.gz: 0cf681f5fb70e49bac70024ed0d1f9a25738387ddac907f36cb9abcb0f8dd0a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: '
|
48
|
-
|
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
|
-
|
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
|
data/lib/uni-sdk/client.rb
CHANGED
@@ -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
data/lib/uni-sdk/response.rb
CHANGED
@@ -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)
|
data/lib/uni-sdk/version.rb
CHANGED
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.
|
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:
|
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
|