nexmo 4.8.0 → 5.0.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +48 -42
- data/lib/nexmo.rb +20 -0
- data/lib/nexmo/account.rb +23 -0
- data/lib/nexmo/alerts.rb +25 -0
- data/lib/nexmo/applications.rb +25 -0
- data/lib/nexmo/call_dtmf.rb +15 -0
- data/lib/nexmo/call_stream.rb +19 -0
- data/lib/nexmo/call_talk.rb +19 -0
- data/lib/nexmo/calls.rb +68 -0
- data/lib/nexmo/client.rb +75 -324
- data/lib/nexmo/conversions.rb +15 -0
- data/lib/nexmo/entity.rb +53 -0
- data/lib/nexmo/files.rb +25 -0
- data/lib/nexmo/jwt.rb +2 -1
- data/lib/nexmo/keys.rb +31 -0
- data/lib/nexmo/messages.rb +23 -0
- data/lib/nexmo/namespace.rb +83 -0
- data/lib/nexmo/number_insight.rb +21 -0
- data/lib/nexmo/numbers.rb +33 -0
- data/lib/nexmo/pricing.rb +31 -0
- data/lib/nexmo/pricing_types.rb +17 -0
- data/lib/nexmo/signature.rb +9 -1
- data/lib/nexmo/sms.rb +17 -0
- data/lib/nexmo/user_agent.rb +13 -0
- data/lib/nexmo/verify.rb +31 -0
- data/lib/nexmo/version.rb +1 -1
- data/nexmo.gemspec +3 -11
- metadata +39 -23
- data/spec/nexmo/client_spec.rb +0 -651
- data/spec/nexmo/jwt_spec.rb +0 -53
- data/spec/nexmo/params_spec.rb +0 -18
- data/spec/nexmo/signature_spec.rb +0 -20
data/spec/nexmo/jwt_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'nexmo'
|
3
|
-
|
4
|
-
describe 'Nexmo::JWT' do
|
5
|
-
describe 'auth_token method' do
|
6
|
-
it 'returns the payload encoded with the private key' do
|
7
|
-
time = Time.now.to_i
|
8
|
-
|
9
|
-
payload = {
|
10
|
-
'application_id' => application_id,
|
11
|
-
'iat' => time,
|
12
|
-
'exp' => time + 3600,
|
13
|
-
'jti' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
14
|
-
}
|
15
|
-
|
16
|
-
encoded_token = Nexmo::JWT.auth_token(payload, private_key)
|
17
|
-
|
18
|
-
decode(encoded_token).must_equal(payload)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'sets a default value for the iat parameter' do
|
22
|
-
encoded_token = Nexmo::JWT.auth_token({}, private_key)
|
23
|
-
|
24
|
-
decode(encoded_token).fetch('iat').must_be_kind_of(Integer)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'sets a default value for the exp parameter' do
|
28
|
-
encoded_token = Nexmo::JWT.auth_token({}, private_key)
|
29
|
-
|
30
|
-
decode(encoded_token).fetch('exp').must_be_kind_of(Integer)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'sets a default value for the jti parameter' do
|
34
|
-
encoded_token = Nexmo::JWT.auth_token({}, private_key)
|
35
|
-
|
36
|
-
decode(encoded_token).fetch('jti').must_match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def decode(encoded_token)
|
43
|
-
JWT.decode(encoded_token, private_key, verify=true, {algorithm: 'RS256'}).first
|
44
|
-
end
|
45
|
-
|
46
|
-
def application_id
|
47
|
-
@application_id ||= SecureRandom.uuid
|
48
|
-
end
|
49
|
-
|
50
|
-
def private_key
|
51
|
-
@private_key ||= OpenSSL::PKey::RSA.new(1024)
|
52
|
-
end
|
53
|
-
end
|
data/spec/nexmo/params_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'nexmo'
|
3
|
-
|
4
|
-
describe 'Nexmo::Params' do
|
5
|
-
describe 'encode method' do
|
6
|
-
it 'returns a url encoded string containing the given params' do
|
7
|
-
params = {'name' => 'Example App', 'type' => 'voice'}
|
8
|
-
|
9
|
-
Nexmo::Params.encode(params).must_equal('name=Example+App&type=voice')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'flattens array values into multiple key value pairs' do
|
13
|
-
params = {'ids' => %w[00A0B0C0 00A0B0C1 00A0B0C2]}
|
14
|
-
|
15
|
-
Nexmo::Params.encode(params).must_equal('ids=00A0B0C0&ids=00A0B0C1&ids=00A0B0C2')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'nexmo'
|
3
|
-
|
4
|
-
describe 'Nexmo::Signature' do
|
5
|
-
let(:secret) { 'secret' }
|
6
|
-
|
7
|
-
describe 'check method' do
|
8
|
-
it 'returns true if the given params has the correct sig value' do
|
9
|
-
params = {'a' => '1', 'b' => '2', 'timestamp' => '1461605396', 'sig' => '6af838ef94998832dbfc29020b564830'}
|
10
|
-
|
11
|
-
Nexmo::Signature.check(params, secret).must_equal(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns false otherwise' do
|
15
|
-
params = {'a' => '1', 'b' => '2', 'timestamp' => '1461605396', 'sig' => 'xxx'}
|
16
|
-
|
17
|
-
Nexmo::Signature.check(params, secret).must_equal(false)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|