simple_geolocator 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/simple_geolocator.rb +21 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4320a2241c0f8a819468d1c3bce0598bf06b213
|
4
|
+
data.tar.gz: d04523c554576740b5bbe41f119854ae14f481ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2edd8a1dbe039a589cb27a90d51df0f8b2561cf889773d25b1870184f965cf1a7a90409bf8c50a45c55c017871e6c8f89e4a8fd0452d62a5ab3d99f3d0e2d2
|
7
|
+
data.tar.gz: 072109c812ebd0430317c98f941ab7e3c07883d4dca2d1bdc9581c60104a7593755ae91f6f956b8e716f747c8945f5d7548054fcf735adc28d37c3cd771d014b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
## Version 1
|
3
|
+
### Version 1.2.0
|
4
|
+
* Implement a simple cache that will prevent you ever exceeding the request quota! (vladc)
|
5
|
+
* New method connection for getting the types of connection you have (proxy and/or mobile) (vladc)
|
6
|
+
|
3
7
|
### Version 1.1.0
|
4
8
|
* Fix error method causing NoMethodError.
|
5
9
|
* Better documentation for all methods, including adding the missing documentation for the private error method.
|
@@ -7,7 +11,7 @@
|
|
7
11
|
* Better code in all the getter methods, improving how values are returned and how error is called.
|
8
12
|
* New get_error_description for getting the description to go with the ambiguous error message.
|
9
13
|
* Better error code, which is now dependent on request_successful?, instead of having getter methods being dependent on request_successful?. This greatly reduces the length of the methods.
|
10
|
-
* HTTPClient dependency is no longer open-
|
14
|
+
* HTTPClient dependency is no longer open-ended.
|
11
15
|
|
12
16
|
### Version 1.0.0
|
13
17
|
* Initial release version. Contains methods for most everything available with IP-API.com. The only API that I am not utilizing is the DNS API. That should come in a future release.
|
data/lib/simple_geolocator.rb
CHANGED
@@ -5,16 +5,18 @@ module SimpleGeolocator
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
@client = HTTPClient.new
|
8
|
+
@cache = {}
|
8
9
|
|
9
10
|
# Gets the full JSON response, useful for getting multiple pieces of data in
|
10
11
|
# a single request.
|
11
12
|
# @param ip [String] The IP to get data for.
|
12
13
|
# @return [JSON] A parsed JSON object containing the response.
|
13
14
|
def get_full_response(ip)
|
14
|
-
|
15
|
+
return @cache[ip] unless @cache[ip].nil?
|
16
|
+
url = "http://ip-api.com/json/#{ip}?fields=258047"
|
15
17
|
uri = URI.parse(url)
|
16
18
|
response = @client.get(uri)
|
17
|
-
JSON.parse(response.body)
|
19
|
+
@cache[ip] = JSON.parse(response.body)
|
18
20
|
end
|
19
21
|
|
20
22
|
# Gets whether the request failed or not.
|
@@ -136,6 +138,23 @@ module SimpleGeolocator
|
|
136
138
|
response['org']
|
137
139
|
end
|
138
140
|
|
141
|
+
# Gets the IP connection attributes - if it's a mobile and/or a proxy
|
142
|
+
# connection.
|
143
|
+
# @param ip [String] See #get_full_response
|
144
|
+
# @return [Hash] A hash containing data formatted as
|
145
|
+
# { :mobile => true, :proxy => true}
|
146
|
+
# @return [String] A string containing the error message.
|
147
|
+
def connection(ip)
|
148
|
+
response = get_full_response(ip)
|
149
|
+
err = error(response)
|
150
|
+
return err unless err.nil?
|
151
|
+
ret = {
|
152
|
+
mobile: response['mobile'],
|
153
|
+
proxy: response['proxy']
|
154
|
+
}
|
155
|
+
ret
|
156
|
+
end
|
157
|
+
|
139
158
|
# Gets the according description for the semi-ambiguous error returned by the
|
140
159
|
# API.
|
141
160
|
# @param error [String] The error message returned by #error
|