Class: TowerDataApi::Api
- Inherits:
-
Object
- Object
- TowerDataApi::Api
- Defined in:
- lib/towerdata_api.rb
Instance Method Summary collapse
-
#bulk_query(set) ⇒ Object
Get bulk request set - is array of hashes in format.
-
#email_validation(email) ⇒ Object
For given email returns EmailValidation object This method will rise TowerDataApi::Error::Unsupported if yours api key doesn’t have email validation field.
-
#initialize(api_key = nil, options = {}) ⇒ Api
constructor
A new instance of Api.
-
#query_by_email(email, options = {}) ⇒ Object
Takes an e-mail and returns a hash which maps attribute fields onto attributes Options: :hash_email - the email will be hashed before it’s sent to Rapleaf.
-
#query_by_md5(md5_email, options = {}) ⇒ Object
Takes an e-mail that has already been hashed by md5 and returns a hash which maps attribute fields onto attributes, optionally showing available data in the response.
-
#query_by_nap(first, last, street, city, state, options = {}) ⇒ Object
Takes first name, last name, and postal (street, city, and state acronym), and returns a hash which maps attribute fields onto attributes Options: :email - query with an email to increase the hit rate.
-
#query_by_naz(first, last, zip4, options = {}) ⇒ Object
Takes first name, last name, and zip4 code (5-digit zip and 4-digit extension separated by a dash as a string), and returns a hash which maps attribute fields onto attributes Options: :email - query with an email to increase the hit rate.
-
#query_by_sha1(sha1_email, options = {}) ⇒ Object
Takes an e-mail that has already been hashed by sha1 and returns a hash which maps attribute fields onto attributes, optionally showing available data in the response.
-
#valid_email?(email) ⇒ Boolean
Check is email valid This method will rise TowerDataApi::Error::Api if yours api key doesn’t have email validation field Value can be true, false and nil.
Constructor Details
#initialize(api_key = nil, options = {}) ⇒ Api
34 35 36 37 38 39 |
# File 'lib/towerdata_api.rb', line 34 def initialize(api_key=nil, = {}) @api_key = api_key.nil? ? Configuration.api_key : api_key .each do |key, value| Configuration.send("#{key}=", value) end end |
Instance Method Details
#bulk_query(set) ⇒ Object
Get bulk request set - is array of hashes in format
[{email: 'first_email'}, {email: 'second_email'}]
128 129 130 |
# File 'lib/towerdata_api.rb', line 128 def bulk_query(set) get_bulk_response(bulk_path, JSON.generate(set)) end |
#email_validation(email) ⇒ Object
For given email returns EmailValidation object This method will rise TowerDataApi::Error::Unsupported if yours api key doesn’t have email validation field
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/towerdata_api.rb', line 100 def email_validation email begin result = query_by_email email rescue TowerDataApi::Error::BadRequest result = {'email_validation' => {'ok' => false}} end if result.has_key? 'email_validation' EmailValidation.new result['email_validation'] else raise TowerDataApi::Error::Unsupported, 'Email validation is not supported with yours api key.' end end |
#query_by_email(email, options = {}) ⇒ Object
Takes an e-mail and returns a hash which maps attribute fields onto attributes Options:
:hash_email - the email will be hashed before it's sent to Rapleaf
44 45 46 47 48 49 50 |
# File 'lib/towerdata_api.rb', line 44 def query_by_email(email, = {}) if [:hash_email] query_by_sha1(Digest::SHA1.hexdigest(email.downcase)) else get_json_response("#{base_path}&email=#{url_encode(email)}") end end |
#query_by_md5(md5_email, options = {}) ⇒ Object
Takes an e-mail that has already been hashed by md5 and returns a hash which maps attribute fields onto attributes, optionally showing available data in the response
55 56 57 |
# File 'lib/towerdata_api.rb', line 55 def query_by_md5(md5_email, = {}) get_json_response("#{base_path}&md5_email=#{url_encode(md5_email)}") end |
#query_by_nap(first, last, street, city, state, options = {}) ⇒ Object
Takes first name, last name, and postal (street, city, and state acronym), and returns a hash which maps attribute fields onto attributes Options:
:email - query with an email to increase the hit rate
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/towerdata_api.rb', line 70 def query_by_nap(first, last, street, city, state, = {}) if [:email] url = "#{base_path}&email=#{url_encode(options[:email])}&first=#{url_encode(first)}&last=#{url_encode(last)}" + "&street=#{url_encode(street)}&city=#{url_encode(city)}&state=#{url_encode(state)}" else url = "#{base_path}&first=#{url_encode(first)}&last=#{url_encode(last)}" + "&street=#{url_encode(street)}&city=#{url_encode(city)}&state=#{url_encode(state)}" end get_json_response(url) end |
#query_by_naz(first, last, zip4, options = {}) ⇒ Object
Takes first name, last name, and zip4 code (5-digit zip and 4-digit extension separated by a dash as a string), and returns a hash which maps attribute fields onto attributes Options:
:email - query with an email to increase the hit rate
86 87 88 89 90 91 92 93 |
# File 'lib/towerdata_api.rb', line 86 def query_by_naz(first, last, zip4, = {}) if [:email] url = "#{base_path}&email=#{url_encode(options[:email])}&first=#{url_encode(first)}&last=#{url_encode(last)}&zip4=#{zip4}" else url = "#{base_path}&first=#{url_encode(first)}&last=#{url_encode(last)}&zip4=#{zip4}" end get_json_response(url) end |
#query_by_sha1(sha1_email, options = {}) ⇒ Object
Takes an e-mail that has already been hashed by sha1 and returns a hash which maps attribute fields onto attributes, optionally showing available data in the response
62 63 64 |
# File 'lib/towerdata_api.rb', line 62 def query_by_sha1(sha1_email, = {}) get_json_response("#{base_path}&sha1_email=#{url_encode(sha1_email)}") end |
#valid_email?(email) ⇒ Boolean
Check is email valid This method will rise TowerDataApi::Error::Api if yours api key doesn’t have email validation field Value can be true, false and nil
118 119 120 |
# File 'lib/towerdata_api.rb', line 118 def valid_email? email email_validation(email).valid? end |