Class: MaxMind::CityService

Inherits:
Service
  • Object
show all
Defined in:
lib/max_mind/service/city.rb

Instance Attribute Summary

Attributes inherited from Service

#response

Instance Method Summary collapse

Methods inherited from Service

#build_path, fetch_for_ip, #make_request

Instance Method Details

#parsed_responseObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/max_mind/service/city.rb', line 6

def parsed_response
  if self.valid_response?
    parsed_response = CSV.parse_line(self.response)
    {
      :country => parsed_response[0],
      :state => parsed_response[1],
      :city => parsed_response[2],
      :latitude => parsed_response[3],
      :longitude => parsed_response[4],
      :api_response => self.response
    }
  else
    {
      :api_response => self.response
    }
  end
end

#valid_response?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/max_mind/service/city.rb', line 24

def valid_response?
  super && !(self.response =~ /,,,,,(.+?)/)
end