test_nextcaller_client 0.0.1
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 +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +9 -0
- data/lib/test_nextcaller_client/client.rb +88 -0
- data/lib/test_nextcaller_client/constants.rb +16 -0
- data/lib/test_nextcaller_client/exceptions.rb +6 -0
- data/lib/test_nextcaller_client/transport.rb +46 -0
- data/lib/test_nextcaller_client/utils.rb +68 -0
- data/lib/test_nextcaller_client/version.rb +3 -0
- data/lib/test_nextcaller_client.rb +14 -0
- data/nextcaller_client.gemspec +28 -0
- data/test/test_base.rb +14 -0
- data/test/test_by_phone.rb +136 -0
- data/test/test_by_profile.rb +130 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDk2OWVhMGYzZmQ2YzBhNzI4MzdlMmFjZTRmZDZmODU1NDc2ZWNlOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDRlNjQ3Y2EzOGM5MzA0MTY4NmU5YjgwNzUyMzY5YmZiZTQyZGUyYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NWIzMzM4YjdlZTUyYmI2OTVhMjY5NzU1YzhkZTAyZWFkNjFmNjI3MTE2ZTJm
|
10
|
+
ZDQ2M2QzNGZhYWM4OGMzNDA0YjlhM2ZkNWNjZTZkZWI4ZmJkMGM4NjEzMjY5
|
11
|
+
OGM3NWU4NzRiODhjZGEzM2MyODU0NjU3ZWUwZjU1NjgxM2I1NzA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzRhOTZiMTZkZjQ4ZmFiYTIyNTdkZTNjNGRkZDI3NDc0YjY5ZDkxMzhmYTJk
|
14
|
+
NTg0NmI5NmMxZWMyN2UwZDAwZTFkMTNhNGEwZDQyYzM1YTI0YTE1ZDQ2ZGM3
|
15
|
+
ODk4MzFjMzkxZWUxNWZjYTIxZWU4ZjQ3ZTU0M2VhNmE4NzhhMzQ=
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Next Caller Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# NextcallerClient
|
2
|
+
|
3
|
+
A ruby wrapper around the Nextcaller API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
ruby gem 'test_nextcaller_client'
|
10
|
+
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install test_nextcaller_client
|
19
|
+
|
20
|
+
**Dependencies**:
|
21
|
+
|
22
|
+
* nokogiri
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
**Example**
|
27
|
+
|
28
|
+
require 'test_nextcaller_client'
|
29
|
+
api_key = "XXXXX"
|
30
|
+
api_secret = "YYYYY"
|
31
|
+
phone_number = "121212..."
|
32
|
+
client = NextcallerClient::Client.new(api_key, api_secret)
|
33
|
+
resp = client.get_by_phone(phone_number)
|
34
|
+
print resp
|
35
|
+
|
36
|
+
**Initializing client**
|
37
|
+
|
38
|
+
require 'test_nextcaller_client'
|
39
|
+
api_key = "XXXXX"
|
40
|
+
api_secret = "YYYYY"
|
41
|
+
client = NextcallerClient::Client.new(api_key, api_secret)
|
42
|
+
|
43
|
+
**Get profile by phone**
|
44
|
+
|
45
|
+
resp = client.get_by_phone(phone, response_format, debug)
|
46
|
+
|
47
|
+
# arguments:
|
48
|
+
# phone -- 10 digits phone, str ot int, required
|
49
|
+
# response_format -- response format [json|xml] (default json)
|
50
|
+
# debug -- boolean (default false)
|
51
|
+
|
52
|
+
**Get profile by id**
|
53
|
+
|
54
|
+
resp = client.get_by_profile_id(profile_id, response_format, debug)
|
55
|
+
|
56
|
+
# arguments:
|
57
|
+
# profile_id -- Profile identifier, required
|
58
|
+
# response_format -- response format [json|xml] (default json)
|
59
|
+
# debug -- boolean (default false)
|
60
|
+
|
61
|
+
**Update profile by id**
|
62
|
+
|
63
|
+
resp = client.update_by_profile_id(profile_id, data, debug)
|
64
|
+
|
65
|
+
# arguments:
|
66
|
+
# profile_id -- Profile identifier, required
|
67
|
+
# data -- dictionary with changed data, required
|
68
|
+
# debug -- boolean (default false)
|
69
|
+
|
70
|
+
# Returns 204 response in the case of the succesfull request.
|
71
|
+
|
72
|
+
##Notes
|
73
|
+
|
74
|
+
It is possible to override the default response handler
|
75
|
+
by passing a block to get_by_phone/get_by_profile_id/update_by_profile_id function.
|
76
|
+
For example:
|
77
|
+
|
78
|
+
result = client.get_by_phone(number, 'json') { |resp| {body: JSON.parse(resp.body), code: resp.code} }
|
79
|
+
|
80
|
+
Default handler for get_by_* methods:
|
81
|
+
|
82
|
+
def self.default_handle_response(resp, response_format='json')
|
83
|
+
return JSON.parse(resp.body) if response_format == 'json'
|
84
|
+
return Nokogiri::XML(resp.body) if response_format == 'xml'
|
85
|
+
resp
|
86
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module NextcallerClient
|
2
|
+
#The NextCaller API client
|
3
|
+
class Client
|
4
|
+
|
5
|
+
attr_accessor :auth
|
6
|
+
|
7
|
+
def initialize(api_key, api_secret)
|
8
|
+
@auth = {username: api_key, password: api_secret}
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
# Get profiles by phone
|
13
|
+
# arguments:
|
14
|
+
# phone -- 10 digits phone, str ot int, required
|
15
|
+
# response_format -- response format [json|xml] (default json)
|
16
|
+
# debug -- boolean (default false)
|
17
|
+
#
|
18
|
+
def get_by_phone(phone, response_format=JSON_RESPONSE_FORMAT, debug=false)
|
19
|
+
|
20
|
+
method = 'GET'
|
21
|
+
NextcallerClient.validate_format(response_format)
|
22
|
+
NextcallerClient.validate_phone(phone)
|
23
|
+
url_params = {
|
24
|
+
phone: phone,
|
25
|
+
format: response_format
|
26
|
+
}
|
27
|
+
url = NextcallerClient.prepare_url('records', url_params)
|
28
|
+
response = NextcallerClient.make_http_request(@auth, url, method, debug)
|
29
|
+
|
30
|
+
if block_given?
|
31
|
+
yield response
|
32
|
+
else
|
33
|
+
NextcallerClient.default_handle_response(response, response_format)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Get profile by id
|
39
|
+
# arguments:
|
40
|
+
# profile_id -- Profile identifier, required
|
41
|
+
# response_format -- response format [json|xml] (default json)
|
42
|
+
# debug -- boolean (default false)
|
43
|
+
#
|
44
|
+
def get_by_profile_id(profile_id, response_format=JSON_RESPONSE_FORMAT, debug=false)
|
45
|
+
|
46
|
+
method = 'GET'
|
47
|
+
NextcallerClient.validate_format(response_format)
|
48
|
+
url_params = {
|
49
|
+
format: response_format
|
50
|
+
}
|
51
|
+
url = NextcallerClient.prepare_url('users/%s/' % profile_id, url_params)
|
52
|
+
response = NextcallerClient.make_http_request(@auth, url, method, debug)
|
53
|
+
|
54
|
+
if block_given?
|
55
|
+
yield response
|
56
|
+
else
|
57
|
+
NextcallerClient.default_handle_response(response, response_format)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Update profile by id
|
63
|
+
# arguments:
|
64
|
+
# profile_id -- Profile identifier, required
|
65
|
+
# data -- dictionary with changed data, required
|
66
|
+
# debug -- boolean (default false)
|
67
|
+
#
|
68
|
+
def update_by_profile_id(profile_id, data, debug=false)
|
69
|
+
|
70
|
+
method = 'POST'
|
71
|
+
url_params = {
|
72
|
+
format: JSON_RESPONSE_FORMAT
|
73
|
+
}
|
74
|
+
url = NextcallerClient.prepare_url('users/%s/' % profile_id, url_params)
|
75
|
+
data = NextcallerClient.prepare_json_data(data)
|
76
|
+
response = NextcallerClient.make_http_request(@auth, url, method, debug, data)
|
77
|
+
|
78
|
+
if block_given?
|
79
|
+
yield response
|
80
|
+
else
|
81
|
+
response
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module NextcallerClient
|
2
|
+
# default values
|
3
|
+
DEFAULT_REQUEST_TIMEOUT = 60
|
4
|
+
JSON_RESPONSE_FORMAT = 'json'
|
5
|
+
XML_RESPONSE_FORMAT = 'xml'
|
6
|
+
RESPONSE_FORMATS = [JSON_RESPONSE_FORMAT, XML_RESPONSE_FORMAT]
|
7
|
+
DEFAULT_PHONE_LENGTH = 10
|
8
|
+
DEFAULT_USER_AGENT = 'nextcaller/ruby/0.0.1'
|
9
|
+
JSON_CONTENT_TYPE = 'application/json; charset=utf-8'
|
10
|
+
DEFAULT_REDIRECT_ATTEMPTS = 10
|
11
|
+
|
12
|
+
# urls
|
13
|
+
BASE_URL = 'api.nextcaller.com/v2/'
|
14
|
+
FULL_URL = 'https://api.nextcaller.com/v2/'
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module NextcallerClient
|
2
|
+
|
3
|
+
log = Logger.new(STDOUT)
|
4
|
+
log.level = Logger::DEBUG
|
5
|
+
|
6
|
+
def self.make_http_request(auth, url, method='GET', debug=false, data={}, user_agent=DEFAULT_USER_AGENT,
|
7
|
+
redirect_attempts_left = DEFAULT_REDIRECT_ATTEMPTS)
|
8
|
+
raise TooManyRedirects if redirect_attempts_left < 0
|
9
|
+
uri = URI.parse(url)
|
10
|
+
case method
|
11
|
+
when 'GET'
|
12
|
+
request = Net::HTTP::Get.new(uri.path)
|
13
|
+
when 'POST'
|
14
|
+
request = Net::HTTP::Post.new(uri.path)
|
15
|
+
request['Content-Type'] = 'application/json'
|
16
|
+
request.body = data.to_json
|
17
|
+
end
|
18
|
+
request.basic_auth auth[:username], auth[:password]
|
19
|
+
request['Connection'] = 'Keep-Alive'
|
20
|
+
request['User-Agent'] = user_agent if user_agent
|
21
|
+
|
22
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
23
|
+
http.read_timeout = DEFAULT_REQUEST_TIMEOUT
|
24
|
+
http.use_ssl = true
|
25
|
+
response = http.start { |http| http.request(request) }
|
26
|
+
|
27
|
+
log.debug('Request url: %s' % url) if debug
|
28
|
+
log.debug('Request body: %s' % data.to_s) if debug and method == 'POST'
|
29
|
+
case response
|
30
|
+
when Net::HTTPSuccess then
|
31
|
+
response
|
32
|
+
when Net::HTTPRedirection then
|
33
|
+
location = response['location']
|
34
|
+
log.debug("redirected to: #{location}") if debug
|
35
|
+
make_http_request(auth, location, data, method, user_agent, debug, redirect_attempts_left - 1)
|
36
|
+
# else
|
37
|
+
# if 400 <= response.code < 500
|
38
|
+
# raise HttpException '%s Client Error: %s' % [response.code, self.reason]
|
39
|
+
# elsif 500 <= response.code < 600
|
40
|
+
# raise HttpException '%s Server Error: %s' % [response.code, self.reason]
|
41
|
+
# end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module NextcallerClient
|
2
|
+
|
3
|
+
def self.prepare_json_data(data)
|
4
|
+
begin
|
5
|
+
return data.to_json
|
6
|
+
rescue ArgumentError, TypeError
|
7
|
+
return data
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.to_json(data)
|
12
|
+
begin
|
13
|
+
return JSON.parse(data)
|
14
|
+
rescue ArgumentError, TypeError
|
15
|
+
return data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default_handle_response(resp, response_format='json')
|
20
|
+
return JSON.parse(resp.body) if response_format == 'json'
|
21
|
+
return Nokogiri::XML(resp.body) if response_format == 'xml'
|
22
|
+
resp
|
23
|
+
end
|
24
|
+
|
25
|
+
#Validate phone format
|
26
|
+
def self.validate_phone(value, length=DEFAULT_PHONE_LENGTH)
|
27
|
+
unless value
|
28
|
+
raise ArgumentError, 'Invalid phone number: %s. Phone cannot be blank.' % value
|
29
|
+
end
|
30
|
+
if value.is_a? Integer
|
31
|
+
value = value.to_s
|
32
|
+
end
|
33
|
+
unless value.is_a? String
|
34
|
+
raise ArgumentError, 'Invalid phone number: %s. Phone cannot be type of %s.' % [value, value.class]
|
35
|
+
end
|
36
|
+
unless value.length == length
|
37
|
+
raise ArgumentError, 'Invalid phone number: %s. Phone should has length %s.' % [value, length]
|
38
|
+
end
|
39
|
+
unless value =~ /^[0-9]+$/
|
40
|
+
raise ArgumentError, 'Invalid phone number: %s. Phone should consists of only digits.' % value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#Validate response format
|
45
|
+
def self.validate_format(response_format)
|
46
|
+
unless RESPONSE_FORMATS.include? response_format
|
47
|
+
raise ArgumentError, 'Unsupported format: %s. Supported formats are: %s' % [response_format, RESPONSE_FORMATS]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#Prepare url from path and params
|
52
|
+
def self.prepare_url(path, url_params={})
|
53
|
+
url = '%s%s' % [FULL_URL, path]
|
54
|
+
unless url.end_with?('/')
|
55
|
+
url += '/'
|
56
|
+
end
|
57
|
+
unless url_params.empty?
|
58
|
+
url_params_str = CGI::escape(url_params.collect { |k, v| "#{k}=#{v}" }.join('&'))
|
59
|
+
url += '?' + url_params_str
|
60
|
+
end
|
61
|
+
url
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.prepare_url_for_test(auth, path)
|
65
|
+
return Regexp.new 'https://%s:%s@%s%s*' %[auth[:username], auth[:password], BASE_URL, path]
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
require 'net/http'
|
7
|
+
require 'nokogiri'
|
8
|
+
|
9
|
+
require "test_nextcaller_client/version"
|
10
|
+
require "test_nextcaller_client/constants"
|
11
|
+
require "test_nextcaller_client/exceptions"
|
12
|
+
require "test_nextcaller_client/utils"
|
13
|
+
require "test_nextcaller_client/transport"
|
14
|
+
require "test_nextcaller_client/client"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'test_nextcaller_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "test_nextcaller_client"
|
8
|
+
s.version = NextcallerClient::VERSION
|
9
|
+
s.authors = ["Dmitry Vlasov"]
|
10
|
+
s.email = ["d.vlasov.work@gmail.com"]
|
11
|
+
s.summary = 'A Ruby wrapper around the Nextcaller API.'
|
12
|
+
s.description = 'A Ruby wrapper around the Nextcaller API. See ttps://dev.nextcaller.com/documentation/ for details.'
|
13
|
+
s.homepage = 'http://rubygems.org/gems/test_nextcaller_client'
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files -z`.split("\x0")
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
s.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
s.add_runtime_dependency 'nokogiri'
|
25
|
+
s.add_runtime_dependency 'webmock'
|
26
|
+
|
27
|
+
s.required_ruby_version = '>= 1.8.6'
|
28
|
+
end
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_nextcaller_client'
|
2
|
+
require 'webmock/test_unit'
|
3
|
+
|
4
|
+
class BaseTestCase < Test::Unit::TestCase
|
5
|
+
|
6
|
+
MiniTest::Unit::TestCase
|
7
|
+
def initialize(name)
|
8
|
+
@client = NextcallerClient::Client.new('username', 'password')
|
9
|
+
super(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require_relative './test_base'
|
2
|
+
|
3
|
+
PHONE_JSON_RESULT_EXAMPLE = '
|
4
|
+
{
|
5
|
+
"records": [
|
6
|
+
{
|
7
|
+
"id": "97d949a413f4ea8b85e9586e1f2d9a",
|
8
|
+
"first_name": "Jerry",
|
9
|
+
"last_name": "Seinfeld",
|
10
|
+
"name": "Jerry Seinfeld",
|
11
|
+
"language": "English",
|
12
|
+
"fraud_threat": "low",
|
13
|
+
"spoof": "false",
|
14
|
+
"phone": [
|
15
|
+
{
|
16
|
+
"number": "2125558383"
|
17
|
+
}
|
18
|
+
],
|
19
|
+
"carrier": "Verizon Wireless",
|
20
|
+
"line_type": "LAN",
|
21
|
+
"address": [
|
22
|
+
{
|
23
|
+
"city": "New York",
|
24
|
+
"extended_zip": "",
|
25
|
+
"country": "USA",
|
26
|
+
"line2": "Apt 5a",
|
27
|
+
"line1": "129 West 81st Street",
|
28
|
+
"state": "NY",
|
29
|
+
"zip_code": "10024"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"email": "demo@nextcaller.com",
|
33
|
+
"age": "45-54",
|
34
|
+
"gender": "Male",
|
35
|
+
"household_income": "50k-75k",
|
36
|
+
"marital_status": "Single",
|
37
|
+
"presence_of_children": "No",
|
38
|
+
"home_owner_status": "Rent",
|
39
|
+
"market_value": "350k-500k",
|
40
|
+
"length_of_residence": "12 Years",
|
41
|
+
"high_net_worth": "No",
|
42
|
+
"occupation": "Entertainer",
|
43
|
+
"education": "Completed College",
|
44
|
+
"department": "not specified"
|
45
|
+
}
|
46
|
+
]
|
47
|
+
}'
|
48
|
+
|
49
|
+
PHONE_XML_RESULT_EXAMPLE = '
|
50
|
+
<response>
|
51
|
+
<records>
|
52
|
+
<object>
|
53
|
+
<id>97d949a413f4ea8b85e9586e1f2d9a</id>
|
54
|
+
<first_name>Jerry</first_name>
|
55
|
+
<last_name>Seinfeld</last_name>
|
56
|
+
<name>Jerry Seinfeld</name>
|
57
|
+
<language>English</language>
|
58
|
+
<fraud_threat>low</fraud_threat>
|
59
|
+
<spoof>false</spoof>
|
60
|
+
<phone>
|
61
|
+
<object>
|
62
|
+
<number>2125558383</number>
|
63
|
+
</object>
|
64
|
+
</phone>
|
65
|
+
<carrier>Verizon Wireless</carrier>
|
66
|
+
<line_type>LAN</line_type>
|
67
|
+
<address>
|
68
|
+
<object>
|
69
|
+
<line1>129 West 81st Street</line1>
|
70
|
+
<line2>Apt 5a</line2>
|
71
|
+
<city>New York</city>
|
72
|
+
<state>NY</state>
|
73
|
+
<zip_code>10024</zip_code>
|
74
|
+
<extended_zip/>
|
75
|
+
<country>USA</country>
|
76
|
+
</object>
|
77
|
+
</address>
|
78
|
+
<email>demo@nextcaller.com</email>
|
79
|
+
<age>45-54</age>
|
80
|
+
<gender>Male</gender>
|
81
|
+
<household_income>50k-75k</household_income>
|
82
|
+
<marital_status>Single</marital_status>
|
83
|
+
<presence_of_children>No</presence_of_children>
|
84
|
+
<home_owner_status>Rent</home_owner_status>
|
85
|
+
<market_value>350k-500k</market_value>
|
86
|
+
<length_of_residence>12 Years</length_of_residence>
|
87
|
+
<high_net_worth>No</high_net_worth>
|
88
|
+
<occupation>Entertainer</occupation>
|
89
|
+
<education>Completed College</education>
|
90
|
+
<department>not specified</department>
|
91
|
+
</object>
|
92
|
+
</records>
|
93
|
+
</response>'
|
94
|
+
|
95
|
+
|
96
|
+
class PhoneTestCase < BaseTestCase
|
97
|
+
|
98
|
+
def test_by_short_phone
|
99
|
+
phone = '212555838'
|
100
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
101
|
+
assert_raises(ArgumentError) { @client.get_by_phone(phone)}
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_by_wrong_phone
|
105
|
+
phone = 'XXXXXXXXXX'
|
106
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
107
|
+
assert_raises(ArgumentError) { @client.get_by_phone(phone)}
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_by_wrong_response_format
|
111
|
+
phone = 2125558383
|
112
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
113
|
+
assert_raises(ArgumentError) { @client.get_by_phone(phone, 'test')}
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_by_phone_json_request
|
117
|
+
phone = '2125558383'
|
118
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
119
|
+
res = @client.get_by_phone(phone)
|
120
|
+
assert_not_nil(res['records'])
|
121
|
+
assert_equal(res['records'][0]['email'], 'demo@nextcaller.com')
|
122
|
+
assert_equal(res['records'][0]['first_name'], 'Jerry')
|
123
|
+
assert_equal(res['records'][0]['last_name'], 'Seinfeld')
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_by_phone_xml_request
|
127
|
+
phone = '2125558383'
|
128
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'records')).to_return(:body => PHONE_XML_RESULT_EXAMPLE, :status => 200)
|
129
|
+
res = @client.get_by_phone(phone, 'xml')
|
130
|
+
record = res.xpath('/response/records')[0].xpath('object')
|
131
|
+
assert_not_nil(record)
|
132
|
+
assert_equal(record.xpath('email').children[0].text, 'demo@nextcaller.com')
|
133
|
+
assert_equal(record.xpath('first_name').children[0].text, 'Jerry')
|
134
|
+
assert_equal(record.xpath('last_name').children[0].text, 'Seinfeld')
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require_relative './test_base'
|
2
|
+
|
3
|
+
PROFILE_JSON_REQUEST_EXAMPLE = {
|
4
|
+
first_name: 'Clark',
|
5
|
+
last_name: 'Kent',
|
6
|
+
shipping_address1: {
|
7
|
+
line1: '225 Kryptonite Ave.',
|
8
|
+
line2: '',
|
9
|
+
city: 'Smallville',
|
10
|
+
state: 'KS',
|
11
|
+
zip_code: '66002'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
PROFILE_JSON_RESULT_EXAMPLE = '
|
16
|
+
{
|
17
|
+
"id": "97d949a413f4ea8b85e9586e1f2d9a",
|
18
|
+
"first_name": "Jerry",
|
19
|
+
"last_name": "Seinfeld",
|
20
|
+
"name": "Jerry Seinfeld",
|
21
|
+
"language": "English",
|
22
|
+
"fraud_threat": "low",
|
23
|
+
"spoof": "false",
|
24
|
+
"phone": [
|
25
|
+
{
|
26
|
+
"number": "2125558383"
|
27
|
+
}
|
28
|
+
],
|
29
|
+
"carrier": "Verizon Wireless",
|
30
|
+
"line_type": "LAN",
|
31
|
+
"address": [
|
32
|
+
{
|
33
|
+
"city": "New York",
|
34
|
+
"extended_zip": "",
|
35
|
+
"country": "USA",
|
36
|
+
"line2": "Apt 5a",
|
37
|
+
"line1": "129 West 81st Street",
|
38
|
+
"state": "NY",
|
39
|
+
"zip_code": "10024"
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"email": "demo@nextcaller.com",
|
43
|
+
"age": "45-54",
|
44
|
+
"gender": "Male",
|
45
|
+
"household_income": "50k-75k",
|
46
|
+
"marital_status": "Single",
|
47
|
+
"presence_of_children": "No",
|
48
|
+
"home_owner_status": "Rent",
|
49
|
+
"market_value": "350k-500k",
|
50
|
+
"length_of_residence": "12 Years",
|
51
|
+
"high_net_worth": "No",
|
52
|
+
"occupation": "Entertainer",
|
53
|
+
"education": "Completed College",
|
54
|
+
"department": "not specified"
|
55
|
+
}'
|
56
|
+
|
57
|
+
PROFILE_XML_RESULT_EXAMPLE = '
|
58
|
+
<object>
|
59
|
+
<id>97d949a413f4ea8b85e9586e1f2d9a</id>
|
60
|
+
<first_name>Jerry</first_name>
|
61
|
+
<last_name>Seinfeld</last_name>
|
62
|
+
<name>Jerry Seinfeld</name>
|
63
|
+
<language>English</language>
|
64
|
+
<fraud_threat>low</fraud_threat>
|
65
|
+
<spoof>false</spoof>
|
66
|
+
<phone>
|
67
|
+
<object>
|
68
|
+
<number>2125558383</number>
|
69
|
+
</object>
|
70
|
+
</phone>
|
71
|
+
<carrier>Verizon Wireless</carrier>
|
72
|
+
<line_type>LAN</line_type>
|
73
|
+
<address>
|
74
|
+
<object>
|
75
|
+
<line1>129 West 81st Street</line1>
|
76
|
+
<line2>Apt 5a</line2>
|
77
|
+
<city>New York</city>
|
78
|
+
<state>NY</state>
|
79
|
+
<zip_code>10024</zip_code>
|
80
|
+
<extended_zip/>
|
81
|
+
<country>USA</country>
|
82
|
+
</object>
|
83
|
+
</address>
|
84
|
+
<email>demo@nextcaller.com</email>
|
85
|
+
<age>45-54</age>
|
86
|
+
<gender>Male</gender>
|
87
|
+
<household_income>50k-75k</household_income>
|
88
|
+
<marital_status>Single</marital_status>
|
89
|
+
<presence_of_children>No</presence_of_children>
|
90
|
+
<home_owner_status>Rent</home_owner_status>
|
91
|
+
<market_value>350k-500k</market_value>
|
92
|
+
<length_of_residence>12 Years</length_of_residence>
|
93
|
+
<high_net_worth>No</high_net_worth>
|
94
|
+
<occupation>Entertainer</occupation>
|
95
|
+
<education>Completed College</education>
|
96
|
+
<department>not specified</department>
|
97
|
+
</object>'
|
98
|
+
|
99
|
+
|
100
|
+
class ProfileTestCase <BaseTestCase
|
101
|
+
|
102
|
+
def initialize(name)
|
103
|
+
@profile_id = '97d949a413f4ea8b85e9586e1f2d9a'
|
104
|
+
super(name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_profile_get_json_request
|
108
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'users/')).to_return(:body => PROFILE_JSON_RESULT_EXAMPLE, :status => 200)
|
109
|
+
res = @client.get_by_profile_id(@profile_id)
|
110
|
+
assert_equal(res['email'], 'demo@nextcaller.com')
|
111
|
+
assert_equal(res['first_name'], 'Jerry')
|
112
|
+
assert_equal(res['last_name'], 'Seinfeld')
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_profile_get_xml_request
|
116
|
+
stub_request(:get, NextcallerClient.prepare_url_for_test(@client.auth, 'users/')).to_return(:body => PROFILE_XML_RESULT_EXAMPLE, :status => 200)
|
117
|
+
res = @client.get_by_profile_id(@profile_id, 'xml')
|
118
|
+
record = res.xpath('/object')
|
119
|
+
assert_not_nil(record)
|
120
|
+
assert_equal(record.xpath('email')[0].children[0].text, 'demo@nextcaller.com')
|
121
|
+
assert_equal(record.xpath('first_name').children[0].text, 'Jerry')
|
122
|
+
assert_equal(record.xpath('last_name').children[0].text, 'Seinfeld')
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_profile_update_json_request
|
126
|
+
stub_request(:post, NextcallerClient.prepare_url_for_test(@client.auth, 'users/')).to_return(:status => 204)
|
127
|
+
res = @client.update_by_profile_id(@profile_id, PROFILE_JSON_REQUEST_EXAMPLE)
|
128
|
+
assert_equal(res.code, '204')
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_nextcaller_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Vlasov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Ruby wrapper around the Nextcaller API. See ttps://dev.nextcaller.com/documentation/
|
70
|
+
for details.
|
71
|
+
email:
|
72
|
+
- d.vlasov.work@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/test_nextcaller_client.rb
|
82
|
+
- lib/test_nextcaller_client/client.rb
|
83
|
+
- lib/test_nextcaller_client/constants.rb
|
84
|
+
- lib/test_nextcaller_client/exceptions.rb
|
85
|
+
- lib/test_nextcaller_client/transport.rb
|
86
|
+
- lib/test_nextcaller_client/utils.rb
|
87
|
+
- lib/test_nextcaller_client/version.rb
|
88
|
+
- nextcaller_client.gemspec
|
89
|
+
- test/test_base.rb
|
90
|
+
- test/test_by_phone.rb
|
91
|
+
- test/test_by_profile.rb
|
92
|
+
homepage: http://rubygems.org/gems/test_nextcaller_client
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.8.6
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: A Ruby wrapper around the Nextcaller API.
|
116
|
+
test_files:
|
117
|
+
- test/test_base.rb
|
118
|
+
- test/test_by_phone.rb
|
119
|
+
- test/test_by_profile.rb
|