rspotify 0.0.1 → 0.1.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: 7e29fb708a1a147c1715b3646fbf79c7a022ddf9
4
- data.tar.gz: cbaaf10af09720731340c646bad0b1f481c4ef83
3
+ metadata.gz: 41767dc3420c792c7cffc69f25a468adf3e8eb61
4
+ data.tar.gz: 143d31600e35010404e0709a1baec81c7c413fbf
5
5
  SHA512:
6
- metadata.gz: 10b5fbf40e3c113b08e31c35c561be7ca51380d68b01df66967ae464a9079e429789ac933549dcfdce7b19ea4df0d9edf1c418f833d66980a4980450b75a61ca
7
- data.tar.gz: dabf5f86a86e0ea21b1a627a60f7b2b167b385cde6c6dcd63dfb5a75c4d57ab81dfbe7ebfb32efa04c8bace37e37333c1fd7c78e8421a0cbe09ea5eb9138b9e8
6
+ metadata.gz: e65c1ae80cd2e3c455fc7ea25f7f94bd32850cd921962b5f3d5e224c7f504dff5009041e9ec8c259d893d8164606e73361f08847e727dacbabe779ff6bc015c4
7
+ data.tar.gz: 02d62eb595182b7fbe4e224b668206c398b18f2f274e813384cabbfeb034be43689d5fb74396eda540baa02c29ec5a2610682719bd84f2493b6323bbbb1a616b
data/README.md CHANGED
@@ -33,6 +33,19 @@ album.images #=> (Image array)
33
33
  artists = tracks.first.artists
34
34
  artists.first.name #=> "Black Sabbath"
35
35
  artists.first.uri #=> "spotify:artist:5M52tdBnJaKSvOpJGz8mfZ"
36
+
37
+ # Find by id
38
+ artist = RSpotify::Artist.find('5K4W6rqBFWDnAN6FQUkS6x')
39
+ artist.genres #=> ["Alternative Rap", "East Coast Rap", "Hardcore Rap", "Hip Hop", "Midwest Rap", "Pop-Rap", "Rap"]
40
+
41
+ album = RSpotify::Album.find('0uZ8zQLHru4BiNTL2PQY91')
42
+ album.album_type #=> "single"
43
+
44
+ track = RSpotify::Track.find('2qmxggATKFIeg68guRSG3r')
45
+ track.duration_ms #=> 270800
46
+
47
+ user = RSpotify::User.find('wizzler')
48
+ user.external_urls["spotify"] #=> "https://open.spotify.com/user/wizzler"
36
49
  ```
37
50
  More documentation will follow
38
51
 
@@ -4,7 +4,7 @@ require 'json'
4
4
  require 'restclient'
5
5
 
6
6
  module RSpotify
7
-
7
+
8
8
  BASE_URI = 'https://api.spotify.com/v1/'
9
9
  VERBS = %w(get post put delete)
10
10
 
@@ -12,7 +12,8 @@ module RSpotify
12
12
  autoload :Artist, 'rspotify/artist'
13
13
  autoload :Album, 'rspotify/album'
14
14
  autoload :Track, 'rspotify/track'
15
-
15
+ autoload :User, 'rspotify/user'
16
+
16
17
  VERBS.each do |verb|
17
18
  define_singleton_method verb do |path, *params|
18
19
  url = BASE_URI + path
@@ -2,7 +2,11 @@ module RSpotify
2
2
 
3
3
  class Album < Base
4
4
 
5
- attr_accessor :album_type, :images
5
+ attr_accessor :album_type, :images, :name, :tracks
6
+
7
+ def self.find(id)
8
+ super(id, 'album')
9
+ end
6
10
 
7
11
  def self.search(query, limit = 20, offset = 0)
8
12
  super(query, 'album', limit, offset)
@@ -11,6 +15,11 @@ module RSpotify
11
15
  def initialize(options = {})
12
16
  @album_type = options['album_type']
13
17
  @images = options['images']
18
+ @name = options['name']
19
+
20
+ if options['tracks']
21
+ @tracks = options['tracks']['items'].map { |t| Track.new (t) }
22
+ end
14
23
 
15
24
  super(options)
16
25
  end
@@ -2,7 +2,11 @@ module RSpotify
2
2
 
3
3
  class Artist < Base
4
4
 
5
- attr_accessor :genres, :images, :popularity
5
+ attr_accessor :genres, :images, :name, :popularity
6
+
7
+ def self.find(id)
8
+ super(id, 'artist')
9
+ end
6
10
 
7
11
  def self.search(query, limit = 20, offset = 0)
8
12
  super(query, 'artist', limit, offset)
@@ -11,6 +15,7 @@ module RSpotify
11
15
  def initialize(options = {})
12
16
  @genres = options['genres']
13
17
  @images = options['images']
18
+ @name = options['name']
14
19
  @popularity = options['popularity']
15
20
 
16
21
  super(options)
@@ -2,10 +2,14 @@ module RSpotify
2
2
 
3
3
  class Base
4
4
 
5
- attr_accessor :external_urls, :href, :id, :name, :type, :uri
5
+ attr_accessor :external_urls, :href, :id, :type, :uri
6
6
 
7
- def self.find(id)
8
- #TODO
7
+ def self.find(id, type)
8
+ pluralized_type = "#{type}s"
9
+ type_class = eval type.capitalize
10
+
11
+ json = RSpotify.get "#{pluralized_type}/#{id}"
12
+ type_class.new json
9
13
  end
10
14
 
11
15
  def self.search(query, type, limit = 20, offset = 0)
@@ -28,7 +32,6 @@ module RSpotify
28
32
  @external_urls = options['external_urls']
29
33
  @href = options['href']
30
34
  @id = options['id']
31
- @name = options['name']
32
35
  @type = options['type']
33
36
  @uri = options['uri']
34
37
  end
@@ -2,21 +2,26 @@ module RSpotify
2
2
 
3
3
  class Track < Base
4
4
 
5
- attr_accessor :album, :artists, :available_markets, :disc_number, :duration_ms,
6
- :explicit, :external_ids, :popularity, :preview_url, :track_number
5
+ attr_accessor :album, :artists, :available_markets, :disc_number, :duration_ms, :explicit,
6
+ :external_ids, :name, :popularity, :preview_url, :track_number
7
+
8
+ def self.find(id)
9
+ super(id, 'track')
10
+ end
7
11
 
8
12
  def self.search(query, limit = 20, offset = 0)
9
13
  super(query, 'track', limit, offset)
10
14
  end
11
15
 
12
16
  def initialize(options = {})
13
- @album = Album.new options['album']
17
+ @album = Album.new options['album'] if options['album']
14
18
  @artists = options['artists'].map { |a| Artist.new a }
15
19
  @available_markets = options['available_markets']
16
20
  @disc_number = options['disc_number']
17
21
  @duration_ms = options['duration_ms']
18
22
  @explicit = options['explicit']
19
23
  @external_ids = options['external_ids']
24
+ @name = options['name']
20
25
  @popularity = options['popularity']
21
26
  @preview_url = options['preview_url']
22
27
  @track_number = options['track_number']
@@ -0,0 +1,18 @@
1
+ module RSpotify
2
+
3
+ class User < Base
4
+
5
+ def self.find(id)
6
+ super(id, 'user')
7
+ end
8
+
9
+ def self.search
10
+ #TODO
11
+ end
12
+
13
+ def initialize(options = {})
14
+ super(options)
15
+ end
16
+
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RSpotify
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Sad
@@ -97,6 +97,7 @@ files:
97
97
  - lib/rspotify/artist.rb
98
98
  - lib/rspotify/base.rb
99
99
  - lib/rspotify/track.rb
100
+ - lib/rspotify/user.rb
100
101
  - lib/rspotify/version.rb
101
102
  - rspotify.gemspec
102
103
  homepage: http://rubygems.org/gems/rspotify