Class: Opushon::Response Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers: {}, body: {}) ⇒ Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Response.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
# File 'lib/opushon/response.rb', line 23

def initialize(headers: {}, body: {})
  raise ArgumentError, "headers #{headers.inspect}" unless headers.is_a?(Hash)
  raise ArgumentError, "body #{body.inspect}"       unless body.is_a?(Hash)

  @headers  = headers.map { |k, v| [k.to_sym, Parameter.load(v)] }.to_h
  @body     = body.map    { |k, v| [k.to_sym, Parameter.load(v)] }.to_h
end

Instance Attribute Details

#bodyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
# File 'lib/opushon/response.rb', line 21

def body
  @body
end

#headersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
# File 'lib/opushon/response.rb', line 21

def headers
  @headers
end

Class Method Details

.load(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/opushon/response.rb', line 7

def self.load(hash)
  raise ArgumentError, "hash #{hash.inspect}" unless hash.is_a?(Hash)

  headers = hash.fetch('headers', nil)
  body    = hash.fetch('body',    nil)

  hash = {
    headers:  headers,
    body:     body
  }.compact

  new(**hash)
end

Instance Method Details

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
36
# File 'lib/opushon/response.rb', line 31

def to_h
  {
    headers:  headers.map { |k, v| [k, v.to_h] }.to_h,
    body:     body.map    { |k, v| [k, v.to_h] }.to_h
  }
end