Module: OfficialFM::Playlists

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

Instance Method Summary collapse

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

Parameters:

  • track_id: (String)

    id

  • embed (Bool)

    (false) should embed codes be included in the response

Returns:

  • (Hashie::Mash)

    Playlist



24
25
26
27
28
29
# File 'lib/officialfm/playlists.rb', line 24

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

#playlist_create!(name, track_id) ⇒ Hashie::Mash

Create a playlist

Parameters:

  • name: (String)

    playlist name

  • track_id: (String)

    first track id of the new playlist

Returns:

  • (Hashie::Mash)

    Playlist object



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

Parameters:

  • playlist_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



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

Parameters:

  • playlist_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • playlist_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • playlist_id: (String)

    id

Returns:

  • (Hashie::Mash)

    Success or error message



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

Parameters:

  • playlist_id: (String)

    id

  • limit (Integer)

    (50) limit per page

Returns:

  • (Hashie::Mash)

    User list



36
37
38
39
40
41
# File 'lib/officialfm/playlists.rb', line 36

def playlist_votes(playlist_id, options={})
  response = connection.get do |req|
    req.url "/playlist/#{playlist_id}/votes", simple_params(options)
  end
  response.body
end

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

Search for playlists

Parameters:

  • search_param: (String)

    a search parameter (eg. name of the playlist)

  • limit (Integer)

    (50) limit per page (optional)

Returns:

  • (Hashie::Mash)

    Playlist list



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

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

#update_playlist!(playlist_id, data = {}) ⇒ Hashie::Mash

Update information of a given playlist

Parameters:

  • playlist_id: (String)

    id

  • description (String)

    (optional)

  • name (String)

    (optional)

  • password (String)

    (optional)

  • private (String)

    (optional)

Returns:

  • (Hashie::Mash)

    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