philnash / bitly

🗜 A Ruby wrapper for the bit.ly API
https://rubygems.org/gems/bitly
MIT License
451 stars 139 forks source link

no such fire to load -- oauth2 #25

Closed jmesserer closed 12 years ago

jmesserer commented 12 years ago

After installing the gem I am getting errors.

jdms-mm:dev User$ ruby script/server => Booting WEBrick => Rails 2.3.8 application starting on http://0.0.0.0:3000 no such file to load -- oauth2 /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in gem_original_require' /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:inrequire' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:innew_constants_in' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/bitly-0.6.2/lib/bitly/v3.rb:5 /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:ingem_original_require' /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:inrequire' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in new_constants_in' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:inrequire' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/bitly-0.6.2/lib/bitly.rb:9 /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in gem_original_require' /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:inrequire' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:innew_constants_in' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/rails/gem_dependency.rb:215:inload' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/initializer.rb:307:in load_gems' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/initializer.rb:307:ineach' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/initializer.rb:307:in load_gems' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/initializer.rb:169:inprocess' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/initializer.rb:113:in send' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/initializer.rb:113:inrun' /Users/jdm/Documents/rails/obviam/dev/config/environment.rb:9 /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in gem_original_require' /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:inrequire' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:innew_constants_in' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' /Users/jdm/.rvm/gems/ruby-1.8.7-p352@r238/gems/rails-2.3.8/lib/commands/server.rb:84 /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:ingem_original_require' /Users/jdm/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require' script/server:3 => Call with -d to detach => Ctrl-C to shutdown server [2012-09-05 02:29:43] INFO WEBrick 1.3.1 [2012-09-05 02:29:43] INFO ruby 1.8.7 (2011-06-30) [i686-darwin11.2.0] [2012-09-05 02:29:43] INFO WEBrick::HTTPServer#start: pid=57637 port=3000

Here's my gems:

jdms-mm:~ User$ gem list

* LOCAL GEMS *

actionmailer (2.3.8) actionpack (2.3.8) activemodel (3.2.8) activerecord (2.3.8) activeresource (2.3.8) activesupport (3.2.8, 2.3.8) addressable (2.3.2, 2.2.8) arel (3.0.2) Ascii85 (1.0.1) bitly (0.6.2) builder (3.0.0) bundler (1.0.21) cancan (1.5.1) chunky_png (1.2.6) crack (0.3.1) daemons (1.0.10) delayed_job (2.0.4) faraday (0.8.4, 0.7.6, 0.7.4) faraday_middleware (0.7.0) haml (3.1.7) hashery (2.0.1) hashie (1.2.0) httparty (0.8.3) httpauth (0.1) i18n (0.4.2) json (1.7.5) json_pure (1.7.5) jwt (0.1.5) mime-types (1.19) multi_json (1.3.6, 1.0.4) multi_xml (0.5.1) multipart-post (1.1.5) mysql (2.8.1) oauth (0.4.7, 0.4.5) oauth2 (0.8.0, 0.5.1, 0.5.0) omniauth (1.1.1) omniauth-linkedin (0.0.8) omniauth-oauth (1.0.1) rack (1.4.1, 1.1.3) rails (2.3.8) rake (0.8.7) rest-client (1.6.7) ruby-rc4 (0.1.5) rvm (1.11.3.5) ttfunk (1.0.3) tzinfo (0.3.33) jdms-mm:~ User$

philnash commented 12 years ago

I'm not sure what's going on here. Do you have any more information? bitly 0.6.2 only requires oauth2 > 0.1.1 and you appear to have that in your gem list. I notice you're using rvm and gemsets, is oauth2 installed in the correct gemset?

Can you open an irb session and require rubygems then bitly?

jmesserer commented 12 years ago

Sure. Let me know if there are other environment ?'s I can clarify.

jdms-mm:dev User$ ruby -v ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0] jdms-mm:dev User$ rails -v Rails 2.3.8 jdms-mm:dev User$ irb 1.8.7-p352 :001 > require 'rubygems' => true 1.8.7-p352 :002 > require 'bitly' Faraday: you may want to install system_timer for reliable timeouts => true 1.8.7-p352 :003 > Bitly.use_api_version_3 => 3 1.8.7-p352 :004 > bitly = Bitly.new 'UN', 'API_KEY' => #<Bitly::V3::Client:0x108fd1a70 @default_query_opts={:login=>"UN", :apiKey=>"API_KEY"}> 1.8.7-p352 :005 > b = bitly.shorten 'http://www.google.com' => #<Bitly::V3::Url:0x108f8b868 @user_clicks=nil, @clicks_by_minute=nil, @created_by=nil, @new_hash=true, @title=nil, @long_url="http://www.google.com/", @global_hash="2V6CFi", @client=#<Bitly::V3::Client:0x108fd1a70 @default_query_opts={:login=>"UN", :apiKey=>"API_KEY"}>, @aggregate_link=nil, @user_hash="Rl05pT", @global_clicks=nil, @short_url="http://bit.ly/Rl05pT"> 1.8.7-p352 :006 > b.short_url => "http://bit.ly/Rl05pT" 1.8.7-p352 :007 > require 'oauth2' => false

Thanks = Jeremiah

jmesserer commented 12 years ago

Loading up oauth2 ...

jdms-mm:dev User$ irb 1.8.7-p352 :001 > require 'rubygems' => true 1.8.7-p352 :002 > require 'oauth2' Faraday: you may want to install system_timer for reliable timeouts => true

philnash commented 12 years ago

OK, so it works in just irb. How are you requiring it in your Rails app?

jmesserer commented 12 years ago

I am loading it via an initializer and then I'm using it in a library (in the lib directory).


/config/settings_config.yml

development: bitly_un: BITLY_USERNAME bitly_secret: BITLY_API_KEY


/config/bitly.rb

raw_config = File.read(RAILS_ROOT + "/config/settings_config.yml") SETTINGS_CONFIG = YAML.load(raw_config)[RAILS_ENV].symbolize_keys

BITLY_USERNAME = SETTINGS_CONFIG[:bitly_un] BITLY_SECRET = SETTINGS_CONFIG[:bitly_secret] Bitly.use_api_version_3


/config/environment.rb

config.gem "bitly", :version => "= 0.6.2"


/lib/short_url_helper.rb

module ShortUrlHelper def self.generate_short_url(url) bitly = Bitly.new BITLY_USERNAME, BITLY_SECRET
b = bitly.shorten url b.short_url rescue
RAILS_DEFAULT_LOGGER.error "\n\n\ ERROR - failed to generate bitly url for #{url} **\n\n" url end
end

jmesserer commented 12 years ago

Some background information. It was working recently but my RVM environment got messed up so I deleted both the RVM Ruby and gemset entirely and attempted to reinstall both Ruby and Rails (gemset) from scratch. After a clean install it's not working. I do have it working on 2 other machines. I also tried exporting the gemset (the ruby environment and gems) from my working environments to this machine but it still doesn't work which I find really odd.

I appreciate the help!

Thanks,

J

philnash commented 12 years ago

I'm afraid I haven't dealt with a Rails app that doesn't use bundler for gem dependencies for quite a while now. Could you try including config.gem 'oauth2', :version => '0.8.0' in your environment file and see if that gets your app to notice your installed oauth2 gem.

jmesserer commented 12 years ago

/config/environment.rb

config.gem "bitly", :version => "= 0.8.0"

jdms-mm:dev User$ gem list

* LOCAL GEMS * ... bitly (0.8.0, 0.6.2) faraday (0.8.4, 0.7.6, 0.7.4) faraday_middleware (0.7.0) oauth (0.4.7, 0.4.5) oauth2 (0.8.0, 0.5.1, 0.5.0) ...

I still get the same error when I try to start a Rails server or console.

jmesserer commented 12 years ago

I added the 'oauth2' gem to my environment.rb and the problem appears to have gone away :-). Out of curiosity (it doesn't matter ... I'm just trying to understand how it should work in theory) ... that shouldn't really be required because the 'bitly' gem should take care of the dependency, correct?

Thanks for you help, I really appreciate it!

philnash commented 12 years ago

The gem does include the dependency on oauth2, see the bottom of the gemspec file. Using config.gem to include gems will require the gems you specify into the app, but it seems it doesn't necessarily require their dependencies.

If I were you I would set up Bundler to look after the gem dependencies in your app. There are instructions on how to do so in Rails 2.3 on the Bundler site. Bundler will require the gems you specify and their dependencies, managing the correct versions across all your gems too.

I'm going to close this issue as your app is working now. Glad it all got sorted!

jmesserer commented 12 years ago

Thanks a lot for the help!