Class: Safettp::HTTPOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/safettp/http_options.rb

Constant Summary collapse

AUTHENTICATORS =
{
  none: Safettp::NoneAuthenticator,
  basic: Safettp::BasicAuthenticator
}.freeze
DEFAULT_HEADERS =
{
  Accept: 'application/json',
  'Content-Type': 'application/json'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options_hash = {}) ⇒ HTTPOptions

Returns a new instance of HTTPOptions.



14
15
16
# File 'lib/safettp/http_options.rb', line 14

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

Instance Attribute Details

#options_hashObject (readonly)

Returns the value of attribute options_hash.



12
13
14
# File 'lib/safettp/http_options.rb', line 12

def options_hash
  @options_hash
end

Instance Method Details

#authorizationObject



34
35
36
37
38
# File 'lib/safettp/http_options.rb', line 34

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

#bodyObject



30
31
32
# File 'lib/safettp/http_options.rb', line 30

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

#headersObject



18
19
20
# File 'lib/safettp/http_options.rb', line 18

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

#parserObject



22
23
24
# File 'lib/safettp/http_options.rb', line 22

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

#queryObject



26
27
28
# File 'lib/safettp/http_options.rb', line 26

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