Class: Deezify::API::Deezer
- Inherits:
-
Object
- Object
- Deezify::API::Deezer
- Defined in:
- lib/deezify/api/deezer.rb
Instance Method Summary collapse
- #add_tracks(playlist_id, *tracks) ⇒ Object
- #create_playlist(title) ⇒ Object
-
#initialize ⇒ Deezer
constructor
A new instance of Deezer.
- #search(query, params = {}) ⇒ Object
- #user_info ⇒ Object
Constructor Details
#initialize ⇒ Deezer
Returns a new instance of Deezer.
7 8 9 |
# File 'lib/deezify/api/deezer.rb', line 7 def initialize @connection = connection end |
Instance Method Details
#add_tracks(playlist_id, *tracks) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/deezify/api/deezer.rb', line 41 def add_tracks(playlist_id, *tracks) @connection.post do |req| req.url "/playlist/#{playlist_id}/tracks" req.params[:songs] = tracks.join ',' end end |
#create_playlist(title) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/deezify/api/deezer.rb', line 32 def create_playlist(title) res = @connection.post do |req| req.url '/user/me/playlists' req.params[:title] = title end json_decode res.body end |
#search(query, params = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deezify/api/deezer.rb', line 19 def search(query, params={}) unless params.empty? query = params.map{ |k, v| %Q(#{k}:"#{v}") }.join(' ') end res = @connection.get do |req| req.url '/search' req.params[:q] = query end json_decode(res.body)[:data] end |
#user_info ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/deezify/api/deezer.rb', line 11 def user_info res = @connection.get do |req| req.url '/user/me' end json_decode res.body end |