nexmo 4.0.0 → 4.1.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 +45 -19
- data/lib/nexmo.rb +52 -42
- data/lib/nexmo/version.rb +1 -1
- data/nexmo.gemspec +3 -3
- data/spec/nexmo_spec.rb +32 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 706d683032b1928b5139d95e402e77497b0da9b2
|
4
|
+
data.tar.gz: f41681589bcc0a827b08fd521f80dbf2a52ee15c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec1f6d2a5d131f4174407276992e54b00ddc99c87081d277a67c798cc8b4e2ac737c1c5b248deee1d697357409d241a469a9ca9c6fbf8a7b2695ea94f6bca6ad
|
7
|
+
data.tar.gz: d057d84301e06e758b389724d3526cba8c34986118c40fbc4e14ea302bf15bf00542947941298f9361c1e205f146803a469ce59c6653fabf00ee32938a2919ef
|
data/README.md
CHANGED
@@ -1,21 +1,53 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Nexmo Client Library for Ruby
|
2
|
+
=============================
|
3
3
|
|
4
|
+
[Installation](#installation) | [Usage](#usage) | [Examples](#examples) | [License](#license)
|
4
5
|
|
5
|
-
Ruby client for
|
6
|
+
This is the Ruby client library for Nexmo's API. To use it you'll
|
7
|
+
need a Nexmo account. Sign up [for free at nexmo.com][signup].
|
6
8
|
|
7
9
|
|
8
10
|
Installation
|
9
11
|
------------
|
10
12
|
|
13
|
+
To install the Ruby client library using Rubygems:
|
14
|
+
|
11
15
|
$ gem install nexmo
|
12
16
|
|
17
|
+
Alternatively you can clone the repo or download the source.
|
18
|
+
|
19
|
+
|
20
|
+
Usage
|
21
|
+
-----
|
22
|
+
|
23
|
+
Specify your credentials using the `NEXMO_API_KEY` and `NEXMO_API_SECRET`
|
24
|
+
environment variables; require the nexmo library; and construct a client object.
|
25
|
+
For example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'nexmo'
|
29
|
+
|
30
|
+
nexmo = Nexmo::Client.new
|
31
|
+
```
|
32
|
+
|
33
|
+
Alternatively you can specify your credentials directly using the `key`
|
34
|
+
and `secret` options:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'nexmo'
|
38
|
+
|
39
|
+
nexmo = Nexmo::Client.new(key: 'YOUR-API-KEY', secret: 'YOUR-API-SECRET')
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
Examples
|
44
|
+
--------
|
45
|
+
|
46
|
+
### Sending A Message
|
13
47
|
|
14
|
-
|
15
|
-
-----------------
|
48
|
+
Use [Nexmo's SMS API][doc_sms] to send an SMS message.
|
16
49
|
|
17
|
-
|
18
|
-
the #send_message method. For example:
|
50
|
+
Call the send_message method with a hash containing the message parameters. For example:
|
19
51
|
|
20
52
|
```ruby
|
21
53
|
require 'nexmo'
|
@@ -31,18 +63,12 @@ else
|
|
31
63
|
end
|
32
64
|
```
|
33
65
|
|
34
|
-
The Nexmo documentation contains a [list of response codes](https://docs.nexmo.com/api-ref/sms-api/response/status-codes)
|
35
|
-
which may be useful for debugging errors. Remember that phone numbers
|
36
|
-
should be specified in international format, and other country specific
|
37
|
-
restrictions may apply (e.g. US messages must originate from either a
|
38
|
-
pre-approved long number or short code).
|
39
66
|
|
67
|
+
License
|
68
|
+
-------
|
40
69
|
|
41
|
-
|
42
|
-
--------------------------------
|
70
|
+
This library is released under the [MIT License][license]
|
43
71
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
NEXMO_API_KEY and NEXMO_API_SECRET environment variables if the key/secret
|
48
|
-
options were not specified explicitly.
|
72
|
+
[signup]: http://nexmo.com?src=ruby-client-library
|
73
|
+
[doc_sms]: https://docs.nexmo.com/messaging/sms-api
|
74
|
+
[license]: LICENSE.txt
|
data/lib/nexmo.rb
CHANGED
@@ -21,144 +21,154 @@ module Nexmo
|
|
21
21
|
@secret = options.fetch(:secret) { ENV.fetch('NEXMO_API_SECRET') }
|
22
22
|
|
23
23
|
@host = options.fetch(:host) { 'rest.nexmo.com' }
|
24
|
+
|
25
|
+
@api_host = options.fetch(:api_host) { 'api.nexmo.com' }
|
24
26
|
end
|
25
27
|
|
26
28
|
def send_message(params)
|
27
|
-
post(
|
29
|
+
post("https://#@host/sms/json", params)
|
28
30
|
end
|
29
31
|
|
30
32
|
def get_balance
|
31
|
-
get(
|
33
|
+
get("https://#@host/account/get-balance")
|
32
34
|
end
|
33
35
|
|
34
36
|
def get_country_pricing(country_code)
|
35
|
-
get(
|
37
|
+
get("https://#@host/account/get-pricing/outbound", country: country_code)
|
36
38
|
end
|
37
39
|
|
38
40
|
def get_prefix_pricing(prefix)
|
39
|
-
get(
|
41
|
+
get("https://#@host/account/get-prefix-pricing/outbound", prefix: prefix)
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_settings(params)
|
45
|
+
post("https://#@host/account/settings", params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def topup(params)
|
49
|
+
post("https://#@host/account/top-up", params)
|
40
50
|
end
|
41
51
|
|
42
52
|
def get_account_numbers(params)
|
43
|
-
get(
|
53
|
+
get("https://#@host/account/numbers", params)
|
44
54
|
end
|
45
55
|
|
46
56
|
def get_available_numbers(country_code, params = {})
|
47
|
-
get(
|
57
|
+
get("https://#@host/number/search", {country: country_code}.merge(params))
|
48
58
|
end
|
49
59
|
|
50
60
|
def buy_number(params)
|
51
|
-
post(
|
61
|
+
post("https://#@host/number/buy", params)
|
52
62
|
end
|
53
63
|
|
54
64
|
def cancel_number(params)
|
55
|
-
post(
|
65
|
+
post("https://#@host/number/cancel", params)
|
56
66
|
end
|
57
67
|
|
58
68
|
def update_number(params)
|
59
|
-
post(
|
69
|
+
post("https://#@host/number/update", params)
|
60
70
|
end
|
61
71
|
|
62
72
|
def get_message(id)
|
63
|
-
get(
|
73
|
+
get("https://#@host/search/message", id: id)
|
64
74
|
end
|
65
75
|
|
66
76
|
def get_message_rejections(params)
|
67
|
-
get(
|
77
|
+
get("https://#@host/search/rejections", params)
|
68
78
|
end
|
69
79
|
|
70
80
|
def search_messages(params)
|
71
|
-
get(
|
81
|
+
get("https://#@host/search/messages", Hash === params ? params : {ids: Array(params)})
|
72
82
|
end
|
73
83
|
|
74
84
|
def send_ussd_push_message(params)
|
75
|
-
post(
|
85
|
+
post("https://#@host/ussd/json", params)
|
76
86
|
end
|
77
87
|
|
78
88
|
def send_ussd_prompt_message(params)
|
79
|
-
post(
|
89
|
+
post("https://#@host/ussd-prompt/json", params)
|
80
90
|
end
|
81
91
|
|
82
92
|
def send_2fa_message(params)
|
83
|
-
post(
|
93
|
+
post("https://#@host/sc/us/2fa/json", params)
|
84
94
|
end
|
85
95
|
|
86
96
|
def send_event_alert_message(params)
|
87
|
-
post(
|
97
|
+
post("https://#@host/sc/us/alert/json", params)
|
88
98
|
end
|
89
99
|
|
90
100
|
def send_marketing_message(params)
|
91
|
-
post(
|
101
|
+
post("https://#@host/sc/us/marketing/json", params)
|
92
102
|
end
|
93
103
|
|
94
104
|
def initiate_call(params)
|
95
|
-
post(
|
105
|
+
post("https://#@host/call/json", params)
|
96
106
|
end
|
97
107
|
|
98
108
|
def initiate_tts_call(params)
|
99
|
-
post(
|
109
|
+
post("https://#@api_host/tts/json", params)
|
100
110
|
end
|
101
111
|
|
102
112
|
def initiate_tts_prompt_call(params)
|
103
|
-
post(
|
113
|
+
post("https://#@api_host/tts-prompt/json", params)
|
104
114
|
end
|
105
115
|
|
106
116
|
def send_verification_request(params)
|
107
|
-
post(
|
117
|
+
post("https://#@api_host/verify/json", params)
|
108
118
|
end
|
109
119
|
|
110
120
|
def check_verification_request(params)
|
111
|
-
post(
|
121
|
+
post("https://#@api_host/verify/check/json", params)
|
112
122
|
end
|
113
123
|
|
114
124
|
def get_verification_request(id)
|
115
|
-
get(
|
125
|
+
get("https://#@api_host/verify/search/json", request_id: id)
|
116
126
|
end
|
117
127
|
|
118
128
|
def control_verification_request(params)
|
119
|
-
post(
|
129
|
+
post("https://#@api_host/verify/control/json", params)
|
120
130
|
end
|
121
131
|
|
122
132
|
def get_basic_number_insight(params)
|
123
|
-
get(
|
133
|
+
get("https://#@api_host/number/format/json", params)
|
124
134
|
end
|
125
135
|
|
126
136
|
def get_number_insight(params)
|
127
|
-
get(
|
137
|
+
get("https://#@api_host/number/lookup/json", params)
|
128
138
|
end
|
129
139
|
|
130
140
|
def request_number_insight(params)
|
131
|
-
post(
|
141
|
+
post("https://#@host/ni/json", params)
|
132
142
|
end
|
133
143
|
|
134
144
|
private
|
135
145
|
|
136
146
|
USER_AGENT = "ruby-nexmo/#{VERSION}/#{RUBY_VERSION}"
|
137
147
|
|
138
|
-
def get(
|
139
|
-
uri = URI
|
148
|
+
def get(uri, params = {})
|
149
|
+
uri = URI(uri)
|
140
150
|
uri.query = query_string(params.merge(api_key: @key, api_secret: @secret))
|
141
151
|
|
142
|
-
|
143
|
-
|
152
|
+
message = Net::HTTP::Get.new(uri.request_uri)
|
153
|
+
message['User-Agent'] = USER_AGENT
|
144
154
|
|
145
|
-
|
146
|
-
http.use_ssl = true
|
147
|
-
|
148
|
-
parse http.request(get_request), uri.host
|
155
|
+
parse(request(uri, message), uri.host)
|
149
156
|
end
|
150
157
|
|
151
|
-
def post(
|
152
|
-
uri = URI
|
158
|
+
def post(uri, params)
|
159
|
+
uri = URI(uri)
|
153
160
|
|
154
|
-
|
155
|
-
|
156
|
-
|
161
|
+
message = Net::HTTP::Post.new(uri.request_uri)
|
162
|
+
message.form_data = params.merge(api_key: @key, api_secret: @secret)
|
163
|
+
message['User-Agent'] = USER_AGENT
|
157
164
|
|
165
|
+
parse(request(uri, message), uri.host)
|
166
|
+
end
|
167
|
+
|
168
|
+
def request(uri, message)
|
158
169
|
http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port)
|
159
170
|
http.use_ssl = true
|
160
|
-
|
161
|
-
parse http.request(post_request), uri.host
|
171
|
+
http.request(message)
|
162
172
|
end
|
163
173
|
|
164
174
|
def parse(http_response, host)
|
data/lib/nexmo/version.rb
CHANGED
data/nexmo.gemspec
CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ['Tim Craft']
|
9
9
|
s.email = ['mail@timcraft.com']
|
10
|
-
s.homepage = '
|
11
|
-
s.description = '
|
12
|
-
s.summary = '
|
10
|
+
s.homepage = 'https://github.com/Nexmo/nexmo-ruby'
|
11
|
+
s.description = 'Nexmo Client Library for Ruby'
|
12
|
+
s.summary = 'This is the Ruby client library for Nexmo\'s API. To use it you\'ll need a Nexmo account. Sign up for free at https://www.nexmo.com'
|
13
13
|
s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md nexmo.gemspec)
|
14
14
|
s.required_ruby_version = '>= 1.9.3'
|
15
15
|
s.add_development_dependency('rake', '~> 10.1')
|
data/spec/nexmo_spec.rb
CHANGED
@@ -63,6 +63,26 @@ describe 'Nexmo::Client' do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
describe 'update_settings method' do
|
67
|
+
it 'updates the account settings resource with the given parameters and returns the response object' do
|
68
|
+
url = "#@base_url/account/settings"
|
69
|
+
|
70
|
+
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
71
|
+
|
72
|
+
@client.update_settings(moCallBackUrl: 'http://example.com/callback').must_equal(@json_response_object)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'topup method' do
|
77
|
+
it 'updates the account top-up resource with the given parameters and returns the response object' do
|
78
|
+
url = "#@base_url/account/top-up"
|
79
|
+
|
80
|
+
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
81
|
+
|
82
|
+
@client.topup(trx: '00X123456Y7890123Z').must_equal(@json_response_object)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
66
86
|
describe 'get_account_numbers method' do
|
67
87
|
it 'fetches the account numbers resource with the given parameters and returns the response object' do
|
68
88
|
url = "#@base_url/account/numbers?api_key=key&api_secret=secret&size=25&pattern=33"
|
@@ -328,4 +348,16 @@ describe 'Nexmo::Client' do
|
|
328
348
|
|
329
349
|
assert_requested(request)
|
330
350
|
end
|
351
|
+
|
352
|
+
it 'provides an option for specifying a different api hostname to connect to' do
|
353
|
+
url = "https://debug.example.com/number/format/json?api_key=key&api_secret=secret&number=447525856424"
|
354
|
+
|
355
|
+
request = stub_request(:get, url).to_return(@json_response_body)
|
356
|
+
|
357
|
+
@client = Nexmo::Client.new(key: 'key', secret: 'secret', api_host: 'debug.example.com')
|
358
|
+
|
359
|
+
@client.get_basic_number_insight(number: '447525856424')
|
360
|
+
|
361
|
+
assert_requested(request)
|
362
|
+
end
|
331
363
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description:
|
55
|
+
description: Nexmo Client Library for Ruby
|
56
56
|
email:
|
57
57
|
- mail@timcraft.com
|
58
58
|
executables: []
|
@@ -65,7 +65,7 @@ files:
|
|
65
65
|
- lib/nexmo/version.rb
|
66
66
|
- nexmo.gemspec
|
67
67
|
- spec/nexmo_spec.rb
|
68
|
-
homepage:
|
68
|
+
homepage: https://github.com/Nexmo/nexmo-ruby
|
69
69
|
licenses:
|
70
70
|
- MIT
|
71
71
|
metadata: {}
|
@@ -85,8 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.5.1
|
88
|
+
rubygems_version: 2.4.5.1
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
|
-
summary:
|
91
|
+
summary: This is the Ruby client library for Nexmo's API. To use it you'll need a
|
92
|
+
Nexmo account. Sign up for free at https://www.nexmo.com
|
92
93
|
test_files: []
|