Class: GeniusReferrals::Page

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#limitObject

Returns the value of attribute limit

Returns:

  • (Object)

    the current value of limit



13
14
15
# File 'lib/genius_referrals/response.rb', line 13

def limit
  @limit
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page



13
14
15
# File 'lib/genius_referrals/response.rb', line 13

def page
  @page
end

#rawObject

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



13
14
15
# File 'lib/genius_referrals/response.rb', line 13

def raw
  @raw
end

#resultsObject

Returns the value of attribute results

Returns:

  • (Object)

    the current value of results



13
14
15
# File 'lib/genius_referrals/response.rb', line 13

def results
  @results
end

#totalObject

Returns the value of attribute total

Returns:

  • (Object)

    the current value of total



13
14
15
# File 'lib/genius_referrals/response.rb', line 13

def total
  @total
end

Class Method Details

.from_api(payload) ⇒ Object

Build a pagination wrapper from the standard list response shape.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/genius_referrals/response.rb', line 15

def self.from_api(payload)
  envelope = APIResponse.from_api(payload)
  data = envelope.data

  if data.is_a?(Hash)
    new(
      results: data['results'] || [],
      page: data['page'],
      limit: data['limit'],
      total: data['total'],
      raw: payload
    )
  elsif data.is_a?(Array)
    new(results: data, page: nil, limit: nil, total: nil, raw: payload)
  else
    new(results: [], page: nil, limit: nil, total: nil, raw: payload)
  end
end