Module: SimpleSpotify::Actions::Users

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

Instance Method Summary collapse

Instance Method Details

#meObject



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

def me
  Model::User.new (get :me).body
end

#user(id) ⇒ Object



10
11
12
# File 'lib/simplespotify/actions/users.rb', line 10

def user id
  Model::User.new (get "user/#{id}").body
end

#user_follow(type, ids) ⇒ Object


Follows




18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/simplespotify/actions/users.rb', line 18

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

  req = SimpleSpotify::Request.new("me/following", {
    json: true,
    query: {type: type},
    data: {ids: ids},
    method: :put
  })

  put req
end

#user_following(type, ids) ⇒ Object



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

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

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

#user_unfollow(type, ids) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/simplespotify/actions/users.rb', line 36

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

  req = SimpleSpotify::Request.new("me/following", {
    json: true,
    query: {type: type},
    data: {ids: ids},
    method: :delete
  })

  delete req
end