Sha256: 36f2e6e90002a9e9629fd3084207e08d07928ca6d3123508731befa0c53ecc8b

Contents?: true

Size: 1007 Bytes

Versions: 2

Compression:

Stored size: 1007 Bytes

Contents

require 'faraday'
require 'cassette-rack/response'

module CassetteRack
  module Request
    def get(path, params=nil, headers=nil)
      request(:get, path, params, headers)
    end

    def post(path, body, headers=nil)
      request(:post, path, nil, headers, body)
    end

    def patch(path, body, headers=nil)
      request(:patch, path, nil, headers, body)
    end

    def put(path, body=nil, headers=nil)
      request(:put, path, nil, headers, body)
    end

    def delete(path)
      request(:delete, path)
    end

    def request(method, path, params=nil, headers=nil, body=nil, options=nil)
      conn = Faraday.new(url: CassetteRack.config.url, headers: headers)
      res = conn.send(method) do |req|
        case method
        when :get, :delete
          req.url path
        when :post, :patch, :put
          req.path = path
          req.body = body
        end
      end

      @response = CassetteRack::Response.new(res)
    end

    def response
      @response
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cassette-rack-0.4.1 lib/cassette-rack/request.rb
cassette-rack-0.4.0 lib/cassette-rack/request.rb