Class: Napster::Models::Profile
- Inherits:
-
Object
- Object
- Napster::Models::Profile
- Defined in:
- lib/napster/models/profile.rb
Overview
Profile model
Constant Summary collapse
- ATTRIBUTES =
[:id, :real_name, :screen_name, :bio, :location, :gender, :visibility, :type, :href, :favorite_albums_count, :favorite_artists_count, :favorite_tracks_count, :playlists_total_count, :playlists_published_count, :stations_count, :radio_count, :follower_count, :following_count, :avatar, :avatar_id, :default_avatar, :avatar_version, :links].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(arg) ⇒ Profile
constructor
A new instance of Profile.
- #update(body) ⇒ Object
Constructor Details
#initialize(arg) ⇒ Profile
Returns a new instance of Profile.
37 38 39 40 41 42 43 |
# File 'lib/napster/models/profile.rb', line 37 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.
35 36 37 |
# File 'lib/napster/models/profile.rb', line 35 def client @client end |
Class Method Details
Instance Method Details
#get ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/napster/models/profile.rb', line 51 def get = { headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get('/me', ) Profile.new(data: response['me'], client: @client) end |
#update(body) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/napster/models/profile.rb', line 63 def update(body) = { headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } @client.put('/me', Oj.dump(body), ) end |