geoplugin 0.1.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b59e30d2d61dc0b88d1f5a50139fbefb0022263f
4
- data.tar.gz: ca6ee07806ff4c3f3cda16909c6f47ac97393400
3
+ metadata.gz: a87b30dac2b39149c2750fa917cf89c0aaf25867
4
+ data.tar.gz: b90184aa2776674ba46df9074d99bebb85dca0dd
5
5
  SHA512:
6
- metadata.gz: 42b4ec00bb6bd74ad8da95be3fce779660fe1aa80b4ac9e2efb55a8631a9a8b0cc778eff800d57e847403de3966e756f9db6eb376126b529642271af183b50b4
7
- data.tar.gz: a94ec0a0b573c468dc4ebb68cfd7e32c024efada474c7bd9bd5489db50e7f844be5ca21a8b619fb8b45247f3d5460e0e960304c204968cf96d8150aca37a1ea3
6
+ metadata.gz: fd690e5765626fe76d74950f3d87826e31ee6d14ab13d54321e5a16c552598487d888174b32c31ba848aeb4008eff92103cdf6027b5f8cebda42fa224262a4dd
7
+ data.tar.gz: dc42aa6d5658d2eec7bd3b66850aeb2d3513f5be216535371546bb162e7d8a177c682d8f9b408a3b68bf7ac604e5eadfab7b0e16f63802aab8b6a91e68619773
@@ -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.ssl_locate(nil, options[:key]) : Geoplugin::Locate.locate
6
+ location = Geoplugin::Locate.locate(nil, options)
7
7
  end
8
8
 
9
9
  def self.new(ip = nil, options = {})
10
- location = options[:ssl] ? Geoplugin::Locate.ssl_locate(ip, options[:key]) : Geoplugin::Locate.locate(ip)
10
+ location = Geoplugin::Locate.locate(ip, options)
11
11
  end
12
12
  end
@@ -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
- 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
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
- def initialize(attributes)
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
- response = apiresponse(ip)
52
- new(response) unless response.empty?
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
- def self.ssl_locate(ip = nil, key)
56
- response = apiresponse(ip, true, key)
57
- new(response) unless response.empty?
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
- private
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
@@ -1,3 +1,3 @@
1
1
  module Geoplugin
2
- VERSION = "0.1.4"
2
+ VERSION = "0.3.0"
3
3
  end
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
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-17 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler