geoplugin 0.1.2 → 0.1.4
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 +3 -3
- data/lib/geoplugin/locate.rb +30 -51
- 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: b59e30d2d61dc0b88d1f5a50139fbefb0022263f
|
4
|
+
data.tar.gz: ca6ee07806ff4c3f3cda16909c6f47ac97393400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42b4ec00bb6bd74ad8da95be3fce779660fe1aa80b4ac9e2efb55a8631a9a8b0cc778eff800d57e847403de3966e756f9db6eb376126b529642271af183b50b4
|
7
|
+
data.tar.gz: a94ec0a0b573c468dc4ebb68cfd7e32c024efada474c7bd9bd5489db50e7f844be5ca21a8b619fb8b45247f3d5460e0e960304c204968cf96d8150aca37a1ea3
|
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 = options[:ssl] ? Geoplugin::Locate.
|
6
|
+
location = options[:ssl] ? Geoplugin::Locate.ssl_locate(nil, options[:key]) : Geoplugin::Locate.locate
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.new(ip, options = {})
|
10
|
-
location = options[:ssl] ? Geoplugin::Locate.ssl_locate(options[:key]
|
9
|
+
def self.new(ip = nil, options = {})
|
10
|
+
location = options[:ssl] ? Geoplugin::Locate.ssl_locate(ip, options[:key]) : Geoplugin::Locate.locate(ip)
|
11
11
|
end
|
12
12
|
end
|
data/lib/geoplugin/locate.rb
CHANGED
@@ -3,8 +3,8 @@ require 'json'
|
|
3
3
|
require 'ipaddress'
|
4
4
|
require 'uri'
|
5
5
|
|
6
|
-
API_URL =
|
7
|
-
API_SSL_URL =
|
6
|
+
API_URL = 'http://www.geoplugin.net/json.gp'
|
7
|
+
API_SSL_URL = 'https://ssl.geoplugin.net/json.gp'
|
8
8
|
|
9
9
|
module Geoplugin
|
10
10
|
class Locate
|
@@ -26,65 +26,44 @@ module Geoplugin
|
|
26
26
|
:currencysymbol_utf,
|
27
27
|
:currencyconverter
|
28
28
|
|
29
|
-
|
30
|
-
@request = attributes[
|
31
|
-
@status = attributes[
|
32
|
-
@city = attributes[
|
33
|
-
@region = attributes[
|
34
|
-
@areacode = attributes[
|
35
|
-
@dmacode = attributes[
|
36
|
-
@countrycode = attributes[
|
37
|
-
@countryname = attributes[
|
38
|
-
@continentcode = attributes[
|
39
|
-
@latitude = attributes[
|
40
|
-
@longitude = attributes[
|
41
|
-
@regioncode = attributes[
|
42
|
-
@regionname = attributes[
|
43
|
-
@currencycode = attributes[
|
44
|
-
@currencysymbol = attributes[
|
45
|
-
@currencysymbol_utf = attributes[
|
46
|
-
@currencyconverter = attributes[
|
29
|
+
def initialize(attributes)
|
30
|
+
@request = attributes['geoplugin_request']
|
31
|
+
@status = attributes['geoplugin_status']
|
32
|
+
@city = attributes['geoplugin_city']
|
33
|
+
@region = attributes['geoplugin_region']
|
34
|
+
@areacode = attributes['geoplugin_areaCode']
|
35
|
+
@dmacode = attributes['geoplugin_dmaCode']
|
36
|
+
@countrycode = attributes['geoplugin_countryCode']
|
37
|
+
@countryname = attributes['geoplugin_countryName']
|
38
|
+
@continentcode = attributes['geoplugin_continentCode']
|
39
|
+
@latitude = attributes['geoplugin_latitude']
|
40
|
+
@longitude = attributes['geoplugin_longitude']
|
41
|
+
@regioncode = attributes['geoplugin_regionCode']
|
42
|
+
@regionname = attributes['geoplugin_regionName']
|
43
|
+
@currencycode = attributes['geoplugin_currencyCode']
|
44
|
+
@currencysymbol = attributes['geoplugin_currencySymbol']
|
45
|
+
@currencysymbol_utf = attributes['geoplugin_currencySymbol_UTF8']
|
46
|
+
@currencyconverter = attributes['geoplugin_currencyConverter']
|
47
47
|
end
|
48
48
|
|
49
|
-
# locate
|
50
|
-
def self.locate(ip)
|
51
|
-
response =
|
52
|
-
new(response)
|
49
|
+
# locate
|
50
|
+
def self.locate(ip = nil)
|
51
|
+
response = apiresponse(ip)
|
52
|
+
new(response) unless response.empty?
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.ssl_locate(
|
56
|
-
response =
|
57
|
-
new(response)
|
58
|
-
end
|
59
|
-
|
60
|
-
#locate without ip
|
61
|
-
def self.locate_no_ip
|
62
|
-
response = get_response
|
63
|
-
new(response) if not response.empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.ssl_locate_no_ip(key)
|
67
|
-
response = get_ssl_response(key)
|
68
|
-
new(response) if not response.empty?
|
55
|
+
def self.ssl_locate(ip = nil, key)
|
56
|
+
response = apiresponse(ip, true, key)
|
57
|
+
new(response) unless response.empty?
|
69
58
|
end
|
70
59
|
|
71
60
|
private
|
72
|
-
def self.get_response(ip = nil)
|
73
|
-
|
74
|
-
return [] if ip and not IPAddress.valid? ip
|
75
|
-
|
76
|
-
url = ip ? URI.parse(URI.encode("#{API_URL}?ip=#{ip}")) : URI.parse(URI.encode("#{API_URL}"))
|
77
|
-
response = Faraday.get(url)
|
78
|
-
return response.success? ? JSON.parse(response.body) : []
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.get_ssl_response(key, ip = nil)
|
82
61
|
|
62
|
+
private_class_method def self.apiresponse(ip = nil, ssl = false, key = nil)
|
83
63
|
return [] if ip and not IPAddress.valid? ip
|
84
|
-
|
85
|
-
url = ip ? URI.parse(URI.encode("#{API_SSL_URL}?ip=#{ip}&k=#{key}")) : URI.parse(URI.encode("#{API_SSL_URL}?k=#{key}"))
|
64
|
+
url = URI.parse(URI.encode("#{ssl ? API_SSL_URL : API_URL}?#{ip ? 'ip=' + ip : ''}#{key ? '&k=' + key : ''}"))
|
86
65
|
response = Faraday.get(url)
|
87
|
-
|
66
|
+
response.success? ? JSON.parse(response.body) : []
|
88
67
|
end
|
89
68
|
end
|
90
69
|
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.1.
|
4
|
+
version: 0.1.4
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|