Module: OfficialFM::Tracks
- Included in:
- Client
- Defined in:
- lib/officialfm/tracks.rb
Instance Method Summary collapse
-
#add_track_to_playlist!(track_id, playlist_id) ⇒ Hashie::Mash
Add a track to a playlist.
-
#charts(charting, options = {}) ⇒ Hashie::Mash
Retrieve 200 tracks of selected chart.
-
#latest(options = {}) ⇒ Hashie::Mash
Retrieve 200 latest tracks.
-
#remove_track_from_playlist!(track_id, playlist_id) ⇒ Hashie::Mash
Remove a track from a playlist.
-
#track(track_id, options = {}) ⇒ Hashie::Mash
Retrieve information about a specific track.
-
#track_picture!(track_id, path, mime) ⇒ Hashie::Mash
Upload a picture for a given track.
-
#track_unvote!(track_id) ⇒ Hashie::Mash
Remove vote for a track.
-
#track_vote!(track_id) ⇒ Hashie::Mash
Vote for a track.
-
#track_votes(track_id, options = {}) ⇒ Hashie::Mash
Retrieve users that have voted for this track.
-
#tracks(search_param, options = {}) ⇒ Hashie::Mash
Search for tracks.
-
#update_track!(track_id, data = {}) ⇒ Hashie::Mash
Update information of a given track.
-
#upload!(path, mime) ⇒ Hashie::Mash
Upload a new track to Official.fm.
Instance Method Details
#add_track_to_playlist!(track_id, playlist_id) ⇒ Hashie::Mash
Add a track to a playlist
166 167 168 169 170 171 172 173 174 |
# File 'lib/officialfm/tracks.rb', line 166 def add_track_to_playlist! (track_id, playlist_id) check_auth :add_track_to_playlist! response = connection.post do |req| req.url "/track/#{track_id}/addto/#{playlist_id}" req.body = { :format => @format } end response end |
#charts(charting, options = {}) ⇒ Hashie::Mash
Retrieve 200 tracks of selected chart
53 54 55 56 57 58 |
# File 'lib/officialfm/tracks.rb', line 53 def charts(charting, ={}) response = connection.get do |req| req.url "/tracks/charts", simple_params() end response.body end |
#latest(options = {}) ⇒ Hashie::Mash
Retrieve 200 latest tracks
67 68 69 70 71 72 |
# File 'lib/officialfm/tracks.rb', line 67 def latest(={}) response = connection.get do |req| req.url "/tracks/latest", simple_params() end response.body end |
#remove_track_from_playlist!(track_id, playlist_id) ⇒ Hashie::Mash
Remove a track from a playlist
181 182 183 184 185 186 187 188 189 |
# File 'lib/officialfm/tracks.rb', line 181 def remove_track_from_playlist! (track_id, playlist_id) check_auth :remove_track_from_playlist! response = connection.delete do |req| req.url "/track/#{track_id}/removefrom/#{playlist_id}" req.body = { :format => @format } end response end |
#track(track_id, options = {}) ⇒ Hashie::Mash
Retrieve information about a specific track
Note: official.fm/developers/simple_api#track_show says that api_max_responses is a valid parameter. Why escapes me.
26 27 28 29 30 31 |
# File 'lib/officialfm/tracks.rb', line 26 def track(track_id, ={}) response = connection.get do |req| req.url "/track/#{track_id}", simple_params() end response.body[0] end |
#track_picture!(track_id, path, mime) ⇒ Hashie::Mash
Upload a picture for a given track
123 124 125 126 127 128 129 130 131 |
# File 'lib/officialfm/tracks.rb', line 123 def track_picture! (track_id, path, mime) check_auth :track_picture response = connection.post do |req| req.url "/track/picture/#{track_id}" req.body = { :file => Faraday::UploadIO.new(path, mime), :format => @format } end response end |
#track_unvote!(track_id) ⇒ Hashie::Mash
Remove vote for a track
151 152 153 154 155 156 157 158 159 |
# File 'lib/officialfm/tracks.rb', line 151 def track_unvote! (track_id) check_auth :track_unvote response = connection.post do |req| req.url "/track/unvote/#{track_id}" req.body = { :format => @format } end response end |
#track_vote!(track_id) ⇒ Hashie::Mash
Vote for a track
137 138 139 140 141 142 143 144 145 |
# File 'lib/officialfm/tracks.rb', line 137 def track_vote! (track_id) check_auth :track_vote response = connection.post do |req| req.url "/track/vote/#{track_id}" req.body = { :format => @format } end response end |
#track_votes(track_id, options = {}) ⇒ Hashie::Mash
Retrieve users that have voted for this track
38 39 40 41 42 43 |
# File 'lib/officialfm/tracks.rb', line 38 def track_votes(track_id, ={}) response = connection.get do |req| req.url "/track/#{track_id}/votes", simple_params() end response.body end |
#tracks(search_param, options = {}) ⇒ Hashie::Mash
Search for tracks
11 12 13 14 15 16 |
# File 'lib/officialfm/tracks.rb', line 11 def tracks(search_param, ={}) response = connection.get do |req| req.url "/search/tracks/#{CGI::escape(search_param)}", simple_params() end response.body end |
#update_track!(track_id, data = {}) ⇒ Hashie::Mash
Update information of a given track
107 108 109 110 111 112 113 114 115 |
# File 'lib/officialfm/tracks.rb', line 107 def update_track! (track_id, data = {}) check_auth :update_track response = connection.put do |req| req.url "/track/update/#{track_id}", data req.body = { :format => @format } end response end |
#upload!(path, mime) ⇒ Hashie::Mash
Upload a new track to Official.fm
196 197 198 199 200 201 202 203 204 |
# File 'lib/officialfm/tracks.rb', line 196 def upload! (path, mime) check_auth :upload response = connection.post do |req| req.url "/track/upload" req.body = { :file => Faraday::UploadIO.new(path, mime), :format => @format } end response end |