brite-api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +0 -0
- data/README.md +38 -0
- data/lib/brite-api/api_client.rb +28 -0
- data/lib/brite-api/client.rb +26 -0
- data/lib/brite-api/clients/address_api_client.rb +17 -0
- data/lib/brite-api/clients/email_api_client.rb +15 -0
- data/lib/brite-api/clients/ip_api_client.rb +11 -0
- data/lib/brite-api/clients/name_api_client.rb +11 -0
- data/lib/brite-api/clients/phone_api_client.rb +11 -0
- data/lib/brite-api/contact.rb +76 -0
- data/lib/brite-api/version.rb +3 -0
- data/lib/brite-api.rb +10 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca64f3e25faa0daca60ba21b6f9e5157cb5ac233
|
4
|
+
data.tar.gz: 3c7952590be9b3b447e76f205ef9fadc9ba73a20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e036a814c627332c4fd8bffb6f5b53f6408ddc133ca2569b61635e86bac5146627272fc8c5287fcbb4a607ce41b2979f1c46e1701123ca6992a0184ef17f69b0
|
7
|
+
data.tar.gz: 6ed26407e6f1cad5ad1d417ecd9dee97f2eb0de09c1cbf036212c0f2f237acfb01917753f8d403a71b512782fe1ad524f078f6c6946f217a88a93f03f8ed89dd
|
data/LICENSE
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
brite-api-ruby
|
2
|
+
==============
|
3
|
+
|
4
|
+
The official BriteVerify API Client for Ruby
|
5
|
+
|
6
|
+
# Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
client = BriteAPI::Client.new(api_key)
|
10
|
+
|
11
|
+
contact = client.contacts.create(email: 'fake@example.com', name: 'James Bond', ip: '123.213.123.123', phone: '+12345678')
|
12
|
+
|
13
|
+
# Alternative way:
|
14
|
+
# contact = BriteAPI::Contact.new(api_key, options, data)
|
15
|
+
|
16
|
+
# Set and read values in runtime
|
17
|
+
contact.name = 'Santa Claus'
|
18
|
+
contact.address = {street: '120 N Cedar', unit: 'Apt 3201', zip: '28210'}
|
19
|
+
|
20
|
+
# Send verification requests
|
21
|
+
contact.verify!
|
22
|
+
# => false
|
23
|
+
|
24
|
+
contact.valid?
|
25
|
+
# => false
|
26
|
+
|
27
|
+
contact.errors
|
28
|
+
# => {:phone=>"Invalid format", :email=>"Email address invalid"}
|
29
|
+
|
30
|
+
contact.error_codes
|
31
|
+
# => ["invalid_format", "email_address_invalid"]
|
32
|
+
|
33
|
+
contact.status
|
34
|
+
# => "unknown"
|
35
|
+
|
36
|
+
contact.response[:name]
|
37
|
+
# => {"fullname"=>"Santa Claus","prefix"=>nil, "prefix2"=>nil,...}
|
38
|
+
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rest'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module BriteAPI
|
5
|
+
class APIClient
|
6
|
+
API_HOST = 'https://bpi.briteverify.com'
|
7
|
+
|
8
|
+
def initialize(api_key, options = {})
|
9
|
+
@api_key = api_key
|
10
|
+
@options = options
|
11
|
+
@rest = Rest::Client.new(:gem => options[:gem])
|
12
|
+
end
|
13
|
+
|
14
|
+
def verify(value)
|
15
|
+
raise "Not implemented"
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(url, params = {})
|
19
|
+
|
20
|
+
options = {
|
21
|
+
:params => params.merge(:apikey => @api_key)
|
22
|
+
}
|
23
|
+
|
24
|
+
JSON.parse @rest.get(url, options).body
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module BriteAPI
|
2
|
+
|
3
|
+
class Client
|
4
|
+
def initialize(api_key, options = {})
|
5
|
+
raise ArgumentError, "Missing BriteVerify API key" if api_key.nil? || api_key == ''
|
6
|
+
@api_key = api_key
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
def contact_create(data = {})
|
13
|
+
BriteAPI::Contact.new(@api_key, @options, data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def contacts
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
alias_method :create, :contact_create
|
22
|
+
alias_method :contact, :contact_create
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BriteAPI
|
2
|
+
class AddressAPIClient < BriteAPI::APIClient
|
3
|
+
API_HATH = '/addresses.json'
|
4
|
+
|
5
|
+
|
6
|
+
def verify(value)
|
7
|
+
raise "Address should be a Hash" unless value.respond_to? :each
|
8
|
+
params = {}
|
9
|
+
value.each do |k, v|
|
10
|
+
params["address[#{k}]"] = v
|
11
|
+
end
|
12
|
+
|
13
|
+
get API_HOST + API_HATH, params
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BriteAPI
|
2
|
+
class EmailAPIClient < BriteAPI::APIClient
|
3
|
+
API_HATH = '/emails.json'
|
4
|
+
|
5
|
+
|
6
|
+
def verify(value)
|
7
|
+
params = { :address => value }
|
8
|
+
if @options[:verify_connected] || @options['verify_connected']
|
9
|
+
params[:verify_connected] = true
|
10
|
+
end
|
11
|
+
get API_HOST + API_HATH, params
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module BriteAPI
|
2
|
+
|
3
|
+
class Contact
|
4
|
+
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
FIELDS = [:email, :phone, :address, :name, :ip]
|
8
|
+
|
9
|
+
# Define accessors
|
10
|
+
FIELDS.each do |f|
|
11
|
+
define_method f do
|
12
|
+
@data[f]
|
13
|
+
end
|
14
|
+
define_method "#{f}=" do |val|
|
15
|
+
@data[f] = val
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(api_key, options = {}, data = {})
|
20
|
+
raise ArgumentError, "Missing BriteVerify API key" if api_key.nil? || api_key == ''
|
21
|
+
@api_key = api_key
|
22
|
+
@options = options
|
23
|
+
@data = {}
|
24
|
+
FIELDS.each { |key| @data[key] = data[key] || data[key.to_s] }
|
25
|
+
|
26
|
+
@response = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def verify!
|
30
|
+
@response = {}
|
31
|
+
|
32
|
+
data = @data.select{ |_, v| v != nil }
|
33
|
+
|
34
|
+
# send async requests
|
35
|
+
threads = []
|
36
|
+
data.each do |key, value|
|
37
|
+
|
38
|
+
threads << Thread.new(key, value) do |k, v|
|
39
|
+
klass = BriteAPI.const_get(k.to_s.capitalize + "APIClient")
|
40
|
+
@response[k] = klass.new(@api_key, @options).verify(v)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
threads.each { |thr| thr.join }
|
45
|
+
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid?
|
50
|
+
return if @response == {}
|
51
|
+
@response.all?{ |_, data| data['status'] == 'valid' }
|
52
|
+
end
|
53
|
+
|
54
|
+
def status
|
55
|
+
return if @response == {}
|
56
|
+
states = ['valid', 'unknown', 'invalid']
|
57
|
+
states.each_with_index do |state, index|
|
58
|
+
return state if @response.all?{ |_, data| states[0, index + 1].include? data['status'] }
|
59
|
+
end
|
60
|
+
'unknown'
|
61
|
+
end
|
62
|
+
|
63
|
+
def errors
|
64
|
+
err = {}
|
65
|
+
@response.each do |key, data|
|
66
|
+
err[key] = data['error'] if data['error']
|
67
|
+
end
|
68
|
+
err
|
69
|
+
end
|
70
|
+
|
71
|
+
def error_codes
|
72
|
+
@response.map{ |_, data| data['error_code'] }.compact.uniq
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/brite-api.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('brite-api/version', File.dirname(__FILE__))
|
3
|
+
require File.expand_path('brite-api/api_client', File.dirname(__FILE__))
|
4
|
+
require File.expand_path('brite-api/clients/address_api_client', File.dirname(__FILE__))
|
5
|
+
require File.expand_path('brite-api/clients/email_api_client', File.dirname(__FILE__))
|
6
|
+
require File.expand_path('brite-api/clients/ip_api_client', File.dirname(__FILE__))
|
7
|
+
require File.expand_path('brite-api/clients/name_api_client', File.dirname(__FILE__))
|
8
|
+
require File.expand_path('brite-api/clients/phone_api_client', File.dirname(__FILE__))
|
9
|
+
require File.expand_path('brite-api/client', File.dirname(__FILE__))
|
10
|
+
require File.expand_path('brite-api/contact', File.dirname(__FILE__))
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brite-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Shapiotko
|
8
|
+
- BriteVerify
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.2.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.2.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: shoulda
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rdoc
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.12'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.12'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>'
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>'
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: simplecov
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: minitest
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.5.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.5.0
|
98
|
+
description: Ruby client for BriteVerify API
|
99
|
+
email:
|
100
|
+
- support@briteverify.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- lib/brite-api/api_client.rb
|
106
|
+
- lib/brite-api/client.rb
|
107
|
+
- lib/brite-api/clients/address_api_client.rb
|
108
|
+
- lib/brite-api/clients/email_api_client.rb
|
109
|
+
- lib/brite-api/clients/ip_api_client.rb
|
110
|
+
- lib/brite-api/clients/name_api_client.rb
|
111
|
+
- lib/brite-api/clients/phone_api_client.rb
|
112
|
+
- lib/brite-api/contact.rb
|
113
|
+
- lib/brite-api/version.rb
|
114
|
+
- lib/brite-api.rb
|
115
|
+
- README.md
|
116
|
+
- LICENSE
|
117
|
+
homepage: https://github.com/BriteVerify/brite-api-ruby
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '1.9'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.3.6
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.0.0
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Ruby client for BriteVerify API
|
141
|
+
test_files: []
|