Sha256: 73cdd0f8a58b79f4b23cd1325895f8d46d63b1cb242c7997a98627b10fa5b313

Contents?: true

Size: 704 Bytes

Versions: 11

Compression:

Stored size: 704 Bytes

Contents

require 'faraday'

module Twitter
  module Request
    class MultipartWithFile < Faraday::Middleware
      CONTENT_TYPE = 'Content-Type'

      def call(env)
        env[:body].each do |key, value|
          if value.respond_to?(:to_io)
            env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
          end
        end if env[:body].is_a?(::Hash)
        @app.call(env)
      end

    private

      def mime_type(path)
        case path
        when /\.jpe?g/i
          'image/jpeg'
        when /\.gif$/i
          'image/gif'
        when /\.png$/i
          'image/png'
        else
          'application/octet-stream'
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
twitter-4.8.1 lib/twitter/request/multipart_with_file.rb
twitter-4.8.0 lib/twitter/request/multipart_with_file.rb
twitter-4.7.0 lib/twitter/request/multipart_with_file.rb
twitter-4.6.2 lib/twitter/request/multipart_with_file.rb
twitter-4.6.1 lib/twitter/request/multipart_with_file.rb
twitter-4.6.0 lib/twitter/request/multipart_with_file.rb
twitter-4.5.0 lib/twitter/request/multipart_with_file.rb
twitter-4.4.4 lib/twitter/request/multipart_with_file.rb
twitter-4.4.3 lib/twitter/request/multipart_with_file.rb
twitter-4.4.2 lib/twitter/request/multipart_with_file.rb
twitter-4.4.1 lib/twitter/request/multipart_with_file.rb