rspotify 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/rspotify/album.rb +5 -5
- data/lib/rspotify/artist.rb +3 -3
- data/lib/rspotify/base.rb +14 -16
- data/lib/rspotify/playlist.rb +17 -1
- data/lib/rspotify/track.rb +6 -6
- data/lib/rspotify/user.rb +20 -1
- data/lib/rspotify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 099ef6df09a9e5e69ec2765409c9d4262f4e5e30
|
4
|
+
data.tar.gz: 9f00aa8931f67d946b158391c7afa99e05fad61b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451f177d91bcf3cb1025cac3d448b0a69a0216faf51c0f6285a0499ce36435fc6aa04b5d1de6890617339f3f50164e0c71ffaa9697430eb2429e0f8e05d98e9e
|
7
|
+
data.tar.gz: 759310516f92db6b07e71e8afd8ca4b4da649376fff85580d19ea394d0f0d6b34245e68dd1e5bafb27abd55950eee5c3ee32f3e3258802af5f8a025bef91ea1c
|
data/README.md
CHANGED
@@ -137,22 +137,24 @@ get '/auth/spotify/callback', to: 'users#spotify'
|
|
137
137
|
|
138
138
|
Remember you need to tell Spotify this address is white-listed. You can do this by adding it to the Redirect URIs list in your [application page](https://developer.spotify.com/my-applications). An example of Redirect URI would be http://localhost:3000/auth/spotify/callback.
|
139
139
|
|
140
|
-
Finally, create a new RSpotify User with the
|
140
|
+
Finally, create a new RSpotify User with the response received:
|
141
141
|
|
142
142
|
```ruby
|
143
143
|
class UsersController < ApplicationController
|
144
144
|
def spotify
|
145
145
|
spotify_user = RSpotify::User.new(request.env['omniauth.auth'])
|
146
|
-
# Now you can
|
146
|
+
# Now you can access user's private data, create playlists and much more
|
147
147
|
|
148
|
+
# Access private data (Check doc for all attributes)
|
149
|
+
spotify_user.country #=> "US"
|
150
|
+
spotify_user.email #=> "example@email.com"
|
151
|
+
|
152
|
+
# Create playlist in user's Spotify account
|
148
153
|
playlist = spotify_user.create_playlist!('my-awesome-playlist')
|
149
|
-
# Directly creates playlist in user's Spotify account and returns it
|
150
154
|
|
155
|
+
# Add tracks to a playlist in user's Spotify account
|
151
156
|
tracks = RSpotify::Track.search('Know')
|
152
|
-
|
153
157
|
playlist.add_tracks!(tracks)
|
154
|
-
# user's Spotify account now has a playlist with songs containing "Know" in the name
|
155
|
-
|
156
158
|
playlist.tracks.first.name #=> "Somebody That I Used To Know"
|
157
159
|
end
|
158
160
|
end
|
data/lib/rspotify/album.rb
CHANGED
@@ -2,13 +2,13 @@ module RSpotify
|
|
2
2
|
|
3
3
|
# @attr [String] album_type The type of the album (album, single, compilation)
|
4
4
|
# @attr [Array<Artist>] artists The artists of the album
|
5
|
-
# @attr [Array<String>] available_markets The markets in which the album is available
|
5
|
+
# @attr [Array<String>] available_markets The markets in which the album is available. See {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country codes}
|
6
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
|
7
|
+
# @attr [Array<String>] genres A list of the genres used to classify the album. If not yet classified, the array is empty
|
8
8
|
# @attr [Array<Hash>] images The cover art for the album in various sizes, widest first
|
9
9
|
# @attr [String] name The name of the album
|
10
|
-
# @attr [Integer] popularity The popularity of the album
|
11
|
-
# @attr [String] release_date The date the album was first released, for example "1981-12-15"
|
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
12
|
# @attr [String] release_date_precision The precision with which release_date value is known: "year", "month", or "day"
|
13
13
|
# @attr [Array<Track>] tracks The tracks of the album.
|
14
14
|
class Album < Base
|
@@ -33,7 +33,7 @@ module RSpotify
|
|
33
33
|
|
34
34
|
# Returns array of Album objects matching the query, ordered by popularity
|
35
35
|
#
|
36
|
-
# @param query [String] The search query's keywords.
|
36
|
+
# @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
|
37
37
|
# @param limit [Integer] Maximum number of albums to return. Minimum: 1. Maximum: 50.
|
38
38
|
# @param offset [Integer] The index of the first album to return. Use with limit to get the next set of albums.
|
39
39
|
# @return [Array<Album>]
|
data/lib/rspotify/artist.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module RSpotify
|
2
2
|
|
3
|
-
# @attr [Array<String>] genres A list of the genres used to classify the album
|
3
|
+
# @attr [Array<String>] genres A list of the genres used to classify the album. If not yet classified, the array is empty.
|
4
4
|
# @attr [Array<Hash>] images The cover art for the album in various sizes, widest first
|
5
5
|
# @attr [String] name The name of the album
|
6
|
-
# @attr [Integer] popularity The popularity 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
|
7
7
|
class Artist < Base
|
8
8
|
|
9
9
|
# Returns Artist object(s) with id(s) provided
|
@@ -26,7 +26,7 @@ module RSpotify
|
|
26
26
|
|
27
27
|
# Returns array of Artist objects matching the query, ordered by popularity
|
28
28
|
#
|
29
|
-
# @param query [String] The search query's keywords.
|
29
|
+
# @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
|
30
30
|
# @param limit [Integer] Maximum number of artists to return. Minimum: 1. Maximum: 50.
|
31
31
|
# @param offset [Integer] The index of the first artist to return. Use with limit to get the next set of artists.
|
32
32
|
# @return [Array<Artist>]
|
data/lib/rspotify/base.rb
CHANGED
@@ -42,20 +42,18 @@ module RSpotify
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.find_many(ids, type)
|
45
|
-
pluralized_type = "#{type}s"
|
46
45
|
type_class = RSpotify.const_get(type.capitalize)
|
47
46
|
|
48
|
-
path = "#{
|
47
|
+
path = "#{type}s?ids=#{ids.join ','}"
|
49
48
|
json = RSpotify.get path
|
50
|
-
json[
|
49
|
+
json["#{type}s"].map { |t| type_class.new t }
|
51
50
|
end
|
52
51
|
private_class_method :find_many
|
53
52
|
|
54
53
|
def self.find_one(id, type)
|
55
|
-
pluralized_type = "#{type}s"
|
56
54
|
type_class = RSpotify.const_get(type.capitalize)
|
57
55
|
|
58
|
-
path = "#{
|
56
|
+
path = "#{type}s/#{id}"
|
59
57
|
json = RSpotify.get path
|
60
58
|
type_class.new json
|
61
59
|
end
|
@@ -63,11 +61,11 @@ module RSpotify
|
|
63
61
|
|
64
62
|
# Returns array of RSpotify objects matching the query, ordered by popularity
|
65
63
|
#
|
66
|
-
# @param query [String] The search query's keywords.
|
67
|
-
# @param type [String] Valid types are: album, artist and track
|
64
|
+
# @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
|
65
|
+
# @param type [String] Valid types are: album, artist and track. Separate multiple types with commas.
|
68
66
|
# @param limit [Integer] Maximum number of objects to return. Minimum: 1. Maximum: 50.
|
69
67
|
# @param offset [Integer] The index of the first object to return. Use with limit to get the next set of objects.
|
70
|
-
# @return [Array<
|
68
|
+
# @return [Array<Base>]
|
71
69
|
#
|
72
70
|
# @example
|
73
71
|
# artists = RSpotify::Base.search('Arctic', 'artist')
|
@@ -77,25 +75,26 @@ module RSpotify
|
|
77
75
|
#
|
78
76
|
# albums = RSpotify::Base.search('AM', 'album', 10)
|
79
77
|
# albums.size #=> 10
|
80
|
-
def self.search(query,
|
78
|
+
def self.search(query, types, limit = 20, offset = 0)
|
81
79
|
if limit < 1 || limit > 50
|
82
80
|
warn 'Limit must be between 1 and 50'
|
83
81
|
return false
|
84
82
|
end
|
85
83
|
|
86
|
-
|
87
|
-
type_class = RSpotify.const_get(type.capitalize)
|
84
|
+
types.gsub!(/\s+/, '')
|
88
85
|
|
89
86
|
json = RSpotify.get 'search',
|
90
87
|
params: {
|
91
88
|
q: query,
|
92
|
-
type:
|
89
|
+
type: types,
|
93
90
|
limit: limit,
|
94
91
|
offset: offset
|
95
92
|
}
|
96
93
|
|
97
|
-
|
98
|
-
|
94
|
+
types.split(',').flat_map do |type|
|
95
|
+
type_class = RSpotify.const_get(type.capitalize)
|
96
|
+
json["#{type}s"]['items'].map { |item| type_class.new item }
|
97
|
+
end
|
99
98
|
end
|
100
99
|
|
101
100
|
def initialize(options = {})
|
@@ -117,8 +116,7 @@ module RSpotify
|
|
117
116
|
# track.complete!
|
118
117
|
# track.instance_variable_get("@popularity") #=> 62
|
119
118
|
def complete!
|
120
|
-
|
121
|
-
initialize RSpotify.get("#{pluralized_type}/#{@id}")
|
119
|
+
initialize RSpotify.get("#{type}s/#{@id}")
|
122
120
|
end
|
123
121
|
|
124
122
|
# Used internally to retrieve an object's instance variable. If instance
|
data/lib/rspotify/playlist.rb
CHANGED
@@ -50,7 +50,23 @@ module RSpotify
|
|
50
50
|
super(options)
|
51
51
|
end
|
52
52
|
|
53
|
-
#
|
53
|
+
# Adds one or more tracks to a playlist in user's Spotify account. This method is only available when
|
54
|
+
# the current user has granted access to the *playlist-modify* and *playlist-modify-private* scopes.
|
55
|
+
#
|
56
|
+
# @param tracks [Array<Track>] Tracks to be added. Maximum: 100 per request
|
57
|
+
# @param position [Integer, NilClass] The position to insert the tracks, a zero-based index. Default: tracks are appended to the playlist
|
58
|
+
# @return [NilClass]
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# tracks = RSpotify::Track.search('Know', 30)
|
62
|
+
# playlist = user.create_playlist!('my-awesome-playlist')
|
63
|
+
#
|
64
|
+
# playlist.add_tracks!(tracks)
|
65
|
+
# playlist.tracks.size #=> 30
|
66
|
+
# playlist.tracks.first.name #=> "Somebody That I Used To Know"
|
67
|
+
#
|
68
|
+
# playlist.add_tracks!(tracks, position: 20)
|
69
|
+
# playlist.tracks[20].name #=> "Somebody That I Used To Know"
|
54
70
|
def add_tracks!(tracks, position: nil)
|
55
71
|
if tracks.size > 100
|
56
72
|
warn 'Too many tracks requested. Maximum: 100'
|
data/lib/rspotify/track.rb
CHANGED
@@ -2,15 +2,15 @@ module RSpotify
|
|
2
2
|
|
3
3
|
# @attr [Album] album The album on which the track appears
|
4
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
|
6
|
-
# @attr [Integer] disc_number The disc number
|
5
|
+
# @attr [Array<String>] available_markets The markets in which the track can be played. See {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
7
|
# @attr [Integer] duration_ms The track length in milliseconds
|
8
|
-
# @attr [Boolean] explicit Whether or not the track has explicit lyrics
|
8
|
+
# @attr [Boolean] explicit Whether or not the track has explicit lyrics. true = yes it does; false = no it does not OR unknown
|
9
9
|
# @attr [Hash] external_ids Known external IDs for the track
|
10
10
|
# @attr [String] name The name of the track
|
11
|
-
# @attr [Integer] popularity The popularity 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
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
|
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
|
14
14
|
class Track < Base
|
15
15
|
|
16
16
|
# Returns Track object(s) with id(s) provided
|
@@ -33,7 +33,7 @@ module RSpotify
|
|
33
33
|
|
34
34
|
# Returns array of Track objects matching the query, ordered by popularity
|
35
35
|
#
|
36
|
-
# @param query [String] The search query's keywords.
|
36
|
+
# @param query [String] The search query's keywords. See the q description in {https://developer.spotify.com/web-api/search-item here} for details.
|
37
37
|
# @param limit [Integer] Maximum number of tracks to return. Minimum: 1. Maximum: 50.
|
38
38
|
# @param offset [Integer] The index of the first track to return. Use with limit to get the next set of tracks.
|
39
39
|
# @return [Array<Track>]
|
data/lib/rspotify/user.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module RSpotify
|
2
2
|
|
3
|
+
# @attr [String] country The country of the user, as set in the user's account profile. An {http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2 country code}. This field is only available when the current user has granted access to the *user-read-private* scope.
|
4
|
+
# @attr [String] display_name The name displayed on the user's profile. This field is only available when the current user has granted access to the *user-read-private* scope.
|
5
|
+
# @attr [String] email The user's email address. This field is only available when the current user has granted access to the *user-read-email* scope.
|
6
|
+
# @attr [Array] images The user's profile image. This field is only available when the current user has granted access to the *user-read-private* scope.
|
7
|
+
# @attr [String] product The user's Spotify subscription level: "premium", "free", etc. This field is only available when the current user has granted access to the *user-read-private* scope.
|
3
8
|
class User < Base
|
4
9
|
|
5
10
|
# Returns User object with id provided
|
@@ -47,7 +52,21 @@ module RSpotify
|
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
|
-
#
|
55
|
+
# Creates a playlist in user's Spotify account. This method is only available when the current user
|
56
|
+
# has granted access to the *playlist-modify* and *playlist-modify-private* scopes.
|
57
|
+
#
|
58
|
+
# @param name [String] The name for the new playlist
|
59
|
+
# @param public [Boolean] Whether the playlist is public or private. Default: true
|
60
|
+
# @return [Playlist]
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# user.create_playlist!('my-first-playlist')
|
64
|
+
# user.playlists.last.name #=> "my-first-playlist"
|
65
|
+
# user.playlists.last.public #=> true
|
66
|
+
#
|
67
|
+
# playlist = user.create_playlist!('my-second-playlist', public: false)
|
68
|
+
# playlist.name #=> "my-second-playlist"
|
69
|
+
# playlist.public #=> false
|
51
70
|
def create_playlist!(name, public: true)
|
52
71
|
url = "users/#{@id}/playlists"
|
53
72
|
request_data = %Q({"name":"#{name}", "public":#{public}})
|
data/lib/rspotify/version.rb
CHANGED
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.
|
4
|
+
version: 0.10.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-07-
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|