Class: YouTube::PlaylistsResource
- Defined in:
- lib/you_tube/resources/playlists.rb
Constant Summary collapse
- PARTS =
"id,snippet,status"
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(title:, **attributes) ⇒ Object
Creates a Playlist developers.google.com/youtube/v3/docs/playlists/insert.
-
#delete(id:) ⇒ Object
Deletes a Playlist developers.google.com/youtube/v3/docs/playlists/delete.
-
#list(channel_id: nil, page_token: nil, max_results: nil) ⇒ Object
Returns Playlists either for a Channel or owned by the authenticated user developers.google.com/youtube/v3/docs/playlists/list.
-
#retrieve(id:) ⇒ Object
Returns a Playlist for a given ID.
-
#update(id:, title:, **attributes) ⇒ Object
Updates a Playlist.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from YouTube::Resource
Instance Method Details
#create(title:, **attributes) ⇒ Object
Creates a Playlist developers.google.com/youtube/v3/docs/playlists/insert
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/you_tube/resources/playlists.rb', line 30 def create(title:, **attributes) attrs = {} attrs[:snippet] = {} attrs[:status] = {} attrs[:snippet][:title] = title attrs[:snippet][:description] = attributes[:description] attrs[:snippet][:defaultLanguage] = attributes[:default_language] attrs[:status][:privacyStatus] = attributes[:privacy_status] response = post_request("playlists?part=id,snippet,status", body: attrs) Playlist.new(response.body) if response.success? end |
#delete(id:) ⇒ Object
Deletes a Playlist developers.google.com/youtube/v3/docs/playlists/delete
69 70 71 |
# File 'lib/you_tube/resources/playlists.rb', line 69 def delete(id:) delete_request("playlists?id=#{id}") end |
#list(channel_id: nil, page_token: nil, max_results: nil) ⇒ Object
Returns Playlists either for a Channel or owned by the authenticated user developers.google.com/youtube/v3/docs/playlists/list
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/you_tube/resources/playlists.rb', line 8 def list(channel_id: nil, page_token: nil, max_results: nil) attrs = {} if channel_id attrs[:channelId] = channel_id else attrs[:mine] = true end attrs[:maxResults] = max_results if max_results attrs[:pageToken] = page_token if page_token response = get_request "playlists", params: attrs.merge({part: PARTS}) Collection.from_response(response, type: Playlist) end |
#retrieve(id:) ⇒ Object
Returns a Playlist for a given ID
23 24 25 26 |
# File 'lib/you_tube/resources/playlists.rb', line 23 def retrieve(id:) response = get_request "playlists", params: {id: id, part: PARTS} Playlist.new(response.body["items"][0]) end |
#update(id:, title:, **attributes) ⇒ Object
Updates a Playlist. ID and Title are required. developers.google.com/youtube/v3/docs/playlists/update
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/you_tube/resources/playlists.rb', line 49 def update(id:, title:, **attributes) attrs = {} attrs[:id] = id attrs[:snippet] = {} attrs[:status] = {} attrs[:snippet][:title] = title attrs[:snippet][:description] = attributes[:description] attrs[:snippet][:defaultLanguage] = attributes[:default_language] attrs[:status][:privacyStatus] = attributes[:privacy_status] response = put_request("playlists?part=id,snippet,status", body: attrs) Playlist.new(response.body) if response.success? end |