Class: Unit::UnitResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/models/unit_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, included, meta) ⇒ UnitResponse

Returns a new instance of UnitResponse.

Parameters:

  • data (Hash)

    The JSON API payload

  • included (Array)

    The JSON API payload



10
11
12
13
14
# File 'lib/unit/models/unit_response.rb', line 10

def initialize(data, included, meta)
  @data = data
  @included = included
  @meta = meta
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/unit/models/unit_response.rb', line 6

def data
  @data
end

#includedObject (readonly)

Returns the value of attribute included.



6
7
8
# File 'lib/unit/models/unit_response.rb', line 6

def included
  @included
end

#metaObject (readonly)

Returns the value of attribute meta.



6
7
8
# File 'lib/unit/models/unit_response.rb', line 6

def meta
  @meta
end

Class Method Details

.from_json_api(response) ⇒ UnitResponse

Creates a new UnitResponse from given response.

Parameters:

  • response (HTTP::Response)

    The response returned from Unit’s API

Returns:

  • (UnitResponse)

    a new UnitResponse populated with values taken from the response



19
20
21
# File 'lib/unit/models/unit_response.rb', line 19

def self.from_json_api(response)
  new(response.body["data"], response.body["included"], response.body["meta"])
end