ipinfo / rails Goto Github PK
View Code? Open in Web Editor NEWOfficial Rails Library for IPinfo API (IP geolocation and other types of IP data)
Home Page: https://ipinfo.io
Official Rails Library for IPinfo API (IP geolocation and other types of IP data)
Home Page: https://ipinfo.io
Tried completing your steps to install, but got the below error:
Gemfile:
# frozen_string_literal: true
source 'https://rubygems.org'
ruby '2.6.3'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'coffee-rails', '~> 4.2'
gem 'jbuilder', '~> 2.5'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'rails', '~> 5.2.3'
gem 'sass-rails', '~> 5.0'
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'
gem 'ipinfo-rails'
...
config/environment.rb:
require 'ipinfo-rails'
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
# Rails.application.config.middleware.use(IPinfoMiddleware, {token: ENV['IP_INFO_API_KEY']})
When I run rails s
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Exiting
Traceback (most recent call last):
54: from bin/rails:3:in `<main>'
53: from bin/rails:3:in `load'
52: from bin/spring:15:in `<top (required)>'
51: from bin/spring:15:in `require'
50: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
49: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
48: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
47: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
46: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
45: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
44: from ~/.rvm/gems/ruby-2.6.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
43: from ~/dev/caravan-app/bin/rails:9:in `<top (required)>'
42: from ~/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
41: from ~/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
40: from ~/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
39: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
38: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
37: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
36: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
35: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
34: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
33: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
32: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
31: from ~/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
30: from ~/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
29: from ~/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
28: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `perform'
27: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `tap'
26: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:147:in `block in perform'
25: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:51:in `start'
24: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:89:in `log_to_stdout'
23: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/server.rb:354:in `wrapped_app'
22: from ~/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:27:in `app'
21: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/server.rb:219:in `app'
20: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/server.rb:319:in `build_app_and_options_from_config'
19: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/builder.rb:40:in `parse_file'
18: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/builder.rb:49:in `new_from_string'
17: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/builder.rb:49:in `eval'
16: from config.ru:in `<main>'
15: from config.ru:in `new'
14: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
13: from ~/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
12: from config.ru:5:in `block in <main>'
11: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `require_relative'
10: from ~/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
9: from ~/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
8: from ~/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
7: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
6: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
5: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
4: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
3: from ~/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2: from ~/dev/caravan-app/config/environment.rb:11:in `<main>'
1: from ~/.rvm/gems/ruby-2.6.3/gems/actionpack-5.2.3/lib/action_dispatch/middleware/stack.rb:97:in `use'
~/.rvm/gems/ruby-2.6.3/gems/actionpack-5.2.3/lib/action_dispatch/middleware/stack.rb:97:in `push': can't modify frozen Array (FrozenError)
ruby -v
: ruby 2.6.3p62 (2019-04-16 revision 67580)
rails -v
: Rails 5.2.3
We're using this library and when the IPInfo API returns a 503 response, the handler for IPInfo raises an error because the return from the API is not a JSON, but rather a String which states the following,
unexpected token at 'upstream connect error or disconnect/reset before headers. reset reason: connection timeout' (JSON::ParserError)
I have looked at the code and it seems the ipinfo-rails gem relies on the ipinfo Ruby gem version 1.0.1. But the latest version of the IPInfo ruby gem is 2.2.1.
Any idea why we're keeping the Ruby gem's dependency so low?
Thanks for your answer.
Hi Team, just starting to use this gem, following the instructions, i get the following ...
System : Windows 10, Ruby 2.6.6, Rails 6.0.3
added to gemfile gem 'ipinfo-rails'
Thanks in advance
Any help would be appreciated
bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.1
Using multipart-post 2.1.1
Using faraday 0.17.3
Using json 2.3.1
Fetching PriorityQueue 0.1.2
Installing PriorityQueue 0.1.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/PriorityQueue-0.1.2/ext/priority_queue
C:/Ruby26-x64/bin/ruby.exe -I C:/Ruby26-x64/lib/ruby/2.6.0 -r
./siteconf20201125-28200-ycxfbe.rb extconf.rb
creating Makefile
current directory:
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/PriorityQueue-0.1.2/ext/priority_queue
make "DESTDIR=" clean
current directory:
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/PriorityQueue-0.1.2/ext/priority_queue
make "DESTDIR="
generating CPriorityQueue-x64-mingw32.def
compiling priority_queue.c
In file included from C:/Ruby26-x64/include/ruby-2.6.0/ruby.h:33,
from priority_queue.c:24:
priority_queue.c: In function 'pq_push':
priority_queue.c:512:40: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
512 | rb_hash_aset(hash, object, ULONG2NUM((unsigned long) n)); // TODO:
This is hackish, maybe its better to also wrap the nodes.
| ^
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1615:45: note: in definition of
macro 'RB_ULONG2NUM'
1615 | #define RB_ULONG2NUM(x) rb_ulong2num_inline(x)
| ^
priority_queue.c:512:30: note: in expansion of macro 'ULONG2NUM'
512 | rb_hash_aset(hash, object, ULONG2NUM((unsigned long) n)); // TODO:
This is hackish, maybe its better to also wrap the nodes.
| ^~~~~~~~~
priority_queue.c: In function 'pq_change_priority':
priority_queue.c:700:39: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
700 | priority_queue_change_priority(q, (priority_node*) NUM2ULONG(node),
priority);
| ^
priority_queue.c: In function 'pq_get_priority':
priority_queue.c:726:22: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
726 | return (VALUE) (((priority_node*)
NUM2ULONG(node_pointer))->priority);
| ^
priority_queue.c: In function 'pq_delete':
priority_queue.c:788:24: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
788 | priority_node* n = (priority_node*) NUM2ULONG(node_pointer);
| ^
In file included from C:/Ruby26-x64/include/ruby-2.6.0/ruby.h:33,
from priority_queue.c:24:
priority_queue.c: In function 'pq_node2dot':
priority_queue.c:809:14: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
809 | ULONG2NUM((unsigned long) n), n->object, n->priority));
| ^
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:2599:35: note: in definition of
macro 'rb_funcall'
2599 | const VALUE rb_funcall_args[] = {__VA_ARGS__}; \
| ^~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1630:22: note: in expansion of
macro 'RB_ULONG2NUM'
1630 | #define ULONG2NUM(x) RB_ULONG2NUM(x)
| ^~~~~~~~~~~~
priority_queue.c:809:4: note: in expansion of macro 'ULONG2NUM'
809 | ULONG2NUM((unsigned long) n), n->object, n->priority));
| ^~~~~~~~~
priority_queue.c:813:14: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
813 | ULONG2NUM((unsigned long) n), n->object, n->priority));
| ^
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:2599:35: note: in definition of
macro 'rb_funcall'
2599 | const VALUE rb_funcall_args[] = {__VA_ARGS__}; \
| ^~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1630:22: note: in expansion of
macro 'RB_ULONG2NUM'
1630 | #define ULONG2NUM(x) RB_ULONG2NUM(x)
| ^~~~~~~~~~~~
priority_queue.c:813:4: note: in expansion of macro 'ULONG2NUM'
813 | ULONG2NUM((unsigned long) n), n->object, n->priority));
| ^~~~~~~~~
priority_queue.c:821:16: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
821 | ULONG2NUM((unsigned long) n), ULONG2NUM((unsigned long) n1)));
| ^
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:2599:35: note: in definition of
macro 'rb_funcall'
2599 | const VALUE rb_funcall_args[] = {__VA_ARGS__}; \
| ^~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1630:22: note: in expansion of
macro 'RB_ULONG2NUM'
1630 | #define ULONG2NUM(x) RB_ULONG2NUM(x)
| ^~~~~~~~~~~~
priority_queue.c:821:6: note: in expansion of macro 'ULONG2NUM'
821 | ULONG2NUM((unsigned long) n), ULONG2NUM((unsigned long) n1)));
| ^~~~~~~~~
priority_queue.c:821:46: warning: cast from pointer to integer of different size
[-Wpointer-to-int-cast]
821 | ULONG2NUM((unsigned long) n), ULONG2NUM((unsigned long) n1)));
| ^
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:2599:35: note: in definition of
macro 'rb_funcall'
2599 | const VALUE rb_funcall_args[] = {__VA_ARGS__}; \
| ^~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1630:22: note: in expansion of
macro 'RB_ULONG2NUM'
1630 | #define ULONG2NUM(x) RB_ULONG2NUM(x)
| ^~~~~~~~~~~~
priority_queue.c:821:36: note: in expansion of macro 'ULONG2NUM'
821 | ULONG2NUM((unsigned long) n), ULONG2NUM((unsigned long) n1)));
| ^~~~~~~~~
In file included from C:/Ruby26-x64/include/ruby-2.6.0/ruby.h:33,
from priority_queue.c:24:
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: error: call to
'rb_varargs_bad_length' declared with attribute error: argument length doesn't
match
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: note: in definition of
macro 'rb_varargs_argc_check'
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~
priority_queue.c:820:4: note: in expansion of macro 'rb_funcall'
820 | rb_funcall(Qnil, id_format, 4, rb_str_new2("NODE%i -> NODE%i;\n"),
| ^~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: error: call to
'rb_varargs_bad_length' declared with attribute error: argument length doesn't
match
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: note: in definition of
macro 'rb_varargs_argc_check'
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~
priority_queue.c:820:4: note: in expansion of macro 'rb_funcall'
820 | rb_funcall(Qnil, id_format, 4, rb_str_new2("NODE%i -> NODE%i;\n"),
| ^~~~~~~~~~
In function 'pq_node2dot',
inlined from 'pq_node2dot' at priority_queue.c:817:7,
inlined from 'pq_to_dot' at priority_queue.c:841:7:
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: error: call to
'rb_varargs_bad_length' declared with attribute error: argument length doesn't
match
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: note: in definition of
macro 'rb_varargs_argc_check'
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~
priority_queue.c:820:4: note: in expansion of macro 'rb_funcall'
820 | rb_funcall(Qnil, id_format, 4, rb_str_new2("NODE%i -> NODE%i;\n"),
| ^~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: error: call to
'rb_varargs_bad_length' declared with attribute error: argument length doesn't
match
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: note: in definition of
macro 'rb_varargs_argc_check'
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~
priority_queue.c:820:4: note: in expansion of macro 'rb_funcall'
820 | rb_funcall(Qnil, id_format, 4, rb_str_new2("NODE%i -> NODE%i;\n"),
| ^~~~~~~~~~
In function 'pq_node2dot',
inlined from 'pq_to_dot' at priority_queue.c:841:7:
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: error: call to
'rb_varargs_bad_length' declared with attribute error: argument length doesn't
match
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: note: in definition of
macro 'rb_varargs_argc_check'
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~
priority_queue.c:820:4: note: in expansion of macro 'rb_funcall'
820 | rb_funcall(Qnil, id_format, 4, rb_str_new2("NODE%i -> NODE%i;\n"),
| ^~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: error: call to
'rb_varargs_bad_length' declared with attribute error: argument length doesn't
match
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Ruby26-x64/include/ruby-2.6.0/ruby/ruby.h:1850:3: note: in definition of
macro 'rb_varargs_argc_check'
1850 | rb_varargs_bad_length(argc, vargc)), \
| ^~~~~~~~~~~~~~~~~~~~~
priority_queue.c:820:4: note: in expansion of macro 'rb_funcall'
820 | rb_funcall(Qnil, id_format, 4, rb_str_new2("NODE%i -> NODE%i;\n"),
| ^~~~~~~~~~
make: *** [Makefile:244: priority_queue.o] Error 1
make failed, exit code 2
Gem files will remain installed in
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/PriorityQueue-0.1.2 for inspection.
Results logged to
C:/Ruby26-x64/lib/ruby/gems/2.6.0/extensions/x64-mingw32/2.6.0/PriorityQueue-0.1.2/gem_make.out
An error occurred while installing PriorityQueue (0.1.2), and Bundler cannot
continue.
Make sure that `gem install PriorityQueue -v '0.1.2' --source
'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
ipinfo-rails was resolved to 0.1.1, which depends on
IPinfo was resolved to 0.1.2, which depends on
lrucache was resolved to 0.1.4, which depends on
PriorityQueue
Hi. So, i've just installed and configured the gem. Tremendous work and works perfectly. However, when i try to print the attributes for puts request.env['ipinfo'].all
i get the following
{:ip=>"::1", :bogon=>true, :ip_address=>#<IPAddr: IPv6:0000:0000:0000:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>}
I am testing on development mode.
all other attributes are missing. i could not find out where to fix it. what's going wrong? Thanks.
When we fix up the issues present at https://github.com/ipinfo/ruby/issues - update this library to use the latest version.
Add an optional IP selection handler to the SDK client initialization step which accepts the request context and expects returning an IP.
The default handler, if no handler is specified by the user, will simply return the IP attached to the request object.
An additional handler should be available within the library, which looks into the X-Forwarded-For
header and gets the first IP in the list if it exists, falling back to the IP attached to the request if the header isn't available. This is an implementation that users can optionally use instead of making their own.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.