rspotify 0.1.1 → 0.2.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 +25 -1
- data/doc/TODO +0 -0
- data/lib/rspotify.rb +28 -8
- data/lib/rspotify/album.rb +2 -1
- data/lib/rspotify/playlist.rb +36 -0
- data/lib/rspotify/user.rb +5 -0
- data/lib/rspotify/version.rb +1 -1
- data/spec/TODO +0 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86ed84fdd85f9e551759817dea9a12460349a4b8
|
4
|
+
data.tar.gz: e455df5cc613e94a65d78af348b6e775a21b2335
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c2cad5eaf9f7d00a62ce9a2ef61360779ec5264873e44634c75f291bb034cea5734b1fb5f43d59b7f870603d233d444fc598418ceffd273f2121c58e8444a0
|
7
|
+
data.tar.gz: 4653d34b828be1ae1575771eadbc76c76fd4416f2a08a55e84845cb909d5633ae0751ee3e6fd1bd1bf7819c85a1c80b03bee6ba5b411114390289b93778f9330
|
data/README.md
CHANGED
@@ -18,9 +18,11 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Directly access public data such as albums, tracks, artists and users:
|
22
22
|
|
23
23
|
```ruby
|
24
|
+
require 'rspotify'
|
25
|
+
|
24
26
|
tracks = RSpotify::Track.search('Paranoid')
|
25
27
|
|
26
28
|
tracks.first.name #=> "Paranoid"
|
@@ -40,13 +42,35 @@ artist.genres #=> ["Alternative Rap", "East Coast Rap", "Hardcore Rap", "Hip Hop
|
|
40
42
|
|
41
43
|
album = RSpotify::Album.find('0uZ8zQLHru4BiNTL2PQY91')
|
42
44
|
album.album_type #=> "single"
|
45
|
+
album.tracks #=> (Track array)
|
43
46
|
|
44
47
|
track = RSpotify::Track.find('2qmxggATKFIeg68guRSG3r')
|
45
48
|
track.duration_ms #=> 270800
|
49
|
+
track.album #=> (Album object)
|
46
50
|
|
47
51
|
user = RSpotify::User.find('wizzler')
|
48
52
|
user.external_urls["spotify"] #=> "https://open.spotify.com/user/wizzler"
|
49
53
|
```
|
54
|
+
|
55
|
+
Some data require authentication to be accessed, such as playlists. You can easily get your credentials [here](https://developer.spotify.com/my-applications)
|
56
|
+
|
57
|
+
Then just copy and paste them like so:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
RSpotify.authenticate("<your_client_id>", "<your_client_secret>")
|
61
|
+
|
62
|
+
# Now you can access any public playlist and much more!
|
63
|
+
|
64
|
+
playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
|
65
|
+
playlist.name #=> "Movie Soundtrack Masterpieces"
|
66
|
+
playlist.description #=> "Iconic soundtracks featured..."
|
67
|
+
playlist.followers['total'] #=> 13
|
68
|
+
playlist.tracks #=> (Track array)
|
69
|
+
|
70
|
+
my_user = RSpotify::User.find("my_user")
|
71
|
+
my_playlists = my_user.playlists #=> (Playlist array)
|
72
|
+
```
|
73
|
+
|
50
74
|
More documentation will follow
|
51
75
|
|
52
76
|
## Contributing
|
data/doc/TODO
ADDED
File without changes
|
data/lib/rspotify.rb
CHANGED
@@ -1,24 +1,44 @@
|
|
1
1
|
require 'rspotify/version'
|
2
2
|
|
3
|
+
require 'base64'
|
3
4
|
require 'json'
|
4
5
|
require 'restclient'
|
5
6
|
|
6
7
|
module RSpotify
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
API_URI = 'https://api.spotify.com/v1/'
|
10
|
+
TOKEN_URI = 'https://accounts.spotify.com/api/token'
|
11
|
+
VERBS = %w(get post put delete)
|
10
12
|
|
11
|
-
autoload :
|
12
|
-
autoload :Artist,
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
13
|
+
autoload :Album, 'rspotify/album'
|
14
|
+
autoload :Artist, 'rspotify/artist'
|
15
|
+
autoload :Base, 'rspotify/base'
|
16
|
+
autoload :Playlist, 'rspotify/playlist'
|
17
|
+
autoload :Track, 'rspotify/track'
|
18
|
+
autoload :User, 'rspotify/user'
|
19
|
+
|
20
|
+
def self.authenticate(client_id, client_secret)
|
21
|
+
request_body = { grant_type: 'client_credentials' }
|
22
|
+
authorization = Base64.strict_encode64 "#{client_id}:#{client_secret}"
|
23
|
+
headers = { 'Authorization' => "Basic #{authorization}" }
|
24
|
+
response = RestClient.post(TOKEN_URI, request_body, headers)
|
25
|
+
@access_token = JSON.parse(response)['access_token']
|
26
|
+
true
|
27
|
+
end
|
16
28
|
|
17
29
|
VERBS.each do |verb|
|
30
|
+
|
18
31
|
define_singleton_method verb do |path, *params|
|
19
|
-
url =
|
32
|
+
url = API_URI + path
|
20
33
|
response = RestClient.send(verb, url, *params)
|
21
34
|
JSON.parse response
|
22
35
|
end
|
36
|
+
|
37
|
+
define_singleton_method "auth_#{verb}" do |path, *params|
|
38
|
+
auth_header = { 'Authorization' => "Bearer #{@access_token}" }
|
39
|
+
params << auth_header
|
40
|
+
send(verb, path, *params)
|
41
|
+
end
|
42
|
+
|
23
43
|
end
|
24
44
|
end
|
data/lib/rspotify/album.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module RSpotify
|
2
|
+
|
3
|
+
class Playlist < Base
|
4
|
+
|
5
|
+
attr_accessor :collaborative, :description, :followers,
|
6
|
+
:images, :name, :owner, :public, :tracks
|
7
|
+
|
8
|
+
def self.find(user_id, id)
|
9
|
+
json = RSpotify.auth_get("users/#{user_id}/playlists/#{id}")
|
10
|
+
Playlist.new json
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.search
|
14
|
+
#TODO
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
@collaborative = options['collaborative']
|
19
|
+
@description = options['description']
|
20
|
+
@followers = options['followers']
|
21
|
+
@images = options['images']
|
22
|
+
@name = options['name']
|
23
|
+
@owner = options['owner']
|
24
|
+
@public = options['public']
|
25
|
+
@tracks = options['tracks']
|
26
|
+
|
27
|
+
super(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def tracks
|
31
|
+
json = RSpotify.auth_get("users/#{@owner['id']}/playlists/#{@id}/tracks")
|
32
|
+
json['items'].map{ |t| Track.new t['track'] }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/rspotify/user.rb
CHANGED
data/lib/rspotify/version.rb
CHANGED
data/spec/TODO
ADDED
File without changes
|
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.2.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-
|
11
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest_client
|
@@ -92,14 +92,17 @@ files:
|
|
92
92
|
- LICENSE.txt
|
93
93
|
- README.md
|
94
94
|
- Rakefile
|
95
|
+
- doc/TODO
|
95
96
|
- lib/rspotify.rb
|
96
97
|
- lib/rspotify/album.rb
|
97
98
|
- lib/rspotify/artist.rb
|
98
99
|
- lib/rspotify/base.rb
|
100
|
+
- lib/rspotify/playlist.rb
|
99
101
|
- lib/rspotify/track.rb
|
100
102
|
- lib/rspotify/user.rb
|
101
103
|
- lib/rspotify/version.rb
|
102
104
|
- rspotify.gemspec
|
105
|
+
- spec/TODO
|
103
106
|
homepage: http://rubygems.org/gems/rspotify
|
104
107
|
licenses:
|
105
108
|
- MIT
|
@@ -124,4 +127,5 @@ rubygems_version: 2.2.2
|
|
124
127
|
signing_key:
|
125
128
|
specification_version: 4
|
126
129
|
summary: A ruby wrapper for the Spotify Web API
|
127
|
-
test_files:
|
130
|
+
test_files:
|
131
|
+
- spec/TODO
|