Sha256: fb179e29c4d78a4f08b6d34439d1ec00ab74e0aeeddfaa636b91bb063ce93121

Contents?: true

Size: 776 Bytes

Versions: 5

Compression:

Stored size: 776 Bytes

Contents

require 'faraday'

module Twitter
  module REST
    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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twitter-5.1.1 lib/twitter/rest/request/multipart_with_file.rb
twitter-5.1.0 lib/twitter/rest/request/multipart_with_file.rb
twitter-5.0.1 lib/twitter/rest/request/multipart_with_file.rb
twitter-5.0.0 lib/twitter/rest/request/multipart_with_file.rb
twitter-5.0.0.rc.1 lib/twitter/rest/request/multipart_with_file.rb