Class: Maxmind::Response
- Inherits:
-
Object
- Object
- Maxmind::Response
- Defined in:
- lib/maxmind/response.rb
Instance Attribute Summary collapse
-
#anonymous_proxy ⇒ Object
(also: #anonymous_proxy?)
Returns the value of attribute anonymous_proxy.
-
#bin_country ⇒ Object
Returns the value of attribute bin_country.
-
#bin_match ⇒ Object
(also: #bin_match?)
Returns the value of attribute bin_match.
-
#bin_name ⇒ Object
Returns the value of attribute bin_name.
-
#bin_name_match ⇒ Object
Returns the value of attribute bin_name_match.
-
#bin_phone ⇒ Object
Returns the value of attribute bin_phone.
-
#bin_phone_match ⇒ Object
Returns the value of attribute bin_phone_match.
-
#carder_email ⇒ Object
(also: #carder_email?)
Returns the value of attribute carder_email.
-
#city_postal_match ⇒ Object
(also: #city_postal_match?)
Returns the value of attribute city_postal_match.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#country_match ⇒ Object
(also: #country_match?)
Returns the value of attribute country_match.
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#error ⇒ Object
Returns the value of attribute error.
-
#explanation ⇒ Object
Returns the value of attribute explanation.
-
#free_mail ⇒ Object
(also: #free_mail?)
Returns the value of attribute free_mail.
-
#high_risk_country ⇒ Object
(also: #high_risk_country?)
Returns the value of attribute high_risk_country.
-
#high_risk_password ⇒ Object
(also: #high_risk_password?)
Returns the value of attribute high_risk_password.
-
#high_risk_username ⇒ Object
(also: #high_risk_username?)
Returns the value of attribute high_risk_username.
-
#ip_city ⇒ Object
Returns the value of attribute ip_city.
-
#ip_isp ⇒ Object
Returns the value of attribute ip_isp.
-
#ip_latitude ⇒ Object
Returns the value of attribute ip_latitude.
-
#ip_longitude ⇒ Object
Returns the value of attribute ip_longitude.
-
#ip_org ⇒ Object
Returns the value of attribute ip_org.
-
#ip_region ⇒ Object
Returns the value of attribute ip_region.
-
#is_transparent_proxy ⇒ Object
(also: #is_transparent_proxy?)
Returns the value of attribute is_transparent_proxy.
-
#maxmind_id ⇒ Object
Returns the value of attribute maxmind_id.
-
#phone_in_billing_location ⇒ Object
Returns the value of attribute phone_in_billing_location.
-
#proxy_score ⇒ Object
Returns the value of attribute proxy_score.
-
#queries_remaining ⇒ Object
Returns the value of attribute queries_remaining.
-
#response ⇒ Object
Returns the value of attribute response.
-
#risk_score ⇒ Object
Returns the value of attribute risk_score.
-
#score ⇒ Object
Returns the value of attribute score.
-
#ship_city_postal_match ⇒ Object
(also: #ship_city_postal_match?)
Returns the value of attribute ship_city_postal_match.
-
#ship_forward ⇒ Object
Returns the value of attribute ship_forward.
Instance Method Summary collapse
-
#attribute_names ⇒ Object
Returns an array of names for the attributes available on this object sorted alphabetically.
-
#attributes ⇒ Object
Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
- #attributes_from_response ⇒ Object
-
#initialize(response = nil) ⇒ Response
constructor
A new instance of Response.
- #parse(response) ⇒ Object
- #read_attribute(attr_name) ⇒ Object
Constructor Details
#initialize(response = nil) ⇒ Response
Returns a new instance of Response.
12 13 14 15 16 17 |
# File 'lib/maxmind/response.rb', line 12 def initialize(response = nil) raise ArgumentError, 'Missing response string' unless response parse(response) @attributes = attributes_from_response end |
Instance Attribute Details
#anonymous_proxy ⇒ Object Also known as: anonymous_proxy?
Returns the value of attribute anonymous_proxy.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def anonymous_proxy @anonymous_proxy end |
#bin_country ⇒ Object
Returns the value of attribute bin_country.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def bin_country @bin_country end |
#bin_match ⇒ Object Also known as: bin_match?
Returns the value of attribute bin_match.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def bin_match @bin_match end |
#bin_name ⇒ Object
Returns the value of attribute bin_name.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def bin_name @bin_name end |
#bin_name_match ⇒ Object
Returns the value of attribute bin_name_match.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def bin_name_match @bin_name_match end |
#bin_phone ⇒ Object
Returns the value of attribute bin_phone.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def bin_phone @bin_phone end |
#bin_phone_match ⇒ Object
Returns the value of attribute bin_phone_match.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def bin_phone_match @bin_phone_match end |
#carder_email ⇒ Object Also known as: carder_email?
Returns the value of attribute carder_email.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def carder_email @carder_email end |
#city_postal_match ⇒ Object Also known as: city_postal_match?
Returns the value of attribute city_postal_match.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def city_postal_match @city_postal_match end |
#country_code ⇒ Object
Returns the value of attribute country_code.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def country_code @country_code end |
#country_match ⇒ Object Also known as: country_match?
Returns the value of attribute country_match.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def country_match @country_match end |
#distance ⇒ Object
Returns the value of attribute distance.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def distance @distance end |
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def error @error end |
#explanation ⇒ Object
Returns the value of attribute explanation.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def explanation @explanation end |
#free_mail ⇒ Object Also known as: free_mail?
Returns the value of attribute free_mail.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def free_mail @free_mail end |
#high_risk_country ⇒ Object Also known as: high_risk_country?
Returns the value of attribute high_risk_country.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def high_risk_country @high_risk_country end |
#high_risk_password ⇒ Object Also known as: high_risk_password?
Returns the value of attribute high_risk_password.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def high_risk_password @high_risk_password end |
#high_risk_username ⇒ Object Also known as: high_risk_username?
Returns the value of attribute high_risk_username.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def high_risk_username @high_risk_username end |
#ip_city ⇒ Object
Returns the value of attribute ip_city.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ip_city @ip_city end |
#ip_isp ⇒ Object
Returns the value of attribute ip_isp.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ip_isp @ip_isp end |
#ip_latitude ⇒ Object
Returns the value of attribute ip_latitude.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ip_latitude @ip_latitude end |
#ip_longitude ⇒ Object
Returns the value of attribute ip_longitude.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ip_longitude @ip_longitude end |
#ip_org ⇒ Object
Returns the value of attribute ip_org.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ip_org @ip_org end |
#ip_region ⇒ Object
Returns the value of attribute ip_region.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ip_region @ip_region end |
#is_transparent_proxy ⇒ Object Also known as: is_transparent_proxy?
Returns the value of attribute is_transparent_proxy.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def is_transparent_proxy @is_transparent_proxy end |
#maxmind_id ⇒ Object
Returns the value of attribute maxmind_id.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def maxmind_id @maxmind_id end |
#phone_in_billing_location ⇒ Object
Returns the value of attribute phone_in_billing_location.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def phone_in_billing_location @phone_in_billing_location end |
#proxy_score ⇒ Object
Returns the value of attribute proxy_score.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def proxy_score @proxy_score end |
#queries_remaining ⇒ Object
Returns the value of attribute queries_remaining.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def queries_remaining @queries_remaining end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def response @response end |
#risk_score ⇒ Object
Returns the value of attribute risk_score.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def risk_score @risk_score end |
#score ⇒ Object
Returns the value of attribute score.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def score @score end |
#ship_city_postal_match ⇒ Object Also known as: ship_city_postal_match?
Returns the value of attribute ship_city_postal_match.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ship_city_postal_match @ship_city_postal_match end |
#ship_forward ⇒ Object
Returns the value of attribute ship_forward.
3 4 5 |
# File 'lib/maxmind/response.rb', line 3 def ship_forward @ship_forward end |
Instance Method Details
#attribute_names ⇒ Object
Returns an array of names for the attributes available on this object sorted alphabetically.
61 62 63 |
# File 'lib/maxmind/response.rb', line 61 def attribute_names @attributes.keys.sort end |
#attributes ⇒ Object
Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
66 67 68 69 70 71 72 |
# File 'lib/maxmind/response.rb', line 66 def attributes attrs = self.attribute_names.inject({}) do |attrs, name| attrs[name] = read_attribute(name) attrs end attrs.symbolize_keys end |
#attributes_from_response ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/maxmind/response.rb', line 19 def attributes_from_response hash_to_return = {} self.instance_variables.each do |var| hash_to_return[var.gsub("@","")] = self.instance_variable_get(var) end return hash_to_return end |
#parse(response) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/maxmind/response.rb', line 27 def parse(response) response.split(';').each do |parameter| k, v = parameter.split('=') case k when 'err' set_attribute('error', v) when 'custPhoneInBillingLoc' set_attribute('phone_in_billing_location', v) when 'maxmindID' set_attribute('maxmind_id', v) when 'isTransProxy' set_attribute('is_transparent_proxy', v) when 'explanation' @explanation = v else set_attribute(k.gsub(/([A-Z])/, '_\1').downcase, v) end end end |
#read_attribute(attr_name) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/maxmind/response.rb', line 74 def read_attribute(attr_name) attr_name = attr_name.to_s if !(value = @attributes[attr_name]).nil? value else nil end end |