Sha256: 477ad3e409dc8e123decbc9e388ed50b096c91666963540936bdb99ae34e3f5b

Contents?: true

Size: 1019 Bytes

Versions: 3

Compression:

Stored size: 1019 Bytes

Contents

require 'faraday'
class FaradayAdapter < HTTPBaseAdapter
  def send_get_request
    connection.get do |req|
      req.url parse_uri.to_s
      req.headers = @headers
    end
  end

  def send_post_request
    connection.post do |req|
      req.url parse_uri.to_s
      req.headers = @headers
      req.body = query_string
    end
  end

  def send_post_form_request
    connection.post do |req|
      req.url parse_uri.to_s
      req.headers = @headers
      req.body = @params
    end
  end

  def send_multipart_post_request
    file_upload = Faraday::UploadIO.new(@params['file'], 'text/plain')

    connection.post do |req|
      req.url parse_uri.to_s
      req.headers = @headers
      req.body = @params.merge('file' => file_upload)
    end
  end

  private

  def connection
    Faraday.new(url: "#{@protocol}://#{@host}:#{@port}") do |faraday|
      faraday.request :multipart
      faraday.request :url_encoded

      faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
binnacle-0.5.0 spec/adapters/faraday_adapter.rb
binnacle-0.4.9 spec/adapters/faraday_adapter.rb
binnacle-0.4.8 spec/adapters/faraday_adapter.rb