Class: Sofia::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/sofia/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method:, base_url:, options: Sofia::Options.new) ⇒ Request

: (http_method: Symbol, base_url: Sofia::Types::Client::BaseUrl, ?options: Sofia::Options) -> void



23
24
25
26
27
28
29
30
31
# File 'lib/sofia/request.rb', line 23

def initialize(http_method:, base_url:, options: Sofia::Options.new)
  @http_method = http_method
  @base_url    = base_url
  @options     = options #: Sofia::Options
  @path        = Sofia::Types::Client::Path.new #: Sofia::Types::Client::Path
  @params      = Sofia::Types::Client::Params.new #: Sofia::Types::Client::Params
  @headers     = Sofia::Types::Client::Headers.new #: Sofia::Types::Client::Headers
  @body        = Sofia::Types::Client::Body.new #: Sofia::Types::Client::Body
end

Instance Attribute Details

#bodyObject

: Sofia::Types::Client::Body



17
18
19
# File 'lib/sofia/request.rb', line 17

def body
  @body
end

#headersObject

: Sofia::Types::Client::Headers



11
12
13
# File 'lib/sofia/request.rb', line 11

def headers
  @headers
end

#http_methodObject (readonly)

: Symbol



8
9
10
# File 'lib/sofia/request.rb', line 8

def http_method
  @http_method
end

#optionsObject (readonly)

: Sofia::Options



20
21
22
# File 'lib/sofia/request.rb', line 20

def options
  @options
end

#paramsObject

: Sofia::Types::Client::Params



14
15
16
# File 'lib/sofia/request.rb', line 14

def params
  @params
end

Instance Method Details

#path=(path) ⇒ Object

: (untyped path) -> void



34
35
36
# File 'lib/sofia/request.rb', line 34

def path=(path)
  @path = Sofia::Types::Client::Path.new(path)
end

#urlObject

: -> String



54
55
56
57
58
# File 'lib/sofia/request.rb', line 54

def url
  qs = @params.to_s
  base = @base_url.to_s + @path.to_s
  qs.empty? ? base : "#{base}?#{qs}"
end