Class: GeniusReferrals::APIResponse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



2
3
4
# File 'lib/genius_referrals/response.rb', line 2

def code
  @code
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



2
3
4
# File 'lib/genius_referrals/response.rb', line 2

def data
  @data
end

#rawObject

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



2
3
4
# File 'lib/genius_referrals/response.rb', line 2

def raw
  @raw
end

Class Method Details

.from_api(payload) ⇒ Object

Build a response envelope from the public API {code, data} shape.



4
5
6
7
8
9
10
# File 'lib/genius_referrals/response.rb', line 4

def self.from_api(payload)
  if payload.is_a?(Hash) && payload.key?('code') && payload.key?('data')
    new(code: payload['code'], data: payload['data'], raw: payload)
  else
    new(code: nil, data: payload, raw: payload)
  end
end