Class: Napster::Models::Favorite
- Inherits:
-
Object
- Object
- Napster::Models::Favorite
- Defined in:
- lib/napster/models/favorite.rb
Overview
Favorite model
Constant Summary collapse
- ATTRIBUTES =
[:type, :id, :name, :modified, :href, :privacy, :images, :description, :favorite_count, :free_play_compliant].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #add(ids) ⇒ Object
-
#get(params) ⇒ Object
/me.
-
#initialize(arg) ⇒ Favorite
constructor
A new instance of Favorite.
- #member_favorites_for(id) ⇒ Object
-
#members_who_favorited_albums(id) ⇒ Object
Top level methods.
- #members_who_favorited_artists(id) ⇒ Object
- #remove(id) ⇒ Object
- #status(ids) ⇒ Object
Constructor Details
#initialize(arg) ⇒ Favorite
Returns a new instance of Favorite.
24 25 26 27 28 29 30 31 |
# File 'lib/napster/models/favorite.rb', line 24 def initialize(arg) @client = arg[:client] if arg[:client] return unless arg[:data] ATTRIBUTES.each do |attribute| send("#{attribute}=", arg[:data][attribute.to_s.camel_case_lower]) end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
22 23 24 |
# File 'lib/napster/models/favorite.rb', line 22 def client @client end |
Class Method Details
Instance Method Details
#add(ids) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/napster/models/favorite.rb', line 89 def add(ids) = { headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } body = prepare_add_favorites_body(ids) @client.post('/me/favorites', Oj.dump(body), ) status(ids) end |
#get(params) ⇒ Object
/me
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/napster/models/favorite.rb', line 61 def get(params) = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get('/me/favorites', ) Favorite.collection(data: response['favorites'], client: @client) end |
#member_favorites_for(id) ⇒ Object
55 56 57 |
# File 'lib/napster/models/favorite.rb', line 55 def member_favorites_for(id) request_member_favorites(id) end |
#members_who_favorited_albums(id) ⇒ Object
Top level methods
41 42 43 44 45 46 |
# File 'lib/napster/models/favorite.rb', line 41 def members_who_favorited_albums(id) e = 'Invalid playlist id' raise ArgumentError, e unless Napster::Moniker.check(id, :album) response = @client.get("/albums/#{id}/favorited/members") Member.collection(data: response['members'], client: @client) end |
#members_who_favorited_artists(id) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/napster/models/favorite.rb', line 48 def members_who_favorited_artists(id) e = 'Invalid playlist id' raise ArgumentError, e unless Napster::Moniker.check(id, :artist) response = @client.get("/artists/#{id}/favorited/members") Member.collection(data: response['members'], client: @client) end |
#remove(id) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/napster/models/favorite.rb', line 102 def remove(id) = { headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } @client.delete("/me/favorites/#{id}", ) status([id]) end |
#status(ids) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/napster/models/favorite.rb', line 74 def status(ids) = { params: { ids: ids }, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get('/me/favorites/status', ) FavoriteStatus.collection(data: response['status'], client: @client) end |