Class: Rapleaf::Base
- Inherits:
-
Object
- Object
- Rapleaf::Base
- Defined in:
- lib/rapleaf/rapleaf.rb
Instance Method Summary collapse
-
#initialize(api_key, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#person(opts = {}) ⇒ Object
This resource is used to retrieve information about a person, identified using an email address or email address hash.
Constructor Details
#initialize(api_key, options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rapleaf/rapleaf.rb', line 8 def initialize(api_key, = {}) = { :api_host => API_HOST, :api_port => API_PORT, :api_version => API_VERSION, :api_read_timeout => 30, }.merge() @api_key = api_key @host = [:api_host] @port = [:api_port] @version = [:api_version] @read_timeout = [:api_read_timeout] end |
Instance Method Details
#person(opts = {}) ⇒ Object
This resource is used to retrieve information about a person, identified using an email address or email address hash. Examples:
person(:email => '[email protected]')
person(:site => :twitter, :profile => 'samstokes')
person(:sha1 => Digest::SHA1.hexdigest('[email protected]'))
person(:md5 => Digest::MD5.hexdigest('[email protected]'))
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rapleaf/rapleaf.rb', line 30 def person( opts = {} ) resp = fetch_response(URI.parse(person_url(opts))) case resp.code when '200' return Response.parse(:xml => resp.body) when '202' raise PersonAccepted, 'This person is currently being searched. Check back shortly and we should have data.' when '400' raise PersonBadRequestInvalidEmail, 'Invalid email address.' when '401' raise AuthFailure, 'API key was not provided or is invalid.' when '403' raise ForbiddenQueryLimitExceeded, 'Your query limit has been exceeded. Contact [email protected] if you would like to increase your limit.' when '404' raise PersonEmailHashNotFound, 'We do not have this email in our system and are not able to create a person using a hash. If you would like better results, consider supplying the unhashed email address.' when '500' raise InternalServerError, 'There was an unexpected error on our server. This should be very rare and if you see it please contact [email protected].' else msg = resp.body[0,50] msg << "..." if 50 < resp.body.length raise Error, %(Unexpected response code #{resp.code}: "#{msg}") end end |