rspotify 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 143c29a98dc6fd1ddcea30f3652f0f90b76b20cf
4
- data.tar.gz: 37b43846b4ef02d85492c9c28a37e9508d927124
3
+ metadata.gz: 3821a59eda0417ad48c54dfedcb48f81e7b9a20d
4
+ data.tar.gz: c00df9a3e146bec3f253d6837295e7b2b1ee8291
5
5
  SHA512:
6
- metadata.gz: f2e541262d61bc8b5337a29c4a37cf2f19c204ace211767d19579ae936d4107e79ea6a6c7d80d70c6e75356d984388a339a7dfcd9611fedd5b65353363cb2db2
7
- data.tar.gz: 8e3fb4b604c933c1b86d3c0a20960350b766110cf81bc8a3b9b18b8959ed044b62356d29bd4e57594c5d12c90b9792a45f573982070ba80ec781141829b44416
6
+ metadata.gz: 639c192ff705248d9567659cbec7acfb799ed97c185810efb73fe380e64d5302894111bb0a79cc8a6567f0e22e87177663db1a5816dcd233eb70c388bba14771
7
+ data.tar.gz: 3331bbe544c3ca3ad49cdeb3802effc5c223c16d9345e354a161d165b8b77b16f66057a81b47247a89ad0424083ad922611afcad620702af16176208830a8771
data/README.md CHANGED
@@ -97,7 +97,7 @@ RSpotify focuses on objects behaviour so you can forget the API and worry about
97
97
 
98
98
  It is possible to write things like `playlist.tracks.sort_by(&:popularity).last.album` without having to think what API calls must be done. RSpotify fills the gaps for you.
99
99
 
100
- Full documentation can be found [here](http://rdoc.info/github/guilhermesad/rspotify/master/frames). (Will be complete in the next few days)
100
+ Full documentation can be found [here](http://rdoc.info/github/guilhermesad/rspotify/master/frames).
101
101
 
102
102
  ## Notes
103
103
 
@@ -1,11 +1,51 @@
1
1
  module RSpotify
2
2
 
3
+ # @attr [String] album_type The type of the album (album, single, compilation)
4
+ # @attr [Array<Artist>] artists The artists of the album
5
+ # @attr [Array<String>] available_markets The markets in which the album is available: {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country codes}
6
+ # @attr [Hash] external_ids Known external IDs for the album
7
+ # @attr [Array<String>] genres A list of the genres used to classify the album (If not yet classified, the array is empty)
8
+ # @attr [Array<Hash>] images The cover art for the album in various sizes, widest first
9
+ # @attr [String] name The name of the album
10
+ # @attr [Integer] popularity The popularity of the album - The value will be between 0 and 100, with 100 being the most popular
11
+ # @attr [String] release_date The date the album was first released, for example "1981-12-15" - Depending on the precision, it might be shown as "1981" or "1981-12"
12
+ # @attr [String] release_date_precision The precision with which release_date value is known: "year", "month", or "day"
13
+ # @attr [Array<Track>] tracks The tracks of the album.
3
14
  class Album < Base
4
15
 
16
+ # Returns Album object(s) with id(s) provided
17
+ #
18
+ # @param ids [String, Array]
19
+ # @return [Album, Array<Album>]
20
+ #
21
+ # @example
22
+ # album = RSpotify::Album.find('41vPD50kQ7JeamkxQW7Vuy')
23
+ # album.class #=> RSpotify::Album
24
+ # album.name #=> "AM"
25
+ #
26
+ # ids = %w(41vPD50kQ7JeamkxQW7Vuy 4jKGRliQXa5VwxKOsiCbfL)
27
+ # albums = RSpotify::Album.find(ids)
28
+ # albums.class #=> Array
29
+ # albums.first.class #=> RSpotify::Album
5
30
  def self.find(ids)
6
31
  super(ids, 'album')
7
32
  end
8
33
 
34
+ # Returns array of Album objects matching the query, ordered by popularity
35
+ #
36
+ # @param query [String]
37
+ # @param limit [Integer]
38
+ # @param offset [Integer]
39
+ # @return [Array<Album>]
40
+ #
41
+ # @example
42
+ # albums = RSpotify::Album.search('AM')
43
+ # albums.size #=> 20
44
+ # albums.first.class #=> RSpotify::Album
45
+ # albums.first.name #=> "AM"
46
+ #
47
+ # albums = RSpotify::Base.search('AM', 10)
48
+ # albums.size #=> 10
9
49
  def self.search(query, limit = 20, offset = 0)
10
50
  super(query, 'album', limit, offset)
11
51
  end
@@ -1,11 +1,44 @@
1
1
  module RSpotify
2
2
 
3
+ # @attr [Array<String>] genres A list of the genres used to classify the album (If not yet classified, the array is empty)
4
+ # @attr [Array<Hash>] images The cover art for the album in various sizes, widest first
5
+ # @attr [String] name The name of the album
6
+ # @attr [Integer] popularity The popularity of the album - The value will be between 0 and 100, with 100 being the most popular
3
7
  class Artist < Base
4
8
 
9
+ # Returns Artist object(s) with id(s) provided
10
+ #
11
+ # @param ids [String, Array]
12
+ # @return [Artist, Array<Artist>]
13
+ #
14
+ # @example
15
+ # artist = RSpotify::Artist.find('7Ln80lUS6He07XvHI8qqHH')
16
+ # artist.class #=> RSpotify::Artist
17
+ # artist.name #=> "Arctic Monkeys"
18
+ #
19
+ # ids = %w(7Ln80lUS6He07XvHI8qqHH 3dRfiJ2650SZu6GbydcHNb)
20
+ # artists = RSpotify::Artist.find(ids)
21
+ # artists.class #=> Array
22
+ # artists.first.class #=> RSpotify::Artist
5
23
  def self.find(ids)
6
24
  super(ids, 'artist')
7
25
  end
8
26
 
27
+ # Returns array of Artist objects matching the query, ordered by popularity
28
+ #
29
+ # @param query [String]
30
+ # @param limit [Integer]
31
+ # @param offset [Integer]
32
+ # @return [Array<Artist>]
33
+ #
34
+ # @example
35
+ # artists = RSpotify::Artist.search('Arctic')
36
+ # artists.size #=> 20
37
+ # artists.first.class #=> RSpotify::Artist
38
+ # artists.first.name #=> "Arctic Monkeys"
39
+ #
40
+ # artists = RSpotify::Artist.search('Arctic', 10)
41
+ # artists.size #=> 10
9
42
  def self.search(query, limit = 20, offset = 0)
10
43
  super(query, 'artist', limit, offset)
11
44
  end
@@ -20,12 +53,31 @@ module RSpotify
20
53
  super(options)
21
54
  end
22
55
 
56
+ # Returns all albums from artist
57
+ #
58
+ # @return [Array<Album>]
59
+ #
60
+ # @example
61
+ # albums = artist.albums
62
+ # albums.class #=> Array
63
+ # albums.first.class #=> RSpotify::Album
64
+ # albums.first.name #=> "AM"
23
65
  def albums
24
66
  return @albums unless @albums.nil?
25
67
  json = RSpotify.get("artists/#{@id}/albums")
26
68
  @albums = json['items'].map { |a| Album.new a }
27
69
  end
28
70
 
71
+ # Returns artist's 10 top tracks by country.
72
+ #
73
+ # @param country [Symbol] an {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}
74
+ # @return [Array<Track>]
75
+ #
76
+ # @example
77
+ # top_tracks = artist.top_tracks(:US)
78
+ # top_tracks.class #=> Array
79
+ # top_tracks.size #=> 10
80
+ # top_tracks.first.class #=> RSpotify::Track
29
81
  def top_tracks(country)
30
82
  return @top_tracks[country] unless @top_tracks[country].nil?
31
83
  json = RSpotify.get("artists/#{@id}/top-tracks?country=#{country}")
data/lib/rspotify/base.rb CHANGED
@@ -1,28 +1,80 @@
1
1
  module RSpotify
2
2
 
3
+ # @attr [Hash] external_urls Known external URLs for object
4
+ # @attr [String] href A link to the Web API endpoint
5
+ # @attr [String] id The {https://developer.spotify.com/web-api/user-guide/#spotify-uris-and-ids Spotify ID} for the object
6
+ # @attr [String] type The object type (artist, album, etc.)
7
+ # @attr [String] uri The {https://developer.spotify.com/web-api/user-guide/#spotify-uris-and-ids Spotify URI} for the object
3
8
  class Base
4
9
 
10
+ # Returns RSpotify object(s) with id(s) and type provided
11
+ #
12
+ # @param ids [String, Array]
13
+ # @param type [String]
14
+ # @return [Album, Artist, Track, User, Array<Album>, Array<Artist>, Array<Track>]
15
+ #
16
+ # @example
17
+ # user = RSpotify::Base.find('wizzler', 'user')
18
+ # user.class #=> RSpotify::User
19
+ # user.id #=> "wizzler"
20
+ #
21
+ # ids = %w(2UzMpPKPhbcC8RbsmuURAZ 7Jzsc04YpkRwB1zeyM39wE)
22
+ # tracks = RSpotify::Base.find(ids, 'track')
23
+ # tracks.class #=> Array
24
+ # tracks.first.class #=> RSpotify::Track
5
25
  def self.find(ids, type)
6
- pluralized_type = "#{type}s"
7
- path = pluralized_type.dup
8
- type_class = eval type.capitalize
9
-
10
26
  case ids.class.to_s
11
27
  when 'Array'
12
- path << "?ids=#{ids.join ','}"
13
- json = RSpotify.get path
14
- json[pluralized_type].map { |t| type_class.new t }
28
+ if type == 'user'
29
+ warn 'Spotify API does not support finding several users simultaneously'
30
+ return false
31
+ end
32
+ find_many(ids, type)
15
33
  when 'String'
16
34
  id = ids
17
- path << "/#{id}"
18
- json = RSpotify.get path
19
- type_class.new json
35
+ find_one(id, type)
20
36
  end
21
37
  end
22
38
 
39
+ def self.find_many(ids, type)
40
+ pluralized_type = "#{type}s"
41
+ type_class = RSpotify.const_get(type.capitalize)
42
+
43
+ path = "#{pluralized_type}?ids=#{ids.join ','}"
44
+ json = RSpotify.get path
45
+ json[pluralized_type].map { |t| type_class.new t }
46
+ end
47
+ private_class_method :find_many
48
+
49
+ def self.find_one(id, type)
50
+ pluralized_type = "#{type}s"
51
+ type_class = RSpotify.const_get(type.capitalize)
52
+
53
+ path = "#{pluralized_type}/#{id}"
54
+ json = RSpotify.get path
55
+ type_class.new json
56
+ end
57
+ private_class_method :find_one
58
+
59
+ # Returns array of RSpotify objects matching the query, ordered by popularity
60
+ #
61
+ # @param query [String]
62
+ # @param type [String]
63
+ # @param limit [Integer]
64
+ # @param offset [Integer]
65
+ # @return [Array<Album>, Array<Artist>, Array<Track>]
66
+ #
67
+ # @example
68
+ # artists = RSpotify::Base.search('Arctic', 'artist')
69
+ # artists.size #=> 20
70
+ # artists.first.class #=> RSpotify::Artist
71
+ # artists.first.name #=> "Arctic Monkeys"
72
+ #
73
+ # albums = RSpotify::Base.search('AM', 'album', 10)
74
+ # albums.size #=> 10
23
75
  def self.search(query, type, limit = 20, offset = 0)
24
76
  pluralized_type = "#{type}s"
25
- type_class = eval type.capitalize
77
+ type_class = RSpotify.const_get(type.capitalize)
26
78
 
27
79
  json = RSpotify.get 'search',
28
80
  params: {
@@ -44,14 +96,34 @@ module RSpotify
44
96
  @uri = options['uri']
45
97
  end
46
98
 
99
+ # When an object is obtained undirectly, Spotify usually returns a simplified version of it.
100
+ # This method updates it into a full object, with all attributes filled.
101
+ #
102
+ # @note It is seldom necessary to use this method explicitly, since RSpotify takes care of it automatically when needed (see {#method_missing})
103
+ #
104
+ # @example
105
+ # track = artist.tracks.first
106
+ # track.instance_variable_get("@popularity") #=> nil
107
+ # track.complete!
108
+ # track.instance_variable_get("@popularity") #=> 62
47
109
  def complete!
48
- pluralized_type = "#{type}s"
110
+ pluralized_type = "#{@type}s"
49
111
  initialize RSpotify.get("#{pluralized_type}/#{@id}")
50
112
  end
51
113
 
114
+ # Used internally to retrieve an object's instance variable. If instance
115
+ # variable equals nil, calls {#complete!} on object and retrieve it again.
116
+ #
117
+ # @example
118
+ # user.id #=> "wizzler"
119
+ #
120
+ # track = artist.tracks.first
121
+ # track.instance_variable_get("@popularity") #=> nil
122
+ # track.popularity #=> 62
123
+ # track.instance_variable_get("@popularity") #=> 62
52
124
  def method_missing(method_name, *args)
53
- attr = "@#{method_name}".to_sym
54
- super unless instance_variables.include? attr
125
+ attr = "@#{method_name}"
126
+ super unless instance_variable_defined? attr
55
127
 
56
128
  attr_value = instance_variable_get attr
57
129
  return attr_value unless attr_value.nil?
@@ -60,9 +132,10 @@ module RSpotify
60
132
  instance_variable_get attr
61
133
  end
62
134
 
63
- def respond_to?(method_name)
64
- attr = "@#{method_name}".to_sym
65
- return true if instance_variables.include? attr
135
+ # Overrides Object#respond_to? to also consider methods dynamically generated by {#method_missing}
136
+ def respond_to?(method_name, include_private_methods = false)
137
+ attr = "@#{method_name}"
138
+ return true if instance_variable_defined? attr
66
139
  super
67
140
  end
68
141
  end
@@ -1,14 +1,34 @@
1
1
  module RSpotify
2
2
 
3
+ # @attr [Boolean] collaborative true if the owner allows other users to modify the playlist
4
+ # @attr [String] description The playlist description
5
+ # @attr [Hash] followers Information about the followers of the playlist
6
+ # @attr [Array<Hash>] images The playlist images
7
+ # @attr [String] name The name of the playlist
8
+ # @attr [User] owner The user who owns the playlist
9
+ # @attr [Boolean] public true if the playlist is not marked as secret
10
+ # @attr [Array<Track>] tracks The tracks of the playlist
3
11
  class Playlist < Base
4
12
 
13
+ # Returns Playlist object with user_id and id provided
14
+ #
15
+ # @param user_id [String]
16
+ # @param id [String]
17
+ # @return [Playlist]
18
+ #
19
+ # @example
20
+ # playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
21
+ # playlist.class #=> RSpotify::Playlist
22
+ # playlist.name #=> "Movie Soundtrack Masterpieces"
5
23
  def self.find(user_id, id)
6
24
  json = RSpotify.auth_get("users/#{user_id}/playlists/#{id}")
7
25
  Playlist.new json
8
26
  end
9
27
 
10
- def self.search
11
- #TODO
28
+ # Spotify does not support search for playlists. Prints warning and returns false
29
+ def self.search(*args)
30
+ warn 'Spotify API does not support search for playlists'
31
+ false
12
32
  end
13
33
 
14
34
  def initialize(options = {})
@@ -30,6 +50,16 @@ module RSpotify
30
50
  super(options)
31
51
  end
32
52
 
53
+ # When an object is obtained undirectly, Spotify usually returns a simplified version of it.
54
+ # This method updates it into a full object, with all attributes filled.
55
+ #
56
+ # @note It is seldom necessary to use this method explicitly, since RSpotify takes care of it automatically when needed (see {Base#method_missing})
57
+ #
58
+ # @example
59
+ # playlist = user.playlists.first
60
+ # playlist.instance_variable_get("@description") #=> nil
61
+ # playlist.complete!
62
+ # playlist.instance_variable_get("@description") #=> "Iconic soundtracks..."
33
63
  def complete!
34
64
  initialize RSpotify.auth_get("users/#{@owner.id}/playlists/#{@id}")
35
65
  end
@@ -1,11 +1,51 @@
1
1
  module RSpotify
2
2
 
3
+ # @attr [Album] album The album on which the track appears
4
+ # @attr [Array<Artist>] artists The artists who performed the track
5
+ # @attr [Array<String>] available_markets The markets in which the track can be played: {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country codes}
6
+ # @attr [Integer] disc_number The disc number (usually 1 unless the album consists of more than one disc)
7
+ # @attr [Integer] duration_ms The track length in milliseconds
8
+ # @attr [Boolean] explicit Whether or not the track has explicit lyrics (true = yes it does; false = no it does not OR unknown)
9
+ # @attr [Hash] external_ids Known external IDs for the track
10
+ # @attr [String] name The name of the track
11
+ # @attr [Integer] popularity The popularity of the track - The value will be between 0 and 100, with 100 being the most popular
12
+ # @attr [String] preview_url A link to a 30 second preview (MP3 format) of the track
13
+ # @attr [Integer] track_number The number of the track - If an album has several discs, the track number is the number on the specified disc
3
14
  class Track < Base
4
15
 
16
+ # Returns Track object(s) with id(s) provided
17
+ #
18
+ # @param ids [String, Array]
19
+ # @return [Track, Array<Track>]
20
+ #
21
+ # @example
22
+ # track = RSpotify::Track.find('2UzMpPKPhbcC8RbsmuURAZ')
23
+ # track.class #=> RSpotify::Track
24
+ # track.name #=> "Do I Wanna Know?"
25
+ #
26
+ # ids = %w(2UzMpPKPhbcC8RbsmuURAZ 7Jzsc04YpkRwB1zeyM39wE)
27
+ # tracks = RSpotify::Base.find(ids, 'track')
28
+ # tracks.class #=> Array
29
+ # tracks.first.class #=> RSpotify::Track
5
30
  def self.find(ids)
6
31
  super(ids, 'track')
7
32
  end
8
33
 
34
+ # Returns array of Track objects matching the query, ordered by popularity
35
+ #
36
+ # @param query [String]
37
+ # @param limit [Integer]
38
+ # @param offset [Integer]
39
+ # @return [Array<Track>]
40
+ #
41
+ # @example
42
+ # tracks = RSpotify::Track.search('Thriller')
43
+ # tracks.size #=> 20
44
+ # tracks.first.class #=> RSpotify::Track
45
+ # tracks.first.name #=> "Thriller"
46
+ #
47
+ # tracks = RSpotify::Track.search('Thriller', 10)
48
+ # tracks.size #=> 10
9
49
  def self.search(query, limit = 20, offset = 0)
10
50
  super(query, 'track', limit, offset)
11
51
  end
data/lib/rspotify/user.rb CHANGED
@@ -2,22 +2,38 @@ module RSpotify
2
2
 
3
3
  class User < Base
4
4
 
5
+ # Returns User object with id provided
6
+ #
7
+ # @param ids [String]
8
+ # @return [User]
9
+ #
10
+ # @example
11
+ # user = RSpotify::User.find('wizzler')
12
+ # user.class #=> RSpotify::User
13
+ # user.id #=> "wizzler"
5
14
  def self.find(id)
6
- if id.is_a? Array
7
- warn 'Spotify API does not support finding several users simultaneously'
8
- return false
9
- end
10
15
  super(id, 'user')
11
16
  end
12
17
 
13
- def self.search
14
- #TODO
18
+ # Spotify does not support search for users. Prints warning and returns false
19
+ def self.search(*args)
20
+ warn 'Spotify API does not support search for users'
21
+ false
15
22
  end
16
23
 
17
24
  def initialize(options = {})
18
25
  super(options)
19
26
  end
20
27
 
28
+ # Returns all playlists from user
29
+ #
30
+ # @return [Array<Playlist>]
31
+ #
32
+ # @example
33
+ # playlists = user.playlists
34
+ # playlists.class #=> Array
35
+ # playlists.first.class #=> RSpotify::Playlist
36
+ # playlists.first.name #=> "Movie Soundtrack Masterpieces"
21
37
  def playlists
22
38
  return @playlists unless @playlists.nil?
23
39
  playlists = RSpotify.auth_get("users/#{@id}/playlists")['items']
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Sad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest_client