Module: OfficialFM::Playlists
- Included in:
- Client
- Defined in:
- lib/officialfm/playlists.rb
Instance Method Summary collapse
- #improve(playlist) ⇒ Object
-
#playlist(playlist_id, options = {}) ⇒ Hashie::Mash
Retrieve information about a specific playlist.
-
#playlist_create!(name, track_id) ⇒ Hashie::Mash
Create a playlist.
-
#playlist_picture!(playlist_id, path, mime) ⇒ Hashie::Mash
Upload a picture for a given playlist.
-
#playlist_remove!(playlist_id) ⇒ Hashie::Mash
Remove a playlist.
-
#playlist_unvote!(playlist_id) ⇒ Hashie::Mash
Remote vote for a playlist.
-
#playlist_vote!(playlist_id) ⇒ Hashie::Mash
Vote for a playlist.
-
#playlist_votes(playlist_id, options = {}) ⇒ Hashie::Mash
Retrieve users that have voted for this playlist.
-
#playlists(search_param, options = {}) ⇒ Hashie::Mash
Search for playlists.
-
#update_playlist!(playlist_id, data = {}) ⇒ Hashie::Mash
Update information of a given playlist.
Instance Method Details
#improve(playlist) ⇒ Object
43 44 45 46 47 |
# File 'lib/officialfm/playlists.rb', line 43 def improve(playlist) # the length field is already used. Note: running_time is in seconds playlist.running_time = playlist["length"] playlist end |
#playlist(playlist_id, options = {}) ⇒ Hashie::Mash
Retrieve information about a specific playlist
24 25 26 27 28 29 |
# File 'lib/officialfm/playlists.rb', line 24 def playlist(playlist_id, ={}) response = connection.get do |req| req.url "/playlist/#{playlist_id}", simple_params() end improve(response.body[0]) end |
#playlist_create!(name, track_id) ⇒ Hashie::Mash
Create a playlist
106 107 108 109 110 111 112 113 114 |
# File 'lib/officialfm/playlists.rb', line 106 def playlist_create! (name, track_id) check_auth :playlist_create response = connection.post do |req| req.url "/playlist/create" req.body = { :format => @format, :name => name, :track_id => track_id } end response end |
#playlist_picture!(playlist_id, path, mime) ⇒ Hashie::Mash
Upload a picture for a given playlist
77 78 79 80 81 82 83 84 85 |
# File 'lib/officialfm/playlists.rb', line 77 def playlist_picture! (playlist_id, path, mime) check_auth :playlist_picture response = connection.post do |req| req.url "/playlist/picture/#{playlist_id}" req.body = { :file => Faraday::UploadIO.new(path, mime), :format => @format } end response end |
#playlist_remove!(playlist_id) ⇒ Hashie::Mash
Remove a playlist
91 92 93 94 95 96 97 98 99 |
# File 'lib/officialfm/playlists.rb', line 91 def playlist_remove! (playlist_id) check_auth :playlist_remove response = connection.delete do |req| req.url "/playlist/remove/#{playlist_id}" req.body = { :format => @format } end response end |
#playlist_unvote!(playlist_id) ⇒ Hashie::Mash
Remote vote for a playlist
134 135 136 137 138 139 140 141 142 |
# File 'lib/officialfm/playlists.rb', line 134 def playlist_unvote! (playlist_id) check_auth :playlist_unvote response = connection.post do |req| req.url "/playlist/unvote/#{playlist_id}" req.body = { :format => @format } end response end |
#playlist_vote!(playlist_id) ⇒ Hashie::Mash
Vote for a playlist
120 121 122 123 124 125 126 127 128 |
# File 'lib/officialfm/playlists.rb', line 120 def playlist_vote! (playlist_id) check_auth :playlist_vote response = connection.post do |req| req.url "/playlist/vote/#{playlist_id}" req.body = { :format => @format } end response end |
#playlist_votes(playlist_id, options = {}) ⇒ Hashie::Mash
Retrieve users that have voted for this playlist
36 37 38 39 40 41 |
# File 'lib/officialfm/playlists.rb', line 36 def playlist_votes(playlist_id, ={}) response = connection.get do |req| req.url "/playlist/#{playlist_id}/votes", simple_params() end response.body end |
#playlists(search_param, options = {}) ⇒ Hashie::Mash
Search for playlists
11 12 13 14 15 16 17 |
# File 'lib/officialfm/playlists.rb', line 11 def playlists(search_param, ={}) response = connection.get do |req| req.url "/search/playlists/#{CGI::escape(search_param)}", simple_params() end response.body.map do |pl| improve(pl) end end |
#update_playlist!(playlist_id, data = {}) ⇒ Hashie::Mash
Update information of a given playlist
61 62 63 64 65 66 67 68 69 |
# File 'lib/officialfm/playlists.rb', line 61 def update_playlist! (playlist_id, data = {}) check_auth :update_playlist response = connection.put do |req| req.url "/playlist/update/#{playlist_id}", data req.body = { :format => @format } end response end |