Class: Soren::Response

Inherits:
Object show all
Defined in:
lib/soren/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_response) ⇒ Response

: (Hash[Symbol, untyped]) -> void



14
15
16
17
18
19
20
21
22
# File 'lib/soren/response.rb', line 14

def initialize(parsed_response)
  parsed_status_line = parsed_response[:status_line]
  @version = parsed_status_line[:version] #: Soren::Types::Response::Version
  @code = parsed_status_line[:code] #: Soren::Types::Response::Code
  @message = parsed_status_line[:message] #: Soren::Types::Response::Message

  @headers = parsed_response[:headers] #: Soren::Types::Response::Headers
  @body = parsed_response[:body] #: Soren::Types::Response::Body
end

Class Method Details

.from_parts(code:, message:, version:, headers:, body:) ⇒ Object

: (code: Integer, message: String, version: String, headers: Hash[String, Array], body: String) -> Soren::Response



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/soren/response.rb', line 51

def from_parts(code:, message:, version:, headers:, body:)
  new({
        status_line: {
          version: Types::Response::Version.new("HTTP/#{version}"),
          code:    Types::Response::Code.new(code),
          message: Types::Response::Message.new(message),
        },
        headers:     Types::Response::Headers.new(headers),
        body:        Types::Response::Body.new(body),
      })
end

Instance Method Details

#bodyObject

: -> String



45
46
47
# File 'lib/soren/response.rb', line 45

def body
  @body.to_s
end

#codeObject

: -> Integer



25
26
27
# File 'lib/soren/response.rb', line 25

def code
  @code.to_i
end

#headersObject

: -> Hash[String, Array]



40
41
42
# File 'lib/soren/response.rb', line 40

def headers
  @headers.to_h
end

#messageObject

: -> String



30
31
32
# File 'lib/soren/response.rb', line 30

def message
  @message.to_s
end

#versionObject

: -> String



35
36
37
# File 'lib/soren/response.rb', line 35

def version
  @version.to_s
end