geoplugin 0.1.4 → 0.3.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 +4 -4
- data/lib/geoplugin.rb +2 -2
- data/lib/geoplugin/locate.rb +32 -36
- data/lib/geoplugin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87b30dac2b39149c2750fa917cf89c0aaf25867
|
4
|
+
data.tar.gz: b90184aa2776674ba46df9074d99bebb85dca0dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd690e5765626fe76d74950f3d87826e31ee6d14ab13d54321e5a16c552598487d888174b32c31ba848aeb4008eff92103cdf6027b5f8cebda42fa224262a4dd
|
7
|
+
data.tar.gz: dc42aa6d5658d2eec7bd3b66850aeb2d3513f5be216535371546bb162e7d8a177c682d8f9b408a3b68bf7ac604e5eadfab7b0e16f63802aab8b6a91e68619773
|
data/lib/geoplugin.rb
CHANGED
@@ -3,10 +3,10 @@ require "geoplugin/locate"
|
|
3
3
|
|
4
4
|
module Geoplugin
|
5
5
|
def self.me(options = {})
|
6
|
-
location =
|
6
|
+
location = Geoplugin::Locate.locate(nil, options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.new(ip = nil, options = {})
|
10
|
-
location =
|
10
|
+
location = Geoplugin::Locate.locate(ip, options)
|
11
11
|
end
|
12
12
|
end
|
data/lib/geoplugin/locate.rb
CHANGED
@@ -7,26 +7,26 @@ API_URL = 'http://www.geoplugin.net/json.gp'
|
|
7
7
|
API_SSL_URL = 'https://ssl.geoplugin.net/json.gp'
|
8
8
|
|
9
9
|
module Geoplugin
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
10
|
+
class Locate
|
11
|
+
attr_reader :request,
|
12
|
+
:status,
|
13
|
+
:city,
|
14
|
+
:region,
|
15
|
+
:areacode,
|
16
|
+
:dmacode,
|
17
|
+
:countrycode,
|
18
|
+
:countryname,
|
19
|
+
:continentcode,
|
20
|
+
:latitude,
|
21
|
+
:longitude,
|
22
|
+
:regioncode,
|
23
|
+
:regionname,
|
24
|
+
:currencycode,
|
25
|
+
:currencysymbol,
|
26
|
+
:currencysymbol_utf,
|
27
|
+
:currencyconverter
|
28
28
|
|
29
|
-
|
29
|
+
def initialize(attributes)
|
30
30
|
@request = attributes['geoplugin_request']
|
31
31
|
@status = attributes['geoplugin_status']
|
32
32
|
@city = attributes['geoplugin_city']
|
@@ -47,23 +47,19 @@ module Geoplugin
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# locate
|
50
|
-
def self.locate(ip = nil)
|
51
|
-
|
52
|
-
|
50
|
+
def self.locate(ip = nil, options)
|
51
|
+
response = apiresponse(ip, options)
|
52
|
+
new(response) unless response.empty?
|
53
53
|
end
|
54
|
+
|
55
|
+
private
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
private_class_method
|
58
|
+
def self.apiresponse(ip = nil, options = {})
|
59
|
+
return [] unless (not ip or IPAddress.valid? ip)
|
60
|
+
url = "#{options[:ssl] ? API_SSL_URL : API_URL}?#{ip ? 'ip=' + ip : ''}#{options[:key] ? '&k=' + options[:key] : ''}#{options[:base_currency] ? '&base_currency=' + options[:base_currency] : ''}"
|
61
|
+
response = Faraday.get(URI.parse(URI.encode(url)))
|
62
|
+
response.success? ? JSON.parse(response.body) : []
|
58
63
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
private_class_method def self.apiresponse(ip = nil, ssl = false, key = nil)
|
63
|
-
return [] if ip and not IPAddress.valid? ip
|
64
|
-
url = URI.parse(URI.encode("#{ssl ? API_SSL_URL : API_URL}?#{ip ? 'ip=' + ip : ''}#{key ? '&k=' + key : ''}"))
|
65
|
-
response = Faraday.get(url)
|
66
|
-
response.success? ? JSON.parse(response.body) : []
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/geoplugin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoplugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Santangelo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|