simple_geolocator 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 162ba0a2fb8e881b8bf09679250b3afdf4f4d13b
4
- data.tar.gz: b18874e63807a865eb41283fad44cce504c2980a
3
+ metadata.gz: e4320a2241c0f8a819468d1c3bce0598bf06b213
4
+ data.tar.gz: d04523c554576740b5bbe41f119854ae14f481ff
5
5
  SHA512:
6
- metadata.gz: 2a68ab25452b990e7be28a1cb7bae870d370922e43eab33391a677c3e3750ce1ca41f569aa506efd269985e5e18b6de01eb855e93a60376b27f61861d57102fb
7
- data.tar.gz: dba071b5f272ef33cfcf928fa8003afc7773bb037a44444be9b1860faef8791fee119c343533216c56a4bd4b7183852266a06c1ce24f8711263ca5bbc8141763
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-eneded.
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.
@@ -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
- url = "http://ip-api.com/json/#{ip}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_geolocator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster