Class: YouTube::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/you_tube/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, total:, next_page_token:, prev_page_token:) ⇒ Collection

Returns a new instance of Collection.



17
18
19
20
21
22
# File 'lib/you_tube/collection.rb', line 17

def initialize(data:, total:, next_page_token:, prev_page_token:)
  @data = data
  @total = total
  @next_page_token = next_page_token
  @prev_page_token = prev_page_token
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/you_tube/collection.rb', line 3

def data
  @data
end

#next_page_tokenObject (readonly)

Returns the value of attribute next_page_token.



3
4
5
# File 'lib/you_tube/collection.rb', line 3

def next_page_token
  @next_page_token
end

#prev_page_tokenObject (readonly)

Returns the value of attribute prev_page_token.



3
4
5
# File 'lib/you_tube/collection.rb', line 3

def prev_page_token
  @prev_page_token
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/you_tube/collection.rb', line 3

def total
  @total
end

Class Method Details

.from_response(response, type:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/you_tube/collection.rb', line 5

def self.from_response(response, type:)
  body = response.body

  new(
    data: body["items"].map { |attrs| type.new(attrs) },
    total: body["items"].count,
    next_page_token: body["nextPageToken"],
    prev_page_token: body["prevPageToken"],
    # cursor: body.dig("pagination", "cursor")
  )
end