geoplugin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/geoplugin/locate.rb +89 -0
- data/lib/geoplugin/version.rb +1 -1
- metadata +5 -19
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.travis.yml +0 -3
- data/Gemfile +0 -4
- data/README.md +0 -73
- data/Rakefile +0 -2
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/geoplugin.gemspec +0 -37
- data/spec/geoplugin_spec.rb +0 -36
- data/spec/spec_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba0bfaa5c204a28ffbe1c43741373c4230bc9362
|
4
|
+
data.tar.gz: c826dcfc9cae86bfe1fb383055bb49adf9b3f4c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44673aafd1d603baf1262ccf7052c0b421ed0bf166e591dc9fde668ffa7cd046ccb5c3061655059b68605ca58d1a3f776cf1a8699edad4096e6dac67655aa2be
|
7
|
+
data.tar.gz: bd301f952247536b9fe6703841b17aa0b69720e7688a71faf1c067f1441464e4eab963a24b6e1b98594a2f46267cf8131eba9d99b0609a00fcc0a1a82853d2e5
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ipaddress'
|
4
|
+
|
5
|
+
API_URL = "http://www.geoplugin.net/json.gp"
|
6
|
+
API_SSL_URL = "https://ssl.geoplugin.net/json.gp"
|
7
|
+
|
8
|
+
module Geoplugin
|
9
|
+
class Locate
|
10
|
+
attr_reader :request,
|
11
|
+
:status,
|
12
|
+
:city,
|
13
|
+
:region,
|
14
|
+
:areacode,
|
15
|
+
:dmacode,
|
16
|
+
:countrycode,
|
17
|
+
:countryname,
|
18
|
+
:continentcode,
|
19
|
+
:latitude,
|
20
|
+
:longitude,
|
21
|
+
:regioncode,
|
22
|
+
:regionname,
|
23
|
+
:currencycode,
|
24
|
+
:currencysymbol,
|
25
|
+
:currencysymbol_utf,
|
26
|
+
:currencyconverter
|
27
|
+
|
28
|
+
def initialize(attributes)
|
29
|
+
@request = attributes["geoplugin_request"]
|
30
|
+
@status = attributes["geoplugin_status"]
|
31
|
+
@city = attributes["geoplugin_city"]
|
32
|
+
@region = attributes["geoplugin_region"]
|
33
|
+
@areacode = attributes["geoplugin_areaCode"]
|
34
|
+
@dmacode = attributes["geoplugin_dmaCode"]
|
35
|
+
@countrycode = attributes["geoplugin_countryCode"]
|
36
|
+
@countryname = attributes["geoplugin_countryName"]
|
37
|
+
@continentcode = attributes["geoplugin_continentCode"]
|
38
|
+
@latitude = attributes["geoplugin_latitude"]
|
39
|
+
@longitude = attributes["geoplugin_longitude"]
|
40
|
+
@regioncode = attributes["geoplugin_regionCode"]
|
41
|
+
@regionname = attributes["geoplugin_regionName"]
|
42
|
+
@currencycode = attributes["geoplugin_currencyCode"]
|
43
|
+
@currencysymbol = attributes["geoplugin_currencySymbol"]
|
44
|
+
@currencysymbol_utf = attributes["geoplugin_currencySymbol_UTF8"]
|
45
|
+
@currencyconverter = attributes["geoplugin_currencyConverter"]
|
46
|
+
end
|
47
|
+
|
48
|
+
# locate with ip
|
49
|
+
def self.locate(ip)
|
50
|
+
response = get_response(ip)
|
51
|
+
new(response) if not response.empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.ssl_locate(key, ip)
|
55
|
+
response = get_ssl_response(key, ip)
|
56
|
+
new(response) if not response.empty?
|
57
|
+
end
|
58
|
+
|
59
|
+
#locate without ip
|
60
|
+
def self.locate_no_ip
|
61
|
+
response = get_response
|
62
|
+
new(response) if not response.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.ssl_locate_no_ip(key)
|
66
|
+
response = get_ssl_response(key)
|
67
|
+
new(response) if not response.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def self.get_response(ip = nil)
|
72
|
+
|
73
|
+
return [] if ip and not IPAddress.valid? ip
|
74
|
+
|
75
|
+
url = ip ? URI.parse(URI.encode("#{API_URL}?ip=#{ip}")) : URI.parse(URI.encode("#{API_URL}"))
|
76
|
+
response = Faraday.get(url)
|
77
|
+
return response.success? ? JSON.parse(response.body) : []
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.get_ssl_response(key, ip = nil)
|
81
|
+
|
82
|
+
return [] if ip and not IPAddress.valid? ip
|
83
|
+
|
84
|
+
url = ip ? URI.parse(URI.encode("#{API_SSL_URL}?ip=#{ip}&k=#{key}")) : URI.parse(URI.encode("#{API_SSL_URL}?k=#{key}"))
|
85
|
+
response = Faraday.get(url)
|
86
|
+
return response.success? ? JSON.parse(response.body) : []
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/geoplugin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Santangelo
|
@@ -127,26 +127,14 @@ description: This is a Ruby wrapper library around the API provided by Geoplugin
|
|
127
127
|
you can provide them with content more relevant to their geographical location.
|
128
128
|
email:
|
129
129
|
- davide.santangelo@gmail.com
|
130
|
-
executables:
|
131
|
-
- console
|
132
|
-
- setup
|
130
|
+
executables: []
|
133
131
|
extensions: []
|
134
132
|
extra_rdoc_files: []
|
135
133
|
files:
|
136
|
-
- ".gitignore"
|
137
|
-
- ".rspec"
|
138
|
-
- ".travis.yml"
|
139
|
-
- Gemfile
|
140
|
-
- README.md
|
141
|
-
- Rakefile
|
142
|
-
- bin/console
|
143
|
-
- bin/setup
|
144
|
-
- geoplugin.gemspec
|
145
134
|
- lib/geoplugin.rb
|
135
|
+
- lib/geoplugin/locate.rb
|
146
136
|
- lib/geoplugin/version.rb
|
147
|
-
|
148
|
-
- spec/spec_helper.rb
|
149
|
-
homepage: ''
|
137
|
+
homepage: https://github.com/davidesantangelo/geoplugin
|
150
138
|
licenses:
|
151
139
|
- MIT
|
152
140
|
metadata:
|
@@ -172,6 +160,4 @@ signing_key:
|
|
172
160
|
specification_version: 4
|
173
161
|
summary: This is a Ruby wrapper library around the API provided by Geoplugin (http://www.geoplugin.com)
|
174
162
|
API.
|
175
|
-
test_files:
|
176
|
-
- spec/geoplugin_spec.rb
|
177
|
-
- spec/spec_helper.rb
|
163
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# Geoplugin
|
2
|
-
|
3
|
-
This is a Ruby wrapper library around the API provided by Geoplugin. Geoplugin is the easiest way for you to know where your visitors are from so that you can provide them with content more relevant to their geographical location.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'geoplugin'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install geoplugin
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
require 'geoplugin'
|
25
|
-
|
26
|
-
# Find my location without ssl
|
27
|
-
location = Geoplugin.me
|
28
|
-
|
29
|
-
# Find my location with ssl
|
30
|
-
location = Geoplugin.me(:ssl => true, :key => 'your geoplugin key')
|
31
|
-
|
32
|
-
|
33
|
-
# Find ip location with ssl
|
34
|
-
location = Geoplugin.new('8.8.8.8')
|
35
|
-
|
36
|
-
# Find my location with ssl
|
37
|
-
location = Geoplugin.new('8.8.8.8', :ssl => true, :key => 'your geoplugin key')
|
38
|
-
|
39
|
-
|
40
|
-
```
|
41
|
-
## Attributes
|
42
|
-
|
43
|
-
request,
|
44
|
-
status,
|
45
|
-
city,
|
46
|
-
region,
|
47
|
-
areacode,
|
48
|
-
dmacode,
|
49
|
-
countrycode,
|
50
|
-
countryname,
|
51
|
-
continentcode,
|
52
|
-
latitude,
|
53
|
-
longitude,
|
54
|
-
regioncode,
|
55
|
-
regionname,
|
56
|
-
currencycode,
|
57
|
-
currencysymbol,
|
58
|
-
currencysymbol_utf,
|
59
|
-
currencyconverter
|
60
|
-
|
61
|
-
## Credits
|
62
|
-
Many thanks to Geoplugin for his implementation of the API.
|
63
|
-
|
64
|
-
## License
|
65
|
-
The restcountry GEM is released under the MIT License.
|
66
|
-
|
67
|
-
## Contributing
|
68
|
-
|
69
|
-
1. Fork it ( https://github.com/[my-github-username]/geoplugin/fork )
|
70
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
-
5. Create a new Pull Request
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "geoplugin"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
data/geoplugin.gemspec
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'geoplugin/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "geoplugin"
|
8
|
-
spec.version = Geoplugin::VERSION
|
9
|
-
spec.authors = ["Davide Santangelo"]
|
10
|
-
spec.email = ["davide.santangelo@gmail.com"]
|
11
|
-
|
12
|
-
if spec.respond_to?(:metadata)
|
13
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
14
|
-
end
|
15
|
-
|
16
|
-
spec.summary = %q{This is a Ruby wrapper library around the API provided by Geoplugin (http://www.geoplugin.com) API.}
|
17
|
-
spec.description = %q{This is a Ruby wrapper library around the API provided by Geoplugin. Geoplugin is the easiest way for you to know where your visitors are from so that you can provide them with content more relevant to their geographical location.}
|
18
|
-
spec.homepage = ""
|
19
|
-
spec.license = "MIT"
|
20
|
-
|
21
|
-
spec.files = `git ls-files`.split($/)
|
22
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
-
spec.require_paths = ["lib"]
|
25
|
-
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.8"
|
27
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency 'rspec'
|
29
|
-
spec.add_development_dependency "vcr"
|
30
|
-
spec.add_development_dependency "typhoeus"
|
31
|
-
|
32
|
-
spec.required_ruby_version = ">= 1.9.3"
|
33
|
-
|
34
|
-
spec.add_dependency "faraday"
|
35
|
-
spec.add_dependency "json"
|
36
|
-
spec.add_dependency "ipaddress"
|
37
|
-
end
|
data/spec/geoplugin_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'vcr'
|
3
|
-
|
4
|
-
describe Geoplugin do
|
5
|
-
it 'has a version number' do
|
6
|
-
expect(Geoplugin::VERSION).not_to be nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'expect status 200' do
|
10
|
-
VCR.use_cassette 'locate my ip without ssl' do
|
11
|
-
response = Geoplugin.me
|
12
|
-
expect(response.status).to eq(200)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'expect status 200' do
|
17
|
-
VCR.use_cassette 'locate my ip with ssl' do
|
18
|
-
response = Geoplugin.me(:ssl => true, :key => 'your geoplugin key')
|
19
|
-
expect(response.status).to eq(200)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'get countryName United States with ip 8.8.8.8' do
|
24
|
-
VCR.use_cassette 'locate ip 8.8.8.8 without ssl' do
|
25
|
-
response = Geoplugin.new('8.8.8.8')
|
26
|
-
expect(response.countryname).to eq('United States')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'get countryName United States with ip 8.8.8.8 with SSL' do
|
31
|
-
VCR.use_cassette 'locate ip 8.8.8.8 with ssl' do
|
32
|
-
response = Geoplugin.new('8.8.8.8', :ssl => true, :key => 'your geoplugin key')
|
33
|
-
expect(response.countryname).to eq('United States')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/spec_helper.rb
DELETED