Module: SimpleSpotify::Actions::Tracks

Defined in:
lib/simplespotify/actions/tracks.rb

Instance Method Summary collapse

Instance Method Details

#remove_tracks(ids) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/simplespotify/actions/tracks.rb', line 54

def remove_tracks ids
  if ids.is_a? Array
    ids.map { |i|
      i.is_a?(Resource) ? i.id : i;
    }.join(',')
  end

  delete "me/tracks", {ids: ids}
end

#save_tracks(ids) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/simplespotify/actions/tracks.rb', line 43

def save_tracks ids
  if ids.is_a? Array
    ids.map { |i|
      i.is_a?(Resource) ? i.id : i;
    }.join(',')
  end

  put "me/tracks", {ids: ids}
end

#saved_tracks(limit: 20, offset: 0, market: nil) ⇒ Object


Saved tracks




25
26
27
28
# File 'lib/simplespotify/actions/tracks.rb', line 25

def saved_tracks limit: 20, offset: 0, market: nil
  response = get "me/tracks", options_with_market(market, {limit: limit, offset: offset})
  Model::Collection.of(Model::PlaylistTrack, response.body)
end

#saved_tracks_include?(ids) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'lib/simplespotify/actions/tracks.rb', line 31

def saved_tracks_include? ids
  if ids.is_a? Array
    ids.map { |i|
      i.is_a?(Resource) ? i.id : i;
    }.join(',')
  end

  res = get "me/tracks/contains", {ids: ids}
  ids.zip(res.body).to_h
end

#track(id, market: nil) ⇒ Object



5
6
7
8
# File 'lib/simplespotify/actions/tracks.rb', line 5

def track id, market: nil
  res = get "tracks/#{id_for(id)}", options_with_market(market)
  Model::Track.new(res.body)
end

#tracks(ids, market: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/simplespotify/actions/tracks.rb', line 11

def tracks ids, market: nil
  if ids.is_a? Array
    ids.map { |i|
      id_for(i)
    }.join(',')
  end

  Model::Collection.of(:tracks, response.body)
end