geoplugin 0.1.2 → 0.1.4

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: 10ceebc4d29eddbe1b90b6dc41dcc1a92b308acd
4
- data.tar.gz: 4dfe0f07722687ba3782413aee3841aa830cc533
3
+ metadata.gz: b59e30d2d61dc0b88d1f5a50139fbefb0022263f
4
+ data.tar.gz: ca6ee07806ff4c3f3cda16909c6f47ac97393400
5
5
  SHA512:
6
- metadata.gz: 85655045128bbf3fcecad483cef7e9807e819f65ebf2df105ef3f14c7cc927642e2e8ea39be3645d00791db8e52ec1eef618c72a44af2444df2b336737381819
7
- data.tar.gz: 6dc95fbdfb5abea7327ccb9b73d69153ef8e4e4ab11f5b5a729530266760248a18c37236678401b54de4cb875061074bb21d43b9951c7ca5d168f2c15fc43e68
6
+ metadata.gz: 42b4ec00bb6bd74ad8da95be3fce779660fe1aa80b4ac9e2efb55a8631a9a8b0cc778eff800d57e847403de3966e756f9db6eb376126b529642271af183b50b4
7
+ data.tar.gz: a94ec0a0b573c468dc4ebb68cfd7e32c024efada474c7bd9bd5489db50e7f844be5ca21a8b619fb8b45247f3d5460e0e960304c204968cf96d8150aca37a1ea3
@@ -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_no_ip(options[:key]) : Geoplugin::Locate.locate_no_ip
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], ip) : Geoplugin::Locate.locate(ip)
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
@@ -3,8 +3,8 @@ require 'json'
3
3
  require 'ipaddress'
4
4
  require 'uri'
5
5
 
6
- API_URL = "http://www.geoplugin.net/json.gp"
7
- API_SSL_URL = "https://ssl.geoplugin.net/json.gp"
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
- 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"]
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 with ip
50
- def self.locate(ip)
51
- response = get_response(ip)
52
- new(response) if not response.empty?
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(key, ip)
56
- response = get_ssl_response(key, ip)
57
- new(response) if not response.empty?
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
- return response.success? ? JSON.parse(response.body) : []
66
+ response.success? ? JSON.parse(response.body) : []
88
67
  end
89
68
  end
90
69
  end
@@ -1,3 +1,3 @@
1
1
  module Geoplugin
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
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.2
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-16 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler