Sha256: 0b77519ee9b1c8f62764ca6c4b6763f2a54b4705e9e01c2e7b0116438c601e1d

Contents?: true

Size: 835 Bytes

Versions: 26

Compression:

Stored size: 835 Bytes

Contents

module RestfulResource
  class Request
    attr_reader :body, :method, :url, :open_timeout, :timeout

    def initialize(method, url, headers: {}, body: nil, open_timeout: nil, timeout: nil)
      @method = method
      @url = url
      @headers = headers
      @body = body
      @open_timeout = open_timeout
      @timeout = timeout
    end

    def headers
      default_headers.merge(format_headers)
    end

    private

    # Formats all keys in Word-Word format
    def format_headers
      @headers.stringify_keys.each_with_object({}) do |key_with_value, headers|
        headers[format_key(key_with_value.first)] = key_with_value.last
      end
    end

    def format_key(key)
      key.humanize.split(' ').map(&:humanize).join('-')
    end

    def default_headers
      { 'Accept' => 'application/json' }
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
restful_resource-2.18.1 lib/restful_resource/request.rb
restful_resource-2.18.0 lib/restful_resource/request.rb
restful_resource-2.17.0 lib/restful_resource/request.rb
restful_resource-2.16.0 lib/restful_resource/request.rb
restful_resource-2.15.0 lib/restful_resource/request.rb
restful_resource-2.14.0 lib/restful_resource/request.rb
restful_resource-2.13.4 lib/restful_resource/request.rb
restful_resource-2.13.3 lib/restful_resource/request.rb
restful_resource-2.13.2 lib/restful_resource/request.rb
restful_resource-2.13.1 lib/restful_resource/request.rb
restful_resource-2.13.0 lib/restful_resource/request.rb
restful_resource-2.12.1 lib/restful_resource/request.rb
restful_resource-2.12.0 lib/restful_resource/request.rb
restful_resource-2.11.0 lib/restful_resource/request.rb
restful_resource-2.10.3 lib/restful_resource/request.rb
restful_resource-2.10.1 lib/restful_resource/request.rb
restful_resource-2.10.0 lib/restful_resource/request.rb
restful_resource-2.9.1 lib/restful_resource/request.rb
restful_resource-2.8.0 lib/restful_resource/request.rb
restful_resource-2.7.0 lib/restful_resource/request.rb