tumblr / tumblr_client

A Ruby Wrapper for the Tumblr v2 API
Apache License 2.0
224 stars 86 forks source link

NoMethodError: undefined method 'chomp' #31

Open ekan opened 10 years ago

ekan commented 10 years ago

Just bundle updated to the latest gem (0.8.1), now I can't post to Tumblr. Here's my code to post:

      Tumblr.configure do |config|
        config.consumer_key = ENV['TUMBLR_API_KEY']
        config.consumer_secret = ENV['TUMBLR_SECRET']
        config.oauth_token = poster.network.tumblr_key
        config.oauth_token_secret = poster.network.tumblr_secret
      end
      file = open(URI.parse(ENV['SERVER_DOMAIN_WITH_PORT'] + poster.social_attachment_url))
      client = Tumblr::Client.new
      response = client.photo "#{poster.network.tumblr_hostname}.tumblr.com", 
        :data => [file],
        :caption => poster.txt_content,
        :link => "http://www.theredpost.com/posters/#{poster.id}",
        :tags => "redpost,#{poster.network.tumblr_hostname}"

And I'm getting this error, from the mime-type gem:

NoMethodError: undefined method `chomp' for #<Tempfile:0x007fd0ded27538>
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/mime-types-1.25.1/lib/mime/types.rb:672:in `type_for'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/mime-types-1.25.1/lib/mime/types.rb:874:in `type_for'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/tumblr_client-0.8.1/lib/tumblr/post.rb:107:in `block in extract_data!'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/tumblr_client-0.8.1/lib/tumblr/post.rb:106:in `each'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/tumblr_client-0.8.1/lib/tumblr/post.rb:106:in `with_index'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/tumblr_client-0.8.1/lib/tumblr/post.rb:106:in `extract_data!'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/tumblr_client-0.8.1/lib/tumblr/post.rb:28:in `photo'
    from (irb):10
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands/console.rb:47:in `start'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands/console.rb:8:in `start'
    from /Users/ekan/redpost_git/RedPost/thin/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Here's the code from the gem:

672      ext = filename.chomp.downcase.gsub(/.*\./o, '')
673      list = @extension_index[ext]
674      list.delete_if { |e| not e.platform? } if platform

Any ideas?

indirect commented 10 years ago

The downloaded file was too big to be stored directly in a string, so it was stuffed into a Tempfile. That's just how the open() call works in ruby. The Tempfile is an IO object, not a string with a path to the location. You'll need to get the filename out of the Tempfile and pass it to the tumblr_client method.