iplocate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5c12ef0ef72d73371f47f0ce4f6ad71e220b3ccc042ccb54ccae93dbd3bf46b
4
+ data.tar.gz: b44c873d06fe29dee0fe178ee1c613223f799fd8aa10b4f59f5d40474f308e79
5
+ SHA512:
6
+ metadata.gz: c109e1edb9f4fa91bfd08f947aec3bab132b1782086ea26eb56dbac3479aef670bf822ad8f5a4bdf0b7512fd1acd7617ce93db18d542732aefcc152a0734cf9e
7
+ data.tar.gz: 8888fb24336120f88db54c170eb0a3c7bb5c577fffbd7e221a1dbaccb85724d1d7b354586ead6e5f0e714ed5c6632d752a9af24134eacaa3e3853957a8ad4b0e
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in iplocate.gemspec
6
+ gemspec
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ iplocate (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (5.1.4)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (~> 0.7)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ addressable (2.5.2)
15
+ public_suffix (>= 2.0.2, < 4.0)
16
+ concurrent-ruby (1.0.5)
17
+ crack (0.4.3)
18
+ safe_yaml (~> 1.0.0)
19
+ diff-lcs (1.3)
20
+ domain_name (0.5.20170404)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ hashdiff (0.3.7)
23
+ http-cookie (1.0.3)
24
+ domain_name (~> 0.5)
25
+ i18n (0.9.1)
26
+ concurrent-ruby (~> 1.0)
27
+ ipaddress (0.8.3)
28
+ mime-types (3.1)
29
+ mime-types-data (~> 3.2015)
30
+ mime-types-data (3.2016.0521)
31
+ minitest (5.10.3)
32
+ netrc (0.11.0)
33
+ public_suffix (3.0.1)
34
+ rake (10.5.0)
35
+ rest-client (2.0.2)
36
+ http-cookie (>= 1.0.2, < 2.0)
37
+ mime-types (>= 1.16, < 4.0)
38
+ netrc (~> 0.8)
39
+ rspec (3.7.0)
40
+ rspec-core (~> 3.7.0)
41
+ rspec-expectations (~> 3.7.0)
42
+ rspec-mocks (~> 3.7.0)
43
+ rspec-core (3.7.0)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-expectations (3.7.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-mocks (3.7.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-support (3.7.0)
52
+ safe_yaml (1.0.4)
53
+ thread_safe (0.3.6)
54
+ tzinfo (1.2.4)
55
+ thread_safe (~> 0.1)
56
+ unf (0.1.4)
57
+ unf_ext
58
+ unf_ext (0.0.7.4)
59
+ webmock (3.1.1)
60
+ addressable (>= 2.3.6)
61
+ crack (>= 0.3.2)
62
+ hashdiff
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activesupport (~> 5.1)
69
+ bundler (~> 1.16)
70
+ ipaddress (~> 0.8)
71
+ iplocate!
72
+ rake (~> 10.0)
73
+ rest-client (~> 2.0)
74
+ rspec (~> 3.0)
75
+ webmock (~> 3.1)
76
+
77
+ BUNDLED WITH
78
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Tally Tarik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # IPLocate for Ruby
2
+
3
+ Find geolocation data from IP addresses (e.g. city, country, timezone) using the [IPLocate.io](https://www.iplocate.io) API.
4
+
5
+ IPLocate.io provides 1,500 free requests per day. For higher plans, check out [the website](https://www.iplocate.io)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'iplocate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install iplocate
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'iplocate'
27
+
28
+ # Look up an IP address
29
+ results = IPLocate.lookup("8.8.8.8")
30
+
31
+ # Or with an API key
32
+ results = IPLocate.lookup("8.8.8.8", "abcdef")
33
+
34
+ results["country"]
35
+ # "United States"
36
+
37
+ results["country_code"]
38
+ # "US"
39
+
40
+ results["org"]
41
+ # "Google LLC"
42
+
43
+ results.inspect
44
+ # {
45
+ # "ip"=>"8.8.8.8",
46
+ # "country"=>"United States",
47
+ # "country_code"=>"US",
48
+ # "city"=>nil,
49
+ # "continent"=>"North America",
50
+ # "latitude"=>37.751,
51
+ # "longitude"=>-97.822,
52
+ # "time_zone"=>nil,
53
+ # "postal_code"=>nil,
54
+ # "org"=>"Google LLC",
55
+ # "asn"=>"AS15169"
56
+ # }
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tallytarik/ruby-iplocate.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "iplocate"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "iplocate/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "iplocate"
8
+ spec.version = Iplocate::VERSION
9
+ spec.authors = ["Tally Tarik"]
10
+ spec.email = ["tally.tarik@gmail.com"]
11
+
12
+ spec.summary = %q{Find geolocation data from IP addresses}
13
+ spec.description = %q{Find geolocation data from IP addresses (e.g. city, country, timezone) using the IPLocate.io API}
14
+ spec.homepage = "https://github.com/tallytarik/ruby-iplocate"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "rest-client", "~> 2.0"
25
+ spec.add_development_dependency "ipaddress", "~> 0.8"
26
+ spec.add_development_dependency "activesupport", "~> 5.1"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "webmock", "~> 3.1"
32
+ end
@@ -0,0 +1,30 @@
1
+ require "iplocate/version"
2
+ require "ipaddress"
3
+ require "rest-client"
4
+ require "json"
5
+ require 'active_support/core_ext/hash/indifferent_access'
6
+
7
+ module IPLocate
8
+ API_ENDPOINT = "https://www.iplocate.io/api/lookup/";
9
+
10
+ def self.lookup(ip_address, api_key = nil)
11
+ # Ensure IP address is valid
12
+ raise "Invalid IP address" if not IPAddress.valid? ip_address
13
+
14
+ # Add API key if given
15
+ headers = {}
16
+ if not api_key.nil?
17
+ headers[:"X-API-Key"] = api_key
18
+ end
19
+
20
+ # Call the API
21
+ endpoint = "#{API_ENDPOINT}#{ip_address}"
22
+ result = RestClient.get(endpoint, headers)
23
+
24
+ # Parse the response
25
+ # Let the parser throw JSON::ParserError on invalid response
26
+ result = JSON.parse(result)
27
+
28
+ return result.to_h.with_indifferent_access
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Iplocate
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iplocate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tally Tarik
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ipaddress
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.1'
111
+ description: Find geolocation data from IP addresses (e.g. city, country, timezone)
112
+ using the IPLocate.io API
113
+ email:
114
+ - tally.tarik@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - iplocate.gemspec
130
+ - lib/iplocate.rb
131
+ - lib/iplocate/version.rb
132
+ homepage: https://github.com/tallytarik/ruby-iplocate
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.7.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Find geolocation data from IP addresses
156
+ test_files: []