Sha256: c5cdc7118a7149d0ad6285831ac759ef359ee9b82ce3209f4dc7f8fd77a03e4c

Contents?: true

Size: 978 Bytes

Versions: 9

Compression:

Stored size: 978 Bytes

Contents

require 'active_support/inflector'

class HyperionResult
  attr_reader :route, :status, :code, :body

  # @param route [RestRoute]
  # @param status [HyperionStatus]
  # @param code [Integer] the HTTP response code
  # @param body [Object, Hash<String,Object>] the deserialized response body.
  #   The type is determined by the content-type.
  #   JSON is deserialized to a Hash<String, Object>
  def initialize(route, status, code=nil, body=nil)
    @route, @status, @code, @body = route, status, code, body
  end

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

  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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyperion_http-0.6.0 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.5.0 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.3.0 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.2.4 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.2.3 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.2.2 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.2.1 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.1.9 lib/hyperion/types/hyperion_result.rb
hyperion_http-0.1.8 lib/hyperion/types/hyperion_result.rb