Class: HyperionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperion/types/hyperion_result.rb

Direct Known Subclasses

Hyperion::DispatchingHyperionResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route, status, code = nil, body = nil) ⇒ HyperionResult

Returns a new instance of HyperionResult.

Parameters:

  • route (RestRoute)
  • status (HyperionStatus)
  • code (Integer) (defaults to: nil)

    the HTTP response code

  • body (Object, Hash<String,Object>) (defaults to: nil)

    the deserialized response body. The type is determined by the content-type. JSON is deserialized to a Hash<String, Object>



12
13
14
# File 'lib/hyperion/types/hyperion_result.rb', line 12

def initialize(route, status, code=nil, body=nil)
  @route, @status, @code, @body = route, status, code, body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/hyperion/types/hyperion_result.rb', line 4

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/hyperion/types/hyperion_result.rb', line 4

def code
  @code
end

#routeObject (readonly)

Returns the value of attribute route.



4
5
6
# File 'lib/hyperion/types/hyperion_result.rb', line 4

def route
  @route
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/hyperion/types/hyperion_result.rb', line 4

def status
  @status
end

Instance Method Details

#as_json(*_args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/hyperion/types/hyperion_result.rb', line 16

def as_json(*_args)
  {
      'route' => route.as_json(*_args),
      'status' => status.value,
      'code' => code,
      'body' => body.as_json(*_args),
  }
end

#to_sObject



25
26
27
28
29
30
31
32
33
# File 'lib/hyperion/types/hyperion_result.rb', line 25

def to_s
  if status == HyperionStatus::CHECK_CODE
    "HTTP #{code}: #{route.to_s}"
  elsif status == HyperionStatus::BAD_ROUTE
    "#{status.value.to_s.humanize} (#{code}): #{route.to_s}"
  else
    "#{status.value.to_s.humanize}: #{route.to_s}"
  end
end