Sha256: 5ad76a42a2a4ea27471d01e4e78be5f1f9c3acab07254b32afb1d6b236f437df

Contents?: true

Size: 860 Bytes

Versions: 3

Compression:

Stored size: 860 Bytes

Contents

class Safettp::HTTPOptions
  AUTHENTICATORS = {
    none: Safettp::NoneAuthenticator,
    basic: Safettp::BasicAuthenticator
  }.freeze

  DEFAULT_HEADERS = {
    Accept: 'application/json',
    'Content-Type': 'application/json'
  }.freeze

  attr_reader :options_hash

  def initialize(options_hash = {})
    @options_hash = options_hash
  end

  def headers
    options_hash.fetch(:headers, DEFAULT_HEADERS)
  end

  def parser
    options_hash.fetch(:parser, Safettp::Parsers::JSON)
  end

  def query
    URI.encode_www_form(options_hash.fetch(:query, {}))
  end

  def body
    options_hash.fetch(:body, "")
  end

  def authorization
    authorization_options = options_hash.fetch(:authorization, { type: :none })
    AUTHENTICATORS.fetch(authorization_options[:type], Safettp::NoneAuthenticator)
                  .new(authorization_options)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
safettp-0.2.1 lib/safettp/http_options.rb
safettp-0.2.0 lib/safettp/http_options.rb
safettp-0.1.0 lib/safettp/http_options.rb