Class: Napster::Models::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/napster/models/library.rb

Overview

Library model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Library

Returns a new instance of Library.



9
10
11
# File 'lib/napster/models/library.rb', line 9

def initialize(arg)
  @client = arg[:client] if arg[:client]
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/napster/models/library.rb', line 7

def client
  @client
end

Instance Method Details

#add_track(tracks) ⇒ Object

Raises:

  • (ArgumentError)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/napster/models/library.rb', line 94

def add_track(tracks)
  e = 'tracks argument should be an array.'
  raise ArgumentError, e unless tracks.class == Array

  tracks = tracks.join(',')
  options = {
    params: { id: tracks },
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  @client.post('/me/library/tracks', '{}', options)
end

#album_tracks(album_id, params) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/napster/models/library.rb', line 67

def album_tracks(album_id, params)
  path = "/me/library/albums/#{album_id}/tracks"
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get(path, get_options)
  Track.collection(data: response['tracks'], client: @client)
end

#albums(params) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/napster/models/library.rb', line 54

def albums(params)
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get('/me/library/albums', get_options)
  Album.collection(data: response['albums'], client: @client)
end

#artist_albums(artist_id, params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/napster/models/library.rb', line 26

def artist_albums(artist_id, params)
  path = "/me/library/artists/#{artist_id}/albums"
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get(path, get_options)
  Album.collection(data: response['albums'], client: @client)
end

#artist_tracks(artist_id, params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/napster/models/library.rb', line 40

def artist_tracks(artist_id, params)
  path = "/me/library/artists/#{artist_id}/tracks"
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get(path, get_options)
  Track.collection(data: response['tracks'], client: @client)
end

#artists(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/napster/models/library.rb', line 13

def artists(params)
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get('/me/library/artists', get_options)
  Artist.collection(data: response['artists'], client: @client)
end

#last_updated_dateObject



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/napster/models/library.rb', line 122

def last_updated_date
  path = '/me/library/updated'
  options = {
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get(path, options)
  LibraryDateTime.new(data: response['lastUpdateDate'], client: @client)
end

#remove_track(track_id) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/napster/models/library.rb', line 110

def remove_track(track_id)
  path = "/me/library/tracks/#{track_id}"
  options = {
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  @client.delete(path, options)
end

#tracks(params) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/napster/models/library.rb', line 81

def tracks(params)
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get('/me/library/tracks', get_options)
  Track.collection(data: response['tracks'], client: @client)
end