Class: SimpleGeolocator::IPAPIResponse
- Inherits:
-
Object
- Object
- SimpleGeolocator::IPAPIResponse
- Defined in:
- lib/simple_geolocator/ipapi_response.rb
Defined Under Namespace
Classes: LOCATION_STRUCT
Instance Attribute Summary collapse
-
#city ⇒ String
readonly
The name of the city.
-
#country ⇒ LOCATION_STRUCT
readonly
The country name and code.
-
#full_response ⇒ Hash<String, Any>
readonly
The full parsed response given by the API.
-
#isp ⇒ String
readonly
The name of the ISP that the IP is using.
-
#ll ⇒ Pair<Float, Float>
readonly
The pair of the longitude and latitude.
-
#organization ⇒ String
readonly
The name of the organization that the IP is within, or their ISP name.
-
#region ⇒ LOCATION_STRUCT
readonly
The region name and code.
-
#timezone ⇒ String
readonly
The name of the timezone, e.g., America/Los Angeles.
-
#zip ⇒ String
readonly
The zip code.
Instance Method Summary collapse
-
#initialize(response = {}) ⇒ IPAPIResponse
constructor
Creates a new IPAPIResponse object.
-
#mobile? ⇒ Boolean
Whether the IP is on a mobile device.
-
#proxy? ⇒ Boolean
Whether the IP is on a proxy.
-
#successful? ⇒ Boolean
Whether the request was successful.
Constructor Details
#initialize(response = {}) ⇒ IPAPIResponse
Creates a new IPAPIResponse object.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 39 def initialize(response = {}) @full_response = response @status = response['status'] if successful? @country = LOCATION_STRUCT.new(response['country'], response['countryCode']) @region = LOCATION_STRUCT.new(response['regionName'], response['region']) @city = response['city'] @zip = response['zip'] @ll = Pair.new(response['lat'], response['lon']) @isp = response['isp'] @timezone = response['timezone'] @organization = response['org'] @mobile = response['mobile'] @proxy = response['proxy'] else case response['message'] when 'private range' fail 'The IP address is part of a private range.' when 'reserved range' fail 'The IP address is part of a reserved range.' when 'invalid query' fail 'The IP address or domain name is invalid.' when 'quota' fail 'You have reached the IP API rate limit.' else end end end |
Instance Attribute Details
#city ⇒ String (readonly)
14 15 16 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 14 def city @city end |
#country ⇒ LOCATION_STRUCT (readonly)
8 9 10 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 8 def country @country end |
#full_response ⇒ Hash<String, Any> (readonly)
5 6 7 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 5 def full_response @full_response end |
#isp ⇒ String (readonly)
26 27 28 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 26 def isp @isp end |
#ll ⇒ Pair<Float, Float> (readonly)
20 21 22 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 20 def ll @ll end |
#organization ⇒ String (readonly)
29 30 31 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 29 def organization @organization end |
#region ⇒ LOCATION_STRUCT (readonly)
11 12 13 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 11 def region @region end |
#timezone ⇒ String (readonly)
23 24 25 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 23 def timezone @timezone end |
#zip ⇒ String (readonly)
17 18 19 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 17 def zip @zip end |
Instance Method Details
#mobile? ⇒ Boolean
74 75 76 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 74 def mobile? @mobile end |
#proxy? ⇒ Boolean
79 80 81 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 79 def proxy? @proxy end |
#successful? ⇒ Boolean
69 70 71 |
# File 'lib/simple_geolocator/ipapi_response.rb', line 69 def successful? @status == 'success' end |