ipinfo-rails 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ipinfo-rails.rb +38 -0
  3. metadata +78 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 282cc121cb426e66103ab41be4e297631aefac73e0323f240437f66976231c78
4
+ data.tar.gz: 6e63c66fbe6553921543b8f9b3fa8a5b4b79144376b83365a8058562cab774ca
5
+ SHA512:
6
+ metadata.gz: 64f9ab7ba952f5db0723e4a01e6ce67e56bb1773fbd71c9ad240047938652bff9cb5a60e655552bed0550e4f7156a9208d228bca62137d1a09c94411ee2595e2
7
+ data.tar.gz: 69f012908250b7e7f3dac85825745a517eeff6120594c925d362f5bfab37d44e002cf93f6b66d7d6e6e917d8d79a3099f9b8c8d5d4030522602a373a86dcdbf0
@@ -0,0 +1,38 @@
1
+ require 'rack'
2
+ require 'ipinfo'
3
+
4
+ class IPinfoMiddleware
5
+ def initialize(app, cache_options = {})
6
+ @app = app
7
+
8
+ token = cache_options.fetch(:token, nil)
9
+ @ipinfo = IPinfo::create(@token, cache_options)
10
+ @filter = cache_options.fetch(:filter, nil)
11
+ end
12
+
13
+ def call(env)
14
+ env["called"] = "yes"
15
+ request = Rack::Request.new(env)
16
+
17
+ if !@filter.nil?
18
+ filtered = @filter.call(request)
19
+ else
20
+ filtered = is_bot(request)
21
+ end
22
+
23
+ if filtered
24
+ env["ipinfo"] = nil
25
+ else
26
+ ip = request.ip
27
+ env["ipinfo"] = @ipinfo.details(ip)
28
+ end
29
+
30
+ @app.call(env)
31
+ end
32
+
33
+ private
34
+ def is_bot(request)
35
+ user_agent = request.user_agent.downcase
36
+ user_agent.include?("bot") || user_agent.include?("spider")
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ipinfo-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - James Timmins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: IPinfo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: The official Rails gem for IPinfo. IPinfo prides itself on being the
42
+ most reliable, accurate, and in-depth source of IP address data available anywhere.
43
+ We process terabytes of data to produce our custom IP geolocation, company, carrier
44
+ and IP type data sets. You can visit our developer docs at https://ipinfo.io/developers.
45
+ email: jameshtimmins@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - lib/ipinfo-rails.rb
51
+ homepage: https://ipinfo.io
52
+ licenses:
53
+ - Apache-2.0
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.7.8
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: The official Rails gem for IPinfo. IPinfo prides itself on being the most
75
+ reliable, accurate, and in-depth source of IP address data available anywhere. We
76
+ process terabytes of data to produce our custom IP geolocation, company, carrier
77
+ and IP type data sets. You can visit our developer docs at https://ipinfo.io/developers.
78
+ test_files: []