nextcaller_client 0.0.2
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 +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +88 -0
- data/Rakefile +9 -0
- data/lib/nextcaller_client/client.rb +82 -0
- data/lib/nextcaller_client/constants.rb +12 -0
- data/lib/nextcaller_client/exceptions.rb +12 -0
- data/lib/nextcaller_client/transport.rb +53 -0
- data/lib/nextcaller_client/utils.rb +43 -0
- data/lib/nextcaller_client/version.rb +3 -0
- data/lib/nextcaller_client.rb +12 -0
- data/nextcaller_client.gemspec +27 -0
- data/test/test_base.rb +21 -0
- data/test/test_by_phone.rb +73 -0
- data/test/test_by_profile.rb +77 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f2349e07434c48f600ec72ea85cc10741e58b153
|
|
4
|
+
data.tar.gz: dd6243f52aad95b9ceff988150db838eb5d29a4b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f0598de770e0c0eaceb0a4e9a574ec9f51c7310d23295567d0ff137a1129915c3ed6ea5825fc8e2068871e3579ce028fb92d82880d9be0cf157b927af10e4216
|
|
7
|
+
data.tar.gz: a8055a87666c80c0a6a4ede9419cf367996484082a6b3927c845308070cff80df250724b91735114bca02a73143aedbc1e8e8bc0c03e4042138e456b1b1dda05
|
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/pkg
|
data/.travis.yml
ADDED
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,88 @@
|
|
|
1
|
+
# NextcallerClient
|
|
2
|
+
|
|
3
|
+
A ruby wrapper around the Nextcaller API.
|
|
4
|
+
|
|
5
|
+
[](https://travis-ci.org/Nextcaller/nextcaller-ruby-api)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
gem 'nextcaller_client'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install nextcaller_client
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
**Example**
|
|
26
|
+
|
|
27
|
+
require 'nextcaller_client'
|
|
28
|
+
api_key = "XXXXX"
|
|
29
|
+
api_secret = "YYYYY"
|
|
30
|
+
phone_number = "121212..."
|
|
31
|
+
client = NextcallerClient::Client.new(api_key, api_secret)
|
|
32
|
+
resp = client.get_by_phone(phone_number)
|
|
33
|
+
print resp
|
|
34
|
+
|
|
35
|
+
**Initializing client**
|
|
36
|
+
|
|
37
|
+
require 'nextcaller_client'
|
|
38
|
+
api_key = "XXXXX"
|
|
39
|
+
api_secret = "YYYYY"
|
|
40
|
+
client = NextcallerClient::Client.new(api_key, api_secret)
|
|
41
|
+
|
|
42
|
+
**Get profile by phone**
|
|
43
|
+
|
|
44
|
+
resp = client.get_by_phone(phone, response_format, debug)
|
|
45
|
+
|
|
46
|
+
# arguments:
|
|
47
|
+
# phone -- 10 digits phone, str or int, required
|
|
48
|
+
# debug -- boolean (default false)
|
|
49
|
+
|
|
50
|
+
**Get profile by id**
|
|
51
|
+
|
|
52
|
+
resp = client.get_by_profile_id(profile_id, response_format, debug)
|
|
53
|
+
|
|
54
|
+
# arguments:
|
|
55
|
+
# profile_id -- Profile identifier, required
|
|
56
|
+
# debug -- boolean (default false)
|
|
57
|
+
|
|
58
|
+
**Update profile by id**
|
|
59
|
+
|
|
60
|
+
resp = client.update_by_profile_id(profile_id, data, debug)
|
|
61
|
+
|
|
62
|
+
# arguments:
|
|
63
|
+
# profile_id -- Profile identifier, required
|
|
64
|
+
# data -- dictionary with changed data, required
|
|
65
|
+
# debug -- boolean (default false)
|
|
66
|
+
|
|
67
|
+
# Returns 204 response in the case of the succesfull request.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
##Exceptions
|
|
71
|
+
|
|
72
|
+
**NextcallerClient::HttpException**
|
|
73
|
+
|
|
74
|
+
Thrown in the case of 4xx or 5xx response from server.
|
|
75
|
+
'content' attribute contains parsed response body.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
##Notes
|
|
79
|
+
|
|
80
|
+
It is possible to override the default response handler
|
|
81
|
+
by passing a block to get_by_phone/get_by_profile_id/update_by_profile_id function.
|
|
82
|
+
For example:
|
|
83
|
+
|
|
84
|
+
result = client.get_by_phone(number) { |resp| {body: JSON.parse(resp.body), code: resp.code} } # resp is Net::HTTPResponse object
|
|
85
|
+
|
|
86
|
+
Default handler for get_by_* methods:
|
|
87
|
+
|
|
88
|
+
JSON.parse(resp.body)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
@transport = Transport.new(auth, DEFAULT_USER_AGENT)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Get profiles by phone
|
|
13
|
+
# arguments:
|
|
14
|
+
# phone -- 10 digits phone, str ot int, required
|
|
15
|
+
# debug -- boolean (default false)
|
|
16
|
+
#
|
|
17
|
+
def get_by_phone(phone, debug=false)
|
|
18
|
+
|
|
19
|
+
method = 'GET'
|
|
20
|
+
Utils.validate_phone(phone)
|
|
21
|
+
url_params = {
|
|
22
|
+
phone: phone,
|
|
23
|
+
format: JSON_RESPONSE_FORMAT
|
|
24
|
+
}
|
|
25
|
+
url = Utils.prepare_url('records', url_params)
|
|
26
|
+
response = @transport.make_http_request(url, method, debug)
|
|
27
|
+
|
|
28
|
+
if block_given?
|
|
29
|
+
yield response
|
|
30
|
+
else
|
|
31
|
+
JSON.parse(response.body)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Get profile by id
|
|
36
|
+
# arguments:
|
|
37
|
+
# profile_id -- Profile identifier, required
|
|
38
|
+
# debug -- boolean (default false)
|
|
39
|
+
#
|
|
40
|
+
def get_by_profile_id(profile_id, debug=false)
|
|
41
|
+
|
|
42
|
+
method = 'GET'
|
|
43
|
+
url_params = {
|
|
44
|
+
format: JSON_RESPONSE_FORMAT
|
|
45
|
+
}
|
|
46
|
+
url = Utils.prepare_url('users/%s/' % profile_id, url_params)
|
|
47
|
+
response = @transport.make_http_request(url, method, debug)
|
|
48
|
+
|
|
49
|
+
if block_given?
|
|
50
|
+
yield response
|
|
51
|
+
else
|
|
52
|
+
JSON.parse(response.body)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Update profile by id
|
|
57
|
+
# arguments:
|
|
58
|
+
# profile_id -- Profile identifier, required
|
|
59
|
+
# data -- dictionary with changed data, required
|
|
60
|
+
# debug -- boolean (default false)
|
|
61
|
+
#
|
|
62
|
+
def update_by_profile_id(profile_id, data, debug=false)
|
|
63
|
+
|
|
64
|
+
method = 'POST'
|
|
65
|
+
url_params = {
|
|
66
|
+
format: JSON_RESPONSE_FORMAT
|
|
67
|
+
}
|
|
68
|
+
url = Utils.prepare_url('users/%s/' % profile_id, url_params)
|
|
69
|
+
data = Utils.prepare_json_data(data)
|
|
70
|
+
response = @transport.make_http_request(url, method, debug, data)
|
|
71
|
+
|
|
72
|
+
if block_given?
|
|
73
|
+
yield response
|
|
74
|
+
else
|
|
75
|
+
response
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module NextcallerClient
|
|
2
|
+
# default values
|
|
3
|
+
DEFAULT_REQUEST_TIMEOUT = 60
|
|
4
|
+
JSON_RESPONSE_FORMAT = 'json'
|
|
5
|
+
DEFAULT_PHONE_LENGTH = 10
|
|
6
|
+
DEFAULT_USER_AGENT = 'nextcaller/ruby/%s' % VERSION
|
|
7
|
+
|
|
8
|
+
# urls
|
|
9
|
+
BASE_URL = 'api.nextcaller.com/v2/'
|
|
10
|
+
FULL_URL = 'https://api.nextcaller.com/v2/'
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module NextcallerClient
|
|
2
|
+
|
|
3
|
+
class Transport
|
|
4
|
+
|
|
5
|
+
attr_accessor :auth, :user_agent, :log
|
|
6
|
+
|
|
7
|
+
def initialize(auth, user_agent=DEFAULT_USER_AGENT)
|
|
8
|
+
@auth = auth
|
|
9
|
+
@user_agent = user_agent
|
|
10
|
+
@log = Logger.new(STDOUT)
|
|
11
|
+
@log.level = Logger::DEBUG
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def make_http_request(url, method='GET', debug=false, data={})
|
|
15
|
+
uri = URI.parse(url)
|
|
16
|
+
case method
|
|
17
|
+
when 'GET'
|
|
18
|
+
request = Net::HTTP::Get.new('%s?%s' % [uri.path, uri.query])
|
|
19
|
+
when 'POST'
|
|
20
|
+
request = Net::HTTP::Post.new('%s?%s' % [uri.path, uri.query])
|
|
21
|
+
request['Content-Type'] = 'application/json'
|
|
22
|
+
request.body = data
|
|
23
|
+
end
|
|
24
|
+
request.basic_auth(@auth[:username], @auth[:password])
|
|
25
|
+
request['Connection'] = 'Keep-Alive'
|
|
26
|
+
request['User-Agent'] = @user_agent if @user_agent
|
|
27
|
+
|
|
28
|
+
hostname = /\A\[(.*)\]\z/ =~ uri.host ? $1 : uri.host # ruby prior to 1.9.3 does not have 'hostname', which removes brackets from ipv6 addresses
|
|
29
|
+
https = Net::HTTP.new(hostname, uri.port)
|
|
30
|
+
https.read_timeout = DEFAULT_REQUEST_TIMEOUT
|
|
31
|
+
https.use_ssl = true
|
|
32
|
+
|
|
33
|
+
# https.set_debug_output($stderr) if debug #deep debug
|
|
34
|
+
@log.debug('Request url: %s' % url) if debug
|
|
35
|
+
@log.debug('Request body: %s' % data.to_s) if debug && method == 'POST'
|
|
36
|
+
|
|
37
|
+
response = https.start { |http| http.request(request) }
|
|
38
|
+
case response
|
|
39
|
+
when Net::HTTPSuccess then
|
|
40
|
+
response
|
|
41
|
+
else
|
|
42
|
+
if response.code.to_i.between?(400, 499)
|
|
43
|
+
raise HttpException.new(Utils.parse_error_response(response)), '%s Client Error: %s' % [response.code, response.message]
|
|
44
|
+
elsif response.code.to_i.between?(500, 599)
|
|
45
|
+
raise HttpException.new(Utils.parse_error_response(response)), '%s Server Error: %s' % [response.code, response.message]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module NextcallerClient
|
|
2
|
+
|
|
3
|
+
module Utils
|
|
4
|
+
|
|
5
|
+
def self.prepare_json_data(data)
|
|
6
|
+
unless data.is_a? Hash
|
|
7
|
+
raise ArgumentError, 'Data should be a hash.'
|
|
8
|
+
end
|
|
9
|
+
data.to_json
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.parse_error_response(resp)
|
|
13
|
+
if resp['Content-Type'].include? 'application/json'
|
|
14
|
+
JSON.parse(resp.body)
|
|
15
|
+
else
|
|
16
|
+
resp.body
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#Validate phone format
|
|
21
|
+
def self.validate_phone(value, length=DEFAULT_PHONE_LENGTH)
|
|
22
|
+
value = value.to_s
|
|
23
|
+
unless value =~ /^[0-9]{10}$/
|
|
24
|
+
raise ArgumentError, 'Invalid phone number: %s. Phone should consists of 10 digits.' % value
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#Prepare url from path and params
|
|
29
|
+
def self.prepare_url(path, url_params={})
|
|
30
|
+
url = '%s%s' % [FULL_URL, path]
|
|
31
|
+
unless url.end_with?('/')
|
|
32
|
+
url += '/'
|
|
33
|
+
end
|
|
34
|
+
unless url_params.empty?
|
|
35
|
+
url_params_str = url_params.collect { |k, v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}" }.join('&')
|
|
36
|
+
url += "?#{url_params_str}"
|
|
37
|
+
end
|
|
38
|
+
url
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'cgi'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'logger'
|
|
5
|
+
require 'net/http'
|
|
6
|
+
|
|
7
|
+
require "nextcaller_client/version"
|
|
8
|
+
require "nextcaller_client/constants"
|
|
9
|
+
require "nextcaller_client/exceptions"
|
|
10
|
+
require "nextcaller_client/utils"
|
|
11
|
+
require "nextcaller_client/transport"
|
|
12
|
+
require "nextcaller_client/client"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'nextcaller_client/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = "nextcaller_client"
|
|
8
|
+
s.version = NextcallerClient::VERSION
|
|
9
|
+
s.authors = ["Zenovich Alexey"]
|
|
10
|
+
s.email = ["zenovich.alexey@itechart-group.com"]
|
|
11
|
+
s.summary = 'A Ruby wrapper around the Nextcaller API.'
|
|
12
|
+
s.description = 'A Ruby wrapper around the Nextcaller API. See https://dev.nextcaller.com/documentation/ for details.'
|
|
13
|
+
s.homepage = 'http://rubygems.org/gems/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.5"
|
|
22
|
+
s.add_development_dependency "rake", ">= 10.0"
|
|
23
|
+
s.add_development_dependency "minitest", "> 5.0.1"
|
|
24
|
+
s.add_development_dependency 'webmock', ">= 1.16"
|
|
25
|
+
|
|
26
|
+
s.required_ruby_version = '>= 1.9.2'
|
|
27
|
+
end
|
data/test/test_base.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'nextcaller_client'
|
|
2
|
+
require 'webmock/minitest'
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
TEST_USERNAME = 'username'
|
|
6
|
+
TEST_PASSWORD = 'password'
|
|
7
|
+
|
|
8
|
+
def prepare_url_for_test(path)
|
|
9
|
+
return Regexp.new 'https://%s:%s@%s%s*' %[TEST_USERNAME, TEST_PASSWORD, NextcallerClient::BASE_URL, path]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class BaseTestCase < Minitest::Test
|
|
13
|
+
|
|
14
|
+
def initialize(name)
|
|
15
|
+
@client = NextcallerClient::Client.new(TEST_USERNAME, TEST_PASSWORD)
|
|
16
|
+
super(name)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
class PhoneTestCase < BaseTestCase
|
|
50
|
+
|
|
51
|
+
def test_by_short_phone
|
|
52
|
+
phone = '212555838'
|
|
53
|
+
stub_request(:get, prepare_url_for_test('records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
|
54
|
+
assert_raises(ArgumentError) { @client.get_by_phone(phone)}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_by_wrong_phone
|
|
58
|
+
phone = 'XXXXXXXXXX'
|
|
59
|
+
stub_request(:get, prepare_url_for_test('records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
|
60
|
+
assert_raises(ArgumentError) { @client.get_by_phone(phone)}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_by_phone_json_request
|
|
64
|
+
phone = '2125558383'
|
|
65
|
+
stub_request(:get, prepare_url_for_test('records')).to_return(:body => PHONE_JSON_RESULT_EXAMPLE, :status => 200)
|
|
66
|
+
res = @client.get_by_phone(phone)
|
|
67
|
+
refute_nil(res['records'])
|
|
68
|
+
assert_equal(res['records'][0]['email'], 'demo@nextcaller.com')
|
|
69
|
+
assert_equal(res['records'][0]['first_name'], 'Jerry')
|
|
70
|
+
assert_equal(res['records'][0]['last_name'], 'Seinfeld')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
class ProfileTestCase <BaseTestCase
|
|
58
|
+
|
|
59
|
+
def initialize(name)
|
|
60
|
+
@profile_id = '97d949a413f4ea8b85e9586e1f2d9a'
|
|
61
|
+
super(name)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_profile_get_json_request
|
|
65
|
+
stub_request(:get, prepare_url_for_test('users/')).to_return(:body => PROFILE_JSON_RESULT_EXAMPLE, :status => 200)
|
|
66
|
+
res = @client.get_by_profile_id(@profile_id)
|
|
67
|
+
assert_equal(res['email'], 'demo@nextcaller.com')
|
|
68
|
+
assert_equal(res['first_name'], 'Jerry')
|
|
69
|
+
assert_equal(res['last_name'], 'Seinfeld')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_profile_update_json_request
|
|
73
|
+
stub_request(:post, prepare_url_for_test('users/')).to_return(:status => 204)
|
|
74
|
+
res = @client.update_by_profile_id(@profile_id, PROFILE_JSON_REQUEST_EXAMPLE)
|
|
75
|
+
assert_equal(res.code, '204')
|
|
76
|
+
end
|
|
77
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nextcaller_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Zenovich Alexey
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-10-17 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.5'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.5'
|
|
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: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 5.0.1
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 5.0.1
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.16'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.16'
|
|
69
|
+
description: A Ruby wrapper around the Nextcaller API. See https://dev.nextcaller.com/documentation/
|
|
70
|
+
for details.
|
|
71
|
+
email:
|
|
72
|
+
- zenovich.alexey@itechart-group.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".gitignore"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE.txt
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- lib/nextcaller_client.rb
|
|
84
|
+
- lib/nextcaller_client/client.rb
|
|
85
|
+
- lib/nextcaller_client/constants.rb
|
|
86
|
+
- lib/nextcaller_client/exceptions.rb
|
|
87
|
+
- lib/nextcaller_client/transport.rb
|
|
88
|
+
- lib/nextcaller_client/utils.rb
|
|
89
|
+
- lib/nextcaller_client/version.rb
|
|
90
|
+
- nextcaller_client.gemspec
|
|
91
|
+
- test/test_base.rb
|
|
92
|
+
- test/test_by_phone.rb
|
|
93
|
+
- test/test_by_profile.rb
|
|
94
|
+
homepage: http://rubygems.org/gems/nextcaller-client
|
|
95
|
+
licenses:
|
|
96
|
+
- MIT
|
|
97
|
+
metadata: {}
|
|
98
|
+
post_install_message:
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
require_paths:
|
|
101
|
+
- lib
|
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: 1.9.2
|
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
requirements: []
|
|
113
|
+
rubyforge_project:
|
|
114
|
+
rubygems_version: 2.2.2
|
|
115
|
+
signing_key:
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: A Ruby wrapper around the Nextcaller API.
|
|
118
|
+
test_files:
|
|
119
|
+
- test/test_base.rb
|
|
120
|
+
- test/test_by_phone.rb
|
|
121
|
+
- test/test_by_profile.rb
|