Class: Rockbox::Api::SmartPlaylists
- Inherits:
-
Object
- Object
- Rockbox::Api::SmartPlaylists
- Defined in:
- lib/rockbox/api/smart_playlists.rb
Instance Method Summary collapse
- #create(name:, rules:, description: nil, image: nil, folder_id: nil) ⇒ Object
- #delete(id) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(http) ⇒ SmartPlaylists
constructor
A new instance of SmartPlaylists.
- #list ⇒ Object
- #play(id) ⇒ Object
- #record_played(track_id) ⇒ Object
- #record_skipped(track_id) ⇒ Object
- #track_ids(id) ⇒ Object
-
#track_stats(track_id) ⇒ Object
——————————————————————— Listening stats ———————————————————————.
- #update(id, name:, rules:, description: nil, image: nil, folder_id: nil) ⇒ Object
Constructor Details
#initialize(http) ⇒ SmartPlaylists
Returns a new instance of SmartPlaylists.
8 9 10 |
# File 'lib/rockbox/api/smart_playlists.rb', line 8 def initialize(http) @http = http end |
Instance Method Details
#create(name:, rules:, description: nil, image: nil, folder_id: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rockbox/api/smart_playlists.rb', line 39 def create(name:, rules:, description: nil, image: nil, folder_id: nil) vars = { name: name, rules: rules, description: description, image: image, folder_id: folder_id }.compact data = @http.execute(<<~GQL, vars) mutation CreateSmartPlaylist( $name: String!, $rules: String!, $description: String, $image: String, $folderId: String ) { createSmartPlaylist( name: $name, rules: $rules, description: $description, image: $image, folderId: $folderId ) { id name description image folderId isSystem rules createdAt updatedAt } } GQL SmartPlaylist.from_hash(data[:create_smart_playlist]) end |
#delete(id) ⇒ Object
73 74 75 76 |
# File 'lib/rockbox/api/smart_playlists.rb', line 73 def delete(id) @http.execute("mutation DeleteSmartPlaylist($id: String!) { deleteSmartPlaylist(id: $id) }", { id: id }) nil end |
#get(id) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/rockbox/api/smart_playlists.rb', line 21 def get(id) data = @http.execute( "query SmartPlaylist($id: String!) { " \ "smartPlaylist(id: $id) { id name description image folderId isSystem rules createdAt updatedAt } }", { id: id } ) SmartPlaylist.from_hash(data[:smart_playlist]) end |
#list ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rockbox/api/smart_playlists.rb', line 12 def list data = @http.execute(<<~GQL) query SmartPlaylists { smartPlaylists { id name description image folderId isSystem rules createdAt updatedAt } } GQL Array(data[:smart_playlists]).map { |p| SmartPlaylist.from_hash(p) } end |
#play(id) ⇒ Object
78 79 80 81 |
# File 'lib/rockbox/api/smart_playlists.rb', line 78 def play(id) @http.execute("mutation PlaySmartPlaylist($id: String!) { playSmartPlaylist(id: $id) }", { id: id }) nil end |
#record_played(track_id) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/rockbox/api/smart_playlists.rb', line 98 def record_played(track_id) @http.execute( "mutation RecordTrackPlayed($trackId: String!) { recordTrackPlayed(trackId: $trackId) }", { track_id: track_id } ) nil end |
#record_skipped(track_id) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/rockbox/api/smart_playlists.rb', line 106 def record_skipped(track_id) @http.execute( "mutation RecordTrackSkipped($trackId: String!) { recordTrackSkipped(trackId: $trackId) }", { track_id: track_id } ) nil end |
#track_ids(id) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rockbox/api/smart_playlists.rb', line 30 def track_ids(id) @http.execute( "query SmartPlaylistTrackIds($id: String!) { smartPlaylistTrackIds(id: $id) }", { id: id } )[:smart_playlist_track_ids] || [] end |
#track_stats(track_id) ⇒ Object
Listening stats
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rockbox/api/smart_playlists.rb', line 87 def track_stats(track_id) data = @http.execute(<<~GQL, { track_id: track_id }) query TrackStats($trackId: String!) { trackStats(trackId: $trackId) { trackId playCount skipCount lastPlayed lastSkipped updatedAt } } GQL TrackStats.from_hash(data[:track_stats]) end |
#update(id, name:, rules:, description: nil, image: nil, folder_id: nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rockbox/api/smart_playlists.rb', line 56 def update(id, name:, rules:, description: nil, image: nil, folder_id: nil) vars = { id: id, name: name, rules: rules, description: description, image: image, folder_id: folder_id }.compact @http.execute(<<~GQL, vars) mutation UpdateSmartPlaylist( $id: String!, $name: String!, $rules: String!, $description: String, $image: String, $folderId: String ) { updateSmartPlaylist( id: $id, name: $name, rules: $rules, description: $description, image: $image, folderId: $folderId ) } GQL nil end |