Module: OfficialFM::Tracks

Included in:
Client
Defined in:
lib/officialfm/tracks.rb

Instance Method Summary collapse

Instance Method Details

#add_track_to_playlist!(track_id, playlist_id) ⇒ Hashie::Mash

Add a track to a playlist

Parameters:

  • track_id: (String)

    id

  • playlist_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • charting: (String)

    :today, :week, :month, :year or :all_time

  • genre: (String)

    Genre string (Electronic, Rock, Jazz, …) (optional)

  • country: (String)

    ISO country id (CH, FR, UK) (optional)

  • embed (Bool)

    (false) should embed codes be included in the response (optional)

  • limit (Integer)

    (200) limit per page (optional)

Returns:

  • (Hashie::Mash)

    Track list



53
54
55
56
57
58
# File 'lib/officialfm/tracks.rb', line 53

def charts(charting, options={})
  response = connection.get do |req|
    req.url "/tracks/charts", simple_params(options)
  end
  response.body
end

#latest(options = {}) ⇒ Hashie::Mash

Retrieve 200 latest tracks

Parameters:

  • genre: (String)

    Genre string (Electronic, Rock, Jazz, …) (optional)

  • country: (String)

    ISO country id (CH, FR, UK) (optional)

  • embed (Bool)

    (false) should embed codes be included in the response (optional)

  • limit (Integer)

    (200) limit per page (optional)

Returns:

  • (Hashie::Mash)

    Track list



67
68
69
70
71
72
# File 'lib/officialfm/tracks.rb', line 67

def latest(options={})
  response = connection.get do |req|
    req.url "/tracks/latest", simple_params(options)
  end
  response.body
end

#remove_track_from_playlist!(track_id, playlist_id) ⇒ Hashie::Mash

Remove a track from a playlist

Parameters:

  • track_id: (String)

    id

  • playlist_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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.

Parameters:

  • track_id: (String)

    id

  • embed (Bool)

    (false) should embed codes be included in the response

Returns:

  • (Hashie::Mash)

    Track



26
27
28
29
30
31
# File 'lib/officialfm/tracks.rb', line 26

def track(track_id, options={})
  response = connection.get do |req|
    req.url "/track/#{track_id}", simple_params(options)
  end
  response.body[0]
end

#track_picture!(track_id, path, mime) ⇒ Hashie::Mash

Upload a picture for a given track

Parameters:

  • track_id: (String)

    id

  • path: (String)

    path to a picture

  • mime: (String)

    the mime-type of the picture (e.g. image/jpeg, image/png, etc.)

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • track_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • track_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • track_id: (String)

    id

  • limit (Integer)

    (50) limit per page

Returns:

  • (Hashie::Mash)

    User list



38
39
40
41
42
43
# File 'lib/officialfm/tracks.rb', line 38

def track_votes(track_id, options={})
  response = connection.get do |req|
    req.url "/track/#{track_id}/votes", simple_params(options)
  end
  response.body
end

#tracks(search_param, options = {}) ⇒ Hashie::Mash

Search for tracks

Parameters:

  • search_param: (String)

    a search parameter (eg. name of the track)

  • limit (Integer)

    (50) limit per page (optional)

Returns:

  • (Hashie::Mash)

    Track list



11
12
13
14
15
16
# File 'lib/officialfm/tracks.rb', line 11

def tracks(search_param, options={})
  response = connection.get do |req|
    req.url "/search/tracks/#{CGI::escape(search_param)}", simple_params(options)
  end
  response.body
end

#update_track!(track_id, data = {}) ⇒ Hashie::Mash

Update information of a given track

Parameters:

  • track_id: (String)

    id

  • artist_name (String)

    (optional)

  • buy_url (String)

    (optional)

  • country_id (String)

    (optional)

  • downloadable (String)

    (optional)

  • derived_by (String)

    (optional)

  • derived_type (String)

    (optional)

  • description (String)

    (optional)

  • isrc (String)

    (optional)

  • label_name (String)

    (optional)

  • label_none (String)

    (optional)

  • license_type (String)

    (optional)

  • lyrics (String)

    (optional)

  • genre_string (String)

    (optional)

  • original_track_id (String)

    (optional)

  • password (String)

    (optional)

  • pr_url (String)

    (optional)

  • private (String)

    (optional)

  • require_valid_email (String)

    (optional)

  • tag_string (String)

    (optional)

  • title (String)

    (optional)

  • url_1_name (String)

    (optional)

  • url_1 (String)

    (optional)

  • url_2_name (String)

    (optional)

  • url_2 (String)

    (optional)

  • web_url (String)

    (optional)

Returns:

  • (Hashie::Mash)

    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

Parameters:

  • path: (String)

    path to an mp3, 44.1Khz file

  • mime: (String)

    the mime-type of the file (e.g. audio/mpeg, etc.)

Returns:

  • (Hashie::Mash)

    Track



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