Skip to content

Commit 8d51637

Browse files
authored
Merge pull request #11 from messagebird/migrated-otp-to-verify
Migrated OTP api to Verify api
2 parents 909b9f1 + a14bc3f commit 8d51637

6 files changed

Lines changed: 46 additions & 33 deletions

File tree

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ Similar to the **message_create** and **message** methods, the **hlr_create** me
111111
client.hlr('4933bed0453ba7455031712h16830892')
112112
```
113113

114-
##### OTP (One-Time Password)
115-
You can send and verify One-Time Passwords through the MessageBird API using the **otp_generate** and **otp_verify** methods.
114+
##### Verify (One-Time Password)
115+
You can send and verify One-Time Passwords through the MessageBird API using the **verify_create** and **verify_token** methods.
116116

117117
```ruby
118-
# otp_generate requires a recipient as a required parameter, and other optional paramaters
119-
client.otp_generate(31612345678, {:reference => "YourReference"})
118+
# verify_create requires a recipient as a required parameter, and other optional paramaters
119+
client.verify_create(31612345678, {:reference => "YourReference"})
120120

121-
#<MessageBird::OTP:0x007fb3c18c8148
121+
#<MessageBird::Verify:0x007fb3c18c8148
122122
@id="080b7f804555213678f14f6o24607735",
123123
@recipient="31612345678",
124124
@reference="YourReference",
@@ -128,11 +128,11 @@ client.otp_generate(31612345678, {:reference => "YourReference"})
128128
@validUntilDatetime=2015-05-12 16:51:49 +0200>
129129
```
130130

131-
This sends a token to the recipient, which can be verified with the **otp_verify** method.
131+
This sends a token to the recipient, which can be verified with the **verify_token** method.
132132

133133
```ruby
134-
# otp_verify requires a recipient, a token as required parameters, and other optional paramaters
135-
client.otp_verify(31612345678, 123456, {:reference => "YourReference"})
134+
# verify_token requires the id of the verify request and a token as required parameters.
135+
client.verify_token('080b7f804555213678f14f6o24607735', 123456)
136136
```
137137

138138
##### Voice Message
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
client = MessageBird::Client.new(ACCESS_KEY)
1616

1717
# Generate a new OTP message
18-
otp = client.otp_generate(31612345678, {
18+
otp = client.verify_create(31612345678, {
1919
:reference => "MessageBirdReference"
2020
})
2121

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44
require 'messagebird'
55

66
ACCESS_KEY = ''
7+
VERIFY_ID = ''
8+
TOKEN = ''
79

810
unless defined?(ACCESS_KEY)
911
puts 'You need to set an ACCESS_KEY constant in this file'
1012
exit 1
1113
end
1214

15+
unless defined?(VERIFY_ID)
16+
puts 'You need to set an VERIFY_ID constant in this file'
17+
exit 1
18+
end
19+
20+
unless defined?(TOKEN)
21+
puts 'You need to set an TOKEN constant in this file'
22+
exit 1
23+
end
24+
1325
begin
1426
# Create a MessageBird client with the specified ACCESS_KEY.
1527
client = MessageBird::Client.new(ACCESS_KEY)
1628

1729
# Verify an OTP message with a token
18-
otp = client.otp_verify(31612345678, 123456, {
19-
:reference => "MessageBirdReference"
20-
})
30+
otp = client.verify_token(VERIFY_ID, TOKEN)
2131

2232
# Print the object information.
2333
puts

lib/messagebird.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ module MessageBird
1010
require 'messagebird/client'
1111
require 'messagebird/error'
1212
require 'messagebird/hlr'
13-
require 'messagebird/otp'
13+
require 'messagebird/verify'
1414
require 'messagebird/message'
1515
require 'messagebird/voicemessage'

lib/messagebird/client.rb

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'messagebird/balance'
66
require 'messagebird/error'
77
require 'messagebird/hlr'
8-
require 'messagebird/otp'
8+
require 'messagebird/verify'
99
require 'messagebird/message'
1010
require 'messagebird/voicemessage'
1111
require 'messagebird/lookup'
@@ -83,27 +83,30 @@ def hlr_create(msisdn, reference)
8383
:reference => reference))
8484
end
8585

86-
# Generate a new One-Time-Password message
87-
def otp_generate(recipient, params={})
88-
OTP.new(request(
89-
:post,
90-
'otp/generate',
91-
params.merge({
92-
:recipient => recipient
93-
})
94-
))
86+
# Retrieve the information of specific Verify.
87+
def verify(id)
88+
Verify.new(request(:get, "verify/#{id.to_s}"))
9589
end
9690

97-
# Verify the One-Time-Password
98-
def otp_verify(recipient, token, params={})
99-
# Set the path to include all the parameters
100-
# Blame Sam Wierema for not adhering to REST principles...
101-
path = 'otp/verify?' + URI.encode_www_form(params.merge({
102-
:recipient => recipient,
103-
:token => token
104-
}))
91+
# Generate a new One-Time-Password message.
92+
def verify_create(recipient, params={})
93+
Verify.new(request(
94+
:post,
95+
'verify',
96+
params.merge({
97+
:recipient => recipient
98+
})
99+
))
100+
end
101+
102+
# Verify the One-Time-Password.
103+
def verify_token(id, token)
104+
Verify.new(request(:get, "verify/#{id.to_s}?token=#{token}"))
105+
end
105106

106-
OTP.new(request(:get, path))
107+
# Delete a Verify
108+
def verify_delete(id)
109+
Verify.new(request(:delete, "verify/#{id.to_s}"))
107110
end
108111

109112
# Retrieve the information of specific message.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'messagebird/base'
44

55
module MessageBird
6-
class OTP < MessageBird::Base
6+
class Verify < MessageBird::Base
77
attr_accessor :id, :recipient, :reference, :status, :href,
88
:createdDatetime, :validUntilDatetime
99

0 commit comments

Comments
 (0)