Sha256: 8084c87f567db6f52ead6139e6fed83f6457920d1cc1bd5bc45bb855d4b51d87

Contents?: true

Size: 886 Bytes

Versions: 5

Compression:

Stored size: 886 Bytes

Contents

require "acter/response"
require "faraday"
require "faraday_middleware"

module Acter
  class Request
    def initialize(method, base_url, path, params = nil, headers = nil)
      @method = method.is_a?(Symbol) ? method : method.to_s.downcase
      @base_url = base_url
      @path = path
      @params = Hash(params)
      @headers = Hash(headers)
    end

    def client
      unless @client && !block_given?
        @client = Faraday.new(
          url: @base_url,
          headers: {'Accept' => "application/json"},
        ) do |faraday|
          faraday.request :json
          yield faraday if block_given?
          faraday.response :json, content_type: /\bjson(?:;|$)/
          faraday.adapter Faraday.default_adapter
        end
      end
      @client
    end

    def send
      Response.new_from_faraday(client.send(@method, @path, @params, @headers))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acter-0.2.0 lib/acter/request.rb
acter-0.1.3 lib/acter/request.rb
acter-0.1.2 lib/acter/request.rb
acter-0.1.1 lib/acter/request.rb
acter-0.1.0 lib/acter/request.rb