Class: Twitch::Response

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

Overview

A compiled response from the API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_class, res) ⇒ Response

Returns a new instance of Response.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/twitch/response.rb', line 34

def initialize(data_class, res)
  http_res = res[:http_res]
  @raw = http_res if res[:with_raw]

  @data = http_res.body['data'].map { |d| data_class.new(d) }

  rate_limit_headers = Hash[http_res.headers.select do |k,v|
    k.to_s.downcase.match(/^ratelimit/)
  end.map { |k,v| [k.gsub('ratelimit-', '').to_sym, v] }]

  @rate_limit = rate_limit_headers[:limit].to_i
  @rate_limit_remaining = rate_limit_headers[:remaining].to_i
  @rate_limit_resets_at = Time.at(rate_limit_headers[:reset].to_i)

  if rate_limit_headers.keys.any? { |k| k.to_s.start_with?('helixclipscreation') }
    @clip_rate_limit = rate_limit_headers[:'helixclipscreation-limit']
    @clip_rate_limit_remaining = rate_limit_headers[:'helixclipscreation-remaining']
  end

  @pagination = http_res.body['pagination']
  @total = http_res.body['total']
  @date_range = http_res.body['date_range']
end

Instance Attribute Details

#clip_rate_limitObject (readonly)

The total amount of clips that can be created in the clip rate limit period (currently unknown).



27
28
29
# File 'lib/twitch/response.rb', line 27

def clip_rate_limit
  @clip_rate_limit
end

#clip_rate_limit_remainingObject (readonly)

The remaining amount of clips that can be created in the clip rate limit period.



30
31
32
# File 'lib/twitch/response.rb', line 30

def clip_rate_limit_remaining
  @clip_rate_limit_remaining
end

#dataObject (readonly)

The requested data.



5
6
7
# File 'lib/twitch/response.rb', line 5

def data
  @data
end

#date_rangeObject (readonly)

A range of dates in which data is effective. Usually contains the keys start_date and end_date. Applies to select endpoints.



12
13
14
# File 'lib/twitch/response.rb', line 12

def date_range
  @date_range
end

#paginationObject (readonly)

A hash containing a pagination token. Access it with

pagination['cursor']

Applies to select endpoints.



17
18
19
# File 'lib/twitch/response.rb', line 17

def pagination
  @pagination
end

#rate_limitObject (readonly)

The total amount of calls that can be used in the rate limit period (one minute by default).



20
21
22
# File 'lib/twitch/response.rb', line 20

def rate_limit
  @rate_limit
end

#rate_limit_remainingObject (readonly)

The remaining amount of calls for the rate limit period.



22
23
24
# File 'lib/twitch/response.rb', line 22

def rate_limit_remaining
  @rate_limit_remaining
end

#rate_limit_resets_atObject (readonly)

The date at which the rate limit is reset.



24
25
26
# File 'lib/twitch/response.rb', line 24

def rate_limit_resets_at
  @rate_limit_resets_at
end

#rawObject (readonly)

The HTTP raw response



32
33
34
# File 'lib/twitch/response.rb', line 32

def raw
  @raw
end

#totalObject (readonly)

A total amount of entities. Applies to select endpoints.



8
9
10
# File 'lib/twitch/response.rb', line 8

def total
  @total
end