Class: K8y::REST::ResponseFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/k8y/rest/response_formatter.rb

Constant Summary collapse

UnsupportedResponseTypeError =
Class.new(Error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseFormatter

Returns a new instance of ResponseFormatter.



10
11
12
# File 'lib/k8y/rest/response_formatter.rb', line 10

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/k8y/rest/response_formatter.rb', line 8

def response
  @response
end

Instance Method Details

#format(as: :ros) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/k8y/rest/response_formatter.rb', line 14

def format(as: :ros)
  case as
  when :ros
    build_k8y_resource_response(response.body)
  when :raw
    response
  else
    raise UnsupportedResponseTypeError, as.to_s
  end
end