messagebird-rest 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 65e692932b82b38e07641c5787691f0dddc4330e
4
- data.tar.gz: ae82199dc7751a50e772ba289fcdc712721fec88
3
+ metadata.gz: 3b53bdc58624f5473f812a02642ac6b74bb83dd4
4
+ data.tar.gz: be218bdcb5e9cdbe47fb58021cbfc0f7805ad0bf
5
5
  SHA512:
6
- metadata.gz: 0ff89ec13b1720dfef137c1e26fca6d105bd6e2538c2e0cbf647b2924791aa81716f62a377100cebc0f4385cfaf953ef224044a853eef0aaa6059ca0d72d145d
7
- data.tar.gz: 62078521b02b35ffd7a30dfd5c1f4226cc20b920d2cd006b118b1f8188ed868b756ba6ed2c78e0e084a28eb748316bffb80d7f49f26f6e98fe0ae9ba16c0d5d7
6
+ metadata.gz: 9889deb627a5ae4a4bca6d7d5d46b7b345c51f8a8e90a26432d219b36b4e885e957305fd68e1590e4d242fa8cd66e7ab5a4fb5a35aa43031d64365c25eb72280
7
+ data.tar.gz: 9b3e70e9894d055929b76762c556257af34cb98f48371663dd6f32255e9e280de37cd72cd7cefe698e3b6e8611baddb8440ecb39581de52e9ad373c9872f2b25
data/README.md CHANGED
@@ -32,7 +32,7 @@ require 'messagebird'
32
32
  client = MessageBird::Client.new(YOUR_ACCESS_KEY)
33
33
  ```
34
34
 
35
- That's easy enough. Now we can query the server for information.
35
+ That's easy enough. Now we can query the server for information.
36
36
 
37
37
  ##### Balance
38
38
  Lets start with out with an overview of our balance.
@@ -111,6 +111,30 @@ Similar to the **message_create** and **message** methods, the **hlr_create** me
111
111
  client.hlr('4933bed0453ba7455031712h16830892')
112
112
  ```
113
113
 
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.
116
+
117
+ ```ruby
118
+ # otp_generate requires a recipient as a required parameter, and other optional paramaters
119
+ client.otp_generate(31612345678, {:reference => "YourReference"})
120
+
121
+ #<MessageBird::OTP:0x007fb3c18c8148
122
+ @id="080b7f804555213678f14f6o24607735",
123
+ @recipient="31612345678",
124
+ @reference="YourReference",
125
+ @status="sent",
126
+ @href={"message"=>"https://rest.messagebird.com/messages/67d42f004555213679416f0b13254392"},
127
+ @createdDatetime=2015-05-12 16:51:19 +0200,
128
+ @validUntilDatetime=2015-05-12 16:51:49 +0200>
129
+ ```
130
+
131
+ This sends a token to the recipient, which can be verified with the **otp_verify** method.
132
+
133
+ ```ruby
134
+ # otp_verify requires a recipient, a token as required parameters, and other optional paramaters
135
+ client.otp_verify(31612345678, 123456, {:reference => "YourReference"})
136
+ ```
137
+
114
138
  ##### Voice Message
115
139
  MessageBird also offers the ability to send out a text message as a voice message, or text-to-speech. For that purpose we have created the **voice_message_create** method, which takes one or more required *recipients* and a *body* text for parameters.
116
140
 
@@ -5,6 +5,7 @@ require 'uri'
5
5
  require 'messagebird/balance'
6
6
  require 'messagebird/error'
7
7
  require 'messagebird/hlr'
8
+ require 'messagebird/otp'
8
9
  require 'messagebird/message'
9
10
  require 'messagebird/voicemessage'
10
11
 
@@ -20,8 +21,8 @@ module MessageBird
20
21
  class Client
21
22
  attr_reader :access_key
22
23
 
23
- def initialize(access_key)
24
- @access_key = access_key
24
+ def initialize(access_key = nil)
25
+ @access_key = access_key || ENV['MESSAGEBIRD_ACCESS_KEY']
25
26
  end
26
27
 
27
28
  def request(method, path, params={})
@@ -79,6 +80,29 @@ module MessageBird
79
80
  :reference => reference))
80
81
  end
81
82
 
83
+ # Generate a new One-Time-Password message
84
+ def otp_generate(recipient, params={})
85
+ OTP.new(request(
86
+ :post,
87
+ 'otp/generate',
88
+ params.merge({
89
+ :recipient => recipient
90
+ })
91
+ ))
92
+ end
93
+
94
+ # Verify the One-Time-Password
95
+ def otp_verify(recipient, token, params={})
96
+ # Set the path to include all the parameters
97
+ # Blame Sam Wierema for not adhering to REST principles...
98
+ path = 'otp/verify?' + URI.encode_www_form(params.merge({
99
+ :recipient => recipient,
100
+ :token => token
101
+ }))
102
+
103
+ OTP.new(request(:get, path))
104
+ end
105
+
82
106
  # Retrieve the information of specific message.
83
107
  def message(id)
84
108
  Message.new(request(:get, "messages/#{id.to_s}"))
@@ -0,0 +1,18 @@
1
+ require 'time'
2
+
3
+ require 'messagebird/base'
4
+
5
+ module MessageBird
6
+ class OTP < MessageBird::Base
7
+ attr_accessor :id, :recipient, :reference, :status, :href,
8
+ :createdDatetime, :validUntilDatetime
9
+
10
+ def createdDatetime=(value)
11
+ @createdDatetime = value_to_time(value)
12
+ end
13
+
14
+ def validUntilDatetime=(value)
15
+ @validUntilDatetime = value_to_time(value)
16
+ end
17
+ end
18
+ end
data/lib/messagebird.rb CHANGED
@@ -2,7 +2,7 @@ libdir = File.dirname(__FILE__)
2
2
  $:.unshift(libdir) unless $:.include?(libdir)
3
3
 
4
4
  module MessageBird
5
- CLIENT_VERSION = '1.1.0'
5
+ CLIENT_VERSION = '1.2.0'
6
6
  ENDPOINT = 'https://rest.messagebird.com'
7
7
  end
8
8
 
@@ -10,5 +10,6 @@ require 'messagebird/balance'
10
10
  require 'messagebird/client'
11
11
  require 'messagebird/error'
12
12
  require 'messagebird/hlr'
13
+ require 'messagebird/otp'
13
14
  require 'messagebird/message'
14
15
  require 'messagebird/voicemessage'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messagebird-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maurice Nonnekes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-10 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple REST API for MessageBird in Ruby
14
14
  email: maurice@messagebird.com
@@ -16,17 +16,18 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - LICENSE
20
- - README.md
21
- - lib/messagebird.rb
22
19
  - lib/messagebird/balance.rb
23
20
  - lib/messagebird/base.rb
24
21
  - lib/messagebird/client.rb
25
22
  - lib/messagebird/error.rb
26
23
  - lib/messagebird/hlr.rb
27
24
  - lib/messagebird/message.rb
25
+ - lib/messagebird/otp.rb
28
26
  - lib/messagebird/recipient.rb
29
27
  - lib/messagebird/voicemessage.rb
28
+ - lib/messagebird.rb
29
+ - LICENSE
30
+ - README.md
30
31
  homepage: https://github.com/messagebird/ruby-rest-api
31
32
  licenses:
32
33
  - BSD-2-Clause
@@ -37,17 +38,17 @@ require_paths:
37
38
  - lib
38
39
  required_ruby_version: !ruby/object:Gem::Requirement
39
40
  requirements:
40
- - - ">="
41
+ - - '>='
41
42
  - !ruby/object:Gem::Version
42
43
  version: '0'
43
44
  required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ">="
46
+ - - '>='
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  requirements: []
49
50
  rubyforge_project:
50
- rubygems_version: 2.2.2
51
+ rubygems_version: 2.0.14
51
52
  signing_key:
52
53
  specification_version: 4
53
54
  summary: MessageBird's REST API