-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ipinfo/uman/fixes
v1.0.0; dependency upgrades & other fixes
- Loading branch information
Showing
7 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
ipinfo-rails-*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
AllCops: | ||
TargetRubyVersion: 2.5 | ||
NewCops: enable | ||
|
||
Layout/IndentationWidth: | ||
Width: 4 | ||
|
||
Layout/LineLength: | ||
Enabled: true | ||
Max: 80 | ||
|
||
Lint/MissingSuper: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Enabled: false | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Metrics/ClassLength: | ||
Enabled: false | ||
|
||
Lint/DuplicateMethods: | ||
Enabled: false | ||
|
||
Style/Documentation: | ||
Enabled: false | ||
|
||
Style/ClassAndModuleChildren: | ||
Enabled: false | ||
|
||
Style/MethodCallWithArgsParentheses: | ||
EnforcedStyle: require_parentheses | ||
IgnoreMacros: false | ||
IgnoredPatterns: [] | ||
AllowParenthesesInMultilineCall: true | ||
AllowParenthesesInChaining: true | ||
AllowParenthesesInCamelCaseMethod: true | ||
|
||
Style/MethodCallWithoutArgsParentheses: | ||
Enabled: false | ||
|
||
Naming/FileName: | ||
Enabled: false | ||
|
||
Naming/PredicateName: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.7.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
group :development do | ||
gem 'bundler' | ||
gem 'minitest' | ||
gem 'minitest-reporters' | ||
gem 'rubocop' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
lib = File.expand_path('lib', __dir__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
||
require 'ipinfo-rails/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'ipinfo-rails' | ||
s.version = '0.1.1' | ||
s.date = '2018-12-10' | ||
s.summary = "The official Rails gem for IPinfo. IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets. You can visit our developer docs at https://ipinfo.io/developers." | ||
s.description = "The official Rails gem for IPinfo. IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets. You can visit our developer docs at https://ipinfo.io/developers." | ||
s.authors = ["James Timmins"] | ||
s.email = '[email protected]' | ||
s.files = ["lib/ipinfo-rails.rb"] | ||
s.homepage = 'https://ipinfo.io' | ||
s.license = 'Apache-2.0' | ||
|
||
s.add_runtime_dependency 'IPinfo', '~> 0.1.2' | ||
s.add_runtime_dependency 'rack', '~> 2.0' | ||
s.name = 'ipinfo-rails' | ||
s.version = IPinfoRails::VERSION | ||
s.required_ruby_version = '>= 2.5.0' | ||
s.date = '2018-12-10' | ||
s.summary = 'The official Rails gem for IPinfo. IPinfo prides itself on ' \ | ||
'being the most reliable, accurate, and in-depth source of ' \ | ||
'IP address data available anywhere. We process terabytes ' \ | ||
'of data to produce our custom IP geolocation, company, ' \ | ||
'carrier and IP type data sets. You can visit our developer ' \ | ||
'docs at https://ipinfo.io/developers.' | ||
s.description = s.summary | ||
s.authors = ['James Timmins', 'Uman Shahzad'] | ||
s.email = ['[email protected]', '[email protected]'] | ||
s.homepage = 'https://ipinfo.io' | ||
s.license = 'Apache-2.0' | ||
|
||
s.add_runtime_dependency 'IPinfo', '~> 1.0.1' | ||
s.add_runtime_dependency 'rack', '~> 2.0' | ||
|
||
s.files = `git ls-files -z`.split("\x0").reject do |f| | ||
f.match(%r{^(test|spec|features)/}) | ||
end | ||
s.require_paths = ['lib'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rack' | ||
require 'ipinfo' | ||
|
||
class IPinfoMiddleware | ||
def initialize(app, cache_options = {}) | ||
@app = app | ||
|
||
token = cache_options.fetch(:token, nil) | ||
@ipinfo = IPinfo::create(@token, cache_options) | ||
@filter = cache_options.fetch(:filter, nil) | ||
end | ||
|
||
def call(env) | ||
env["called"] = "yes" | ||
request = Rack::Request.new(env) | ||
|
||
if !@filter.nil? | ||
filtered = @filter.call(request) | ||
else | ||
filtered = is_bot(request) | ||
def initialize(app, cache_options = {}) | ||
@app = app | ||
@token = cache_options.fetch(:token, nil) | ||
@ipinfo = IPinfo.create(@token, cache_options) | ||
@filter = cache_options.fetch(:filter, nil) | ||
end | ||
|
||
if filtered | ||
env["ipinfo"] = nil | ||
else | ||
ip = request.ip | ||
env["ipinfo"] = @ipinfo.details(ip) | ||
def call(env) | ||
env['called'] = 'yes' | ||
request = Rack::Request.new(env) | ||
|
||
filtered = if @filter.nil? | ||
is_bot(request) | ||
else | ||
@filter.call(request) | ||
end | ||
|
||
if filtered | ||
env['ipinfo'] = nil | ||
else | ||
ip = request.ip | ||
env['ipinfo'] = @ipinfo.details(ip) | ||
end | ||
|
||
@app.call(env) | ||
end | ||
|
||
@app.call(env) | ||
end | ||
private | ||
|
||
private | ||
def is_bot(request) | ||
user_agent = request.user_agent.downcase | ||
user_agent.include?("bot") || user_agent.include?("spider") | ||
user_agent = request.user_agent.downcase | ||
user_agent.include?('bot') || user_agent.include?('spider') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module IPinfoRails | ||
VERSION = '1.0.0' | ||
end |