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:) ⇒ Request

: (http_method: Symbol, base_url: Sofia::Types::BaseUrl) -> void



20
21
22
23
24
25
26
27
# File 'lib/sofia/request.rb', line 20

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

Instance Attribute Details

#bodyObject

: Sofia::Types::Body



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

def body
  @body
end

#headersObject

: Sofia::Types::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

#paramsObject

: Sofia::Types::Params



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

def params
  @params
end

Instance Method Details

#path=(path) ⇒ Object

: (untyped path) -> void



30
31
32
# File 'lib/sofia/request.rb', line 30

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

#urlObject

: -> String



50
51
52
53
54
# File 'lib/sofia/request.rb', line 50

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