Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ Similar to the **message_create** and **message** methods, the **hlr_create** me
client.hlr('4933bed0453ba7455031712h16830892')
```

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

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

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

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

```ruby
# otp_verify requires a recipient, a token as required parameters, and other optional paramaters
client.otp_verify(31612345678, 123456, {:reference => "YourReference"})
# verify_token requires the id of the verify request and a token as required parameters.
client.verify_token(31612345678, 123456)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First argument must be a verify id instead the phone number I guess

```

##### Voice Message
Expand Down
2 changes: 1 addition & 1 deletion examples/otp_generate.rb → examples/verify_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
client = MessageBird::Client.new(ACCESS_KEY)

# Generate a new OTP message
otp = client.otp_generate(31612345678, {
otp = client.verify_create(31612345678, {
:reference => "MessageBirdReference"
})

Expand Down
16 changes: 13 additions & 3 deletions examples/otp_verify.rb → examples/verify_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@
require 'messagebird'

ACCESS_KEY = ''
VERIFY_ID = ''
TOKEN = ''

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

unless defined?(VERIFY_ID)
puts 'You need to set an VERIFY_ID constant in this file'
exit 1
end

unless defined?(TOKEN)
puts 'You need to set an TOKEN constant in this file'
exit 1
end

begin
# Create a MessageBird client with the specified ACCESS_KEY.
client = MessageBird::Client.new(ACCESS_KEY)

# Verify an OTP message with a token
otp = client.otp_verify(31612345678, 123456, {
:reference => "MessageBirdReference"
})
otp = client.verify_token(VERIFY_ID, TOKEN)

# Print the object information.
puts
Expand Down
2 changes: 1 addition & 1 deletion lib/messagebird.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module MessageBird
require 'messagebird/client'
require 'messagebird/error'
require 'messagebird/hlr'
require 'messagebird/otp'
require 'messagebird/verify'
require 'messagebird/message'
require 'messagebird/voicemessage'
45 changes: 26 additions & 19 deletions lib/messagebird/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'messagebird/balance'
require 'messagebird/error'
require 'messagebird/hlr'
require 'messagebird/otp'
require 'messagebird/verify'
require 'messagebird/message'
require 'messagebird/voicemessage'
require 'messagebird/lookup'
Expand Down Expand Up @@ -83,27 +83,34 @@ def hlr_create(msisdn, reference)
:reference => reference))
end

# Generate a new One-Time-Password message
def otp_generate(recipient, params={})
OTP.new(request(
:post,
'otp/generate',
params.merge({
:recipient => recipient
})
))
# Retrieve the information of specific Verify.
def verify(id)
Verify.new(request(:get, "verify/#{id.to_s}"))
end

# Verify the One-Time-Password
def otp_verify(recipient, token, params={})
# Set the path to include all the parameters
# Blame Sam Wierema for not adhering to REST principles...
path = 'otp/verify?' + URI.encode_www_form(params.merge({
:recipient => recipient,
:token => token
}))
# Generate a new One-Time-Password message.
def verify_create(recipient, params={})
Verify.new(request(
:post,
'verify',
params.merge({
:recipient => recipient
})
))
end

# Verify the One-Time-Password.
def verify_token(id, token)
Verify.new(request(
:get,
"verify/#{id.to_s}",
{:token => token}
))
end

OTP.new(request(:get, path))
# Delete a Verify
def verify_delete(id)
Verify.new(request(:delete, "verify/#{id.to_s}"))
end

# Retrieve the information of specific message.
Expand Down
2 changes: 1 addition & 1 deletion lib/messagebird/otp.rb → lib/messagebird/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'messagebird/base'

module MessageBird
class OTP < MessageBird::Base
class Verify < MessageBird::Base
attr_accessor :id, :recipient, :reference, :status, :href,
:createdDatetime, :validUntilDatetime

Expand Down