nexmo-saddle-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +9 -0
- data/README.md +5 -0
- data/lib/nexmo-client.rb +54 -0
- data/lib/nexmo-client/endpoints/verify.rb +19 -0
- data/lib/nexmo-client/exceptions.rb +34 -0
- data/lib/nexmo-client/middleware/exception_raiser.rb +53 -0
- data/lib/nexmo-client/version.rb +5 -0
- data/nexmo-client.gemspec +26 -0
- data/spec/integration/verify_spec.rb +37 -0
- data/spec/spec_helper.rb +15 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d05ecb184f084c53bddcff6f9e784d70fc6a9dc
|
4
|
+
data.tar.gz: d9abbd1eb4a85de7a768aa79f325ab256b16e672
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26e9c5be45709837503bfd863267fe0765ef13be8ebac50d50c246a34514b7c27a10b741ed2ee7f4c42958fc62911d5892b32ea5a41a2679555de139c22965d1
|
7
|
+
data.tar.gz: e0c883e85d485e31280c91a8ef0a4a3bc98eb933045c3b5e302ed1f6958c1f139d6d5ead2f42a6757972b9056fccf1b7f541277b43c0659d0db53da5a009f7d8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/lib/nexmo-client.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'saddle'
|
4
|
+
|
5
|
+
require 'nexmo-client/middleware/exception_raiser'
|
6
|
+
require 'nexmo-client/version'
|
7
|
+
|
8
|
+
|
9
|
+
module NEXMO
|
10
|
+
|
11
|
+
class Client < Saddle::Client
|
12
|
+
#extend NEXMO::Stub
|
13
|
+
|
14
|
+
def initialize args
|
15
|
+
args.each do |k,v|
|
16
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.host
|
21
|
+
@host || 'api.nexmo.com'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.path_prefix
|
25
|
+
@path_prefix || nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.use_ssl
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.num_retries
|
33
|
+
@num_retries || 2
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.timeout
|
37
|
+
# seconds
|
38
|
+
@timeout || 5
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.request_style
|
42
|
+
@request_style || :json
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.port
|
46
|
+
@port || 443
|
47
|
+
end
|
48
|
+
|
49
|
+
add_middleware({
|
50
|
+
:klass => Middleware::ExceptionRaiser,
|
51
|
+
})
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'saddle/endpoint'
|
4
|
+
module NEXMO
|
5
|
+
module Endpoints
|
6
|
+
|
7
|
+
class Verify < Saddle::TraversalEndpoint
|
8
|
+
|
9
|
+
def verify_request(number, brand, params = {}, opts = {})
|
10
|
+
get("json", params.merge({:number => number, :brand => brand}), opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_request(request_id, code, params = {}, opts = {})
|
14
|
+
get("check/json", params.merge({:request_id => request_id, :code => code}), opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# Exceptions for using the Nexmo client
|
5
|
+
# It is recommended that you handle these.
|
6
|
+
##
|
7
|
+
|
8
|
+
module NEXMO
|
9
|
+
|
10
|
+
class GenericException < StandardError; end
|
11
|
+
|
12
|
+
class TimeoutError < GenericException; end
|
13
|
+
|
14
|
+
# Some problems might take care of themselves if you try again later. Others won't.
|
15
|
+
class TemporaryError < GenericException; end # fire warnings on these
|
16
|
+
class PermanentError < GenericException; end # fire errors on these
|
17
|
+
|
18
|
+
## Error codes are based upon:
|
19
|
+
## https://docs.nexmo.com/index.php/verify/search#verify_return_code
|
20
|
+
|
21
|
+
# 1
|
22
|
+
class SystemBusy < TemporaryError; end
|
23
|
+
# 2 - 4, 15 - 18
|
24
|
+
class BadRequest < PermanentError; end
|
25
|
+
# 5 - 7
|
26
|
+
class SystemError < TemporaryError; end
|
27
|
+
# 8
|
28
|
+
class AccessDenied < PermanentError; end
|
29
|
+
# 9
|
30
|
+
class InsufficientAppPermission < AccessDenied; end
|
31
|
+
# 101
|
32
|
+
class NotFound < PermanentError; end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'nexmo-client/exceptions'
|
5
|
+
|
6
|
+
|
7
|
+
module NEXMO
|
8
|
+
module Middleware
|
9
|
+
|
10
|
+
## Raise beautiful exceptions
|
11
|
+
#
|
12
|
+
class ExceptionRaiser < Faraday::Middleware
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
begin
|
16
|
+
response = @app.call(env)
|
17
|
+
verify_return_code = response.body.try(:[], 'status').to_i
|
18
|
+
|
19
|
+
if verify_return_code != 0
|
20
|
+
# Error codes are based upon:
|
21
|
+
# https://docs.nexmo.com/index.php/verify/search#verify_return_code
|
22
|
+
|
23
|
+
# Translate our error code into an exception
|
24
|
+
exception =
|
25
|
+
case verify_return_code
|
26
|
+
when 1
|
27
|
+
NEXMO::SystemBusy
|
28
|
+
when 2..4, 15..18
|
29
|
+
NEXMO::BadRequest
|
30
|
+
when 5..7
|
31
|
+
NEXMO::SystemError
|
32
|
+
when 8
|
33
|
+
NEXMO::AccessDenied
|
34
|
+
when 9
|
35
|
+
NEXMO::InsufficientAppPermission
|
36
|
+
when 101
|
37
|
+
NEXMO::NotFound
|
38
|
+
else
|
39
|
+
NEXMO::GenericException
|
40
|
+
end
|
41
|
+
|
42
|
+
raise exception, response.body.try(:[], 'error_text')
|
43
|
+
end
|
44
|
+
response
|
45
|
+
rescue Saddle::TimeoutError => e
|
46
|
+
raise NEXMO::TimeoutError, e.response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nexmo-client/version', __FILE__)
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'nexmo-saddle-client'
|
9
|
+
s.version = ::NEXMO::VERSION
|
10
|
+
s.authors = ['Henry Cai']
|
11
|
+
s.email = ['minghangcai@gmail.com']
|
12
|
+
s.description = %q{Nexmo api ruby client}
|
13
|
+
s.summary = %q{
|
14
|
+
This is a NEXMO api client implemented on Saddle
|
15
|
+
}
|
16
|
+
s.homepage = 'https://github.com/hcai/nexmo-client.git'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.require_path = 'lib'
|
20
|
+
s.files = `git ls-files`.split($\)
|
21
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
22
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
23
|
+
|
24
|
+
s.add_dependency 'saddle', '~> 0.0.49'
|
25
|
+
s.add_dependency 'simple_oauth', '~> 0.2.0'
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
###
|
6
|
+
# NOTE: This spec will actually hit Nexmo's servers
|
7
|
+
###
|
8
|
+
|
9
|
+
describe 'NEXMO::Endpoints::Verify' do
|
10
|
+
context "Test integration of verify endpoint" do
|
11
|
+
|
12
|
+
# Skip if the creds aren't setup
|
13
|
+
if defined?(API_KEY) && defined?(API_SECRET)
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@client = NEXMO::Client.create()
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sends verify request successfully' do
|
20
|
+
response = @client.verify.verify_request("16503530279", "Thinplify", {:api_key => API_KEY, :api_secret => API_SECRET})
|
21
|
+
response.should be_a(Hash)
|
22
|
+
response['request_id'].should_not be_nil
|
23
|
+
response['status'].should eq('0')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should verify successfully' do
|
27
|
+
response = @client.verify.check_request("8bd16ef5d9664bc0bd86592157145efe", "0874", {:api_key => API_KEY, :api_secret => API_SECRET})
|
28
|
+
response.should be_a(Hash)
|
29
|
+
response['status'].should eq('0')
|
30
|
+
end
|
31
|
+
|
32
|
+
else
|
33
|
+
puts "You should put valid creds in _creds.rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'nexmo-client'
|
4
|
+
|
5
|
+
# Load credentials from ENV if possible, or load from _creds.rb
|
6
|
+
if ENV['API_KEY'] && ENV['API_SECRET']
|
7
|
+
API_KEY = ENV['API_KEY']
|
8
|
+
API_SECRET = ENV['API_SECRET']
|
9
|
+
else
|
10
|
+
begin
|
11
|
+
require '_creds'
|
12
|
+
rescue LoadError
|
13
|
+
puts "Using _creds.stub.rb, create a _creds.rb with actual credentials for a live test."
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nexmo-saddle-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henry Cai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: saddle
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.49
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.49
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simple_oauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
description: Nexmo api ruby client
|
42
|
+
email:
|
43
|
+
- minghangcai@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- lib/nexmo-client.rb
|
52
|
+
- lib/nexmo-client/endpoints/verify.rb
|
53
|
+
- lib/nexmo-client/exceptions.rb
|
54
|
+
- lib/nexmo-client/middleware/exception_raiser.rb
|
55
|
+
- lib/nexmo-client/version.rb
|
56
|
+
- nexmo-client.gemspec
|
57
|
+
- spec/integration/verify_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: https://github.com/hcai/nexmo-client.git
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: This is a NEXMO api client implemented on Saddle
|
83
|
+
test_files:
|
84
|
+
- spec/integration/verify_spec.rb
|
85
|
+
- spec/spec_helper.rb
|