spotify-ruby-api 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE +21 -0
  7. data/README.md +119 -0
  8. data/Rakefile +7 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/lib/spotify/api/album.rb +164 -0
  12. data/lib/spotify/api/artist.rb +248 -0
  13. data/lib/spotify/api/base.rb +150 -0
  14. data/lib/spotify/api/track.rb +127 -0
  15. data/lib/spotify/api/user.rb +58 -0
  16. data/lib/spotify/api/version.rb +5 -0
  17. data/lib/spotify/api.rb +12 -0
  18. data/lib/spotify/models/album.rb +42 -0
  19. data/lib/spotify/models/artist.rb +34 -0
  20. data/lib/spotify/models/category.rb +23 -0
  21. data/lib/spotify/models/copyright.rb +27 -0
  22. data/lib/spotify/models/cursor.rb +19 -0
  23. data/lib/spotify/models/cursorbased_paging.rb +24 -0
  24. data/lib/spotify/models/error.rb +122 -0
  25. data/lib/spotify/models/external_id.rb +41 -0
  26. data/lib/spotify/models/external_url.rb +39 -0
  27. data/lib/spotify/models/follower.rb +27 -0
  28. data/lib/spotify/models/full/album.rb +46 -0
  29. data/lib/spotify/models/full/artist.rb +37 -0
  30. data/lib/spotify/models/full/track.rb +34 -0
  31. data/lib/spotify/models/full/user.rb +31 -0
  32. data/lib/spotify/models/full.rb +11 -0
  33. data/lib/spotify/models/image.rb +28 -0
  34. data/lib/spotify/models/paging.rb +38 -0
  35. data/lib/spotify/models/playlist_track.rb +24 -0
  36. data/lib/spotify/models/saved_album.rb +22 -0
  37. data/lib/spotify/models/saved_track.rb +22 -0
  38. data/lib/spotify/models/simplified/album.rb +23 -0
  39. data/lib/spotify/models/simplified/artist.rb +23 -0
  40. data/lib/spotify/models/simplified/track.rb +23 -0
  41. data/lib/spotify/models/simplified/user.rb +23 -0
  42. data/lib/spotify/models/simplified.rb +11 -0
  43. data/lib/spotify/models/track.rb +50 -0
  44. data/lib/spotify/models/track_link.rb +33 -0
  45. data/lib/spotify/models/user.rb +41 -0
  46. data/lib/spotify/models.rb +27 -0
  47. data/lib/spotify.rb +6 -0
  48. data/spotify-api.gemspec +34 -0
  49. metadata +160 -0
@@ -0,0 +1,39 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class ExternalURL
6
+
7
+ #
8
+ # Sets the arguments to its variables.
9
+ #
10
+ # @param [Hash] args the arguments that will be placed on each variable.
11
+ #
12
+ # @return [ExternalURL] an external url object.
13
+ #
14
+ def initialize(args = {})
15
+ args = Hash(args).with_indifferent_access
16
+
17
+ hsh = {
18
+ spotify: args[:spotify]
19
+ }
20
+
21
+ hsh = hsh.reject { |_, v| v.blank? }
22
+
23
+ if hsh.present?
24
+ # Generates the keys dynamically
25
+ hsh.each do |k, v|
26
+ key = k
27
+ value = v
28
+
29
+ eval("@#{key} = value")
30
+ class_eval { attr_reader key.to_sym }
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,27 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Follower
6
+
7
+ attr_reader :href, :total
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ #
14
+ # @return [Follower] a follower object.
15
+ #
16
+ def initialize(args = {})
17
+ args = Hash(args).with_indifferent_access
18
+
19
+ @href = args[:href]
20
+ @total = args[:total]
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,46 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Full::Album < Models::Album
6
+
7
+ attr_reader :artists, :copyrights, :external_ids, :popularity,
8
+ :release_date, :release_date_precision, :tracks
9
+
10
+ #
11
+ # Sets the arguments to its variables.
12
+ #
13
+ # @param [Hash] args the arguments that will be placed on each variable.
14
+ #
15
+ # @return [Full::Album] a full album object.
16
+ #
17
+ def initialize(args = {})
18
+ super(args)
19
+
20
+ args = Hash(args).with_indifferent_access
21
+
22
+ # Arrays
23
+ artists = Array(args[:artists]).map { |a| Artist.new(a) }
24
+ copyrights = Array(args[:copyrights]).map { |c| Copyright.new(c) }
25
+
26
+ # Objects
27
+ external_ids = Spotify::Models::ExternalID.new(args[:external_ids])
28
+
29
+ # Paging items
30
+ item = Spotify::Models::Simplified::Track
31
+ tracks = Spotify::Models::Paging.new(args[:tracks], item)
32
+
33
+ @artists = artists
34
+ @copyrights = copyrights
35
+ @external_ids = external_ids
36
+ @popularity = args[:popularity]
37
+ @release_date = args[:release_date]
38
+ @release_date_precision = args[:release_date_precision]
39
+ @tracks = tracks
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,37 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Full::Artist < Models::Artist
6
+
7
+ attr_reader :followers, :genres, :images, :popularity
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ #
14
+ # @return [Full::Artist] a full album object.
15
+ #
16
+ def initialize(args = {})
17
+ super(args)
18
+
19
+ args = Hash(args).with_indifferent_access
20
+
21
+ # Arrays
22
+ images = Array(args[:images]).map { |i| Spotify::Models::Image.new(i) }
23
+
24
+ # Objects
25
+ follower = Spotify::Models::Follower.new(args[:followers])
26
+
27
+ @followers = follower
28
+ @genres = args[:genres]
29
+ @images = images
30
+ @popularity = args[:popularity]
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,34 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Full::Track < Models::Track
6
+
7
+ attr_reader :album, :external_ids, :popularity
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ #
14
+ # @return [Full::Track] a full track object.
15
+ #
16
+ def initialize(args = {})
17
+ super(args)
18
+
19
+ args = Hash(args).with_indifferent_access
20
+
21
+ # Objects
22
+ album = Spotify::Models::Simplified::Album.new(args[:album])
23
+ external_ids = Spotify::Models::ExternalID.new(args[:external_ids])
24
+
25
+ @album = album
26
+ @external_ids = external_ids
27
+ @popularity = args[:popularity]
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,31 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Full::User < Models::User
6
+
7
+ attr_reader :birthdate, :country, :email, :product
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ #
14
+ # @return [Full::Artist] a full user object.
15
+ #
16
+ def initialize(args = {})
17
+ super(args)
18
+
19
+ args = Hash(args).with_indifferent_access
20
+
21
+ @birthdate = args[:birthdate]
22
+ @country = args[:country]
23
+ @email = args[:email]
24
+ @product = args[:product]
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,11 @@
1
+ module Spotify
2
+ module Models
3
+ module Full
4
+ end
5
+ end
6
+ end
7
+
8
+ require "spotify/models/full/album"
9
+ require "spotify/models/full/artist"
10
+ require "spotify/models/full/track"
11
+ require "spotify/models/full/user"
@@ -0,0 +1,28 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Image
6
+
7
+ attr_reader :height, :url, :width
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ #
14
+ # @return [Image] an image object.
15
+ #
16
+ def initialize(args = {})
17
+ args = Hash(args).with_indifferent_access
18
+
19
+ @height = args[:height]
20
+ @url = args[:url]
21
+ @width = args[:width]
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,38 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Paging
6
+
7
+ attr_reader :href, :items, :limit, :next, :offset, :previous, :total
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ # @param [Spotify::Model] klass the model's class that is represented on
14
+ # items's array.
15
+ #
16
+ # @return [Paging] a paging object containing the an array of the given
17
+ # model.
18
+ #
19
+ def initialize(args = {}, klass)
20
+ args = Hash(args).with_indifferent_access
21
+
22
+ # Arrays
23
+ items = Array(args[:items]).map { |i| klass.new(i) }
24
+
25
+ @href = args[:href]
26
+ @items = items
27
+ @limit = args[:limit]
28
+ @next = args[:next]
29
+ @offset = args[:offset]
30
+ @previous = args[:previous]
31
+ @total = args[:total]
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,24 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class PlaylistTrack
6
+
7
+ attr_reader :added_at, :added_by, :is_local, :track
8
+
9
+ def initialize(args = {})
10
+ args = args.with_indifferent_access
11
+
12
+ @is_local = args[:is_local]
13
+ @track = Track.new(args[:name])
14
+
15
+ # HACK: Using JSON while the other classes aren't available.
16
+ @added_at = args[:added_at]
17
+ @added_by = args[:added_by]
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,22 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class SavedAlbum
6
+
7
+ attr_reader :added_at, :album
8
+
9
+ def initialize(args = {})
10
+ args = args.with_indifferent_access
11
+
12
+ @album = Album.new(args[:name])
13
+
14
+ # HACK: Using JSON while the other classes aren't available.
15
+ @added_at = args[:added_at]
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class SavedTrack
6
+
7
+ attr_reader :added_at, :track
8
+
9
+ def initialize(args = {})
10
+ args = args.with_indifferent_access
11
+
12
+ @track = Track.new(args[:name])
13
+
14
+ # HACK: Using JSON while the other classes aren't available.
15
+ @added_at = args[:added_at]
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,23 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ #
6
+ # This class is kept only to provide a better visualization.
7
+ #
8
+ class Simplified::Album < Models::Album
9
+
10
+ #
11
+ # Sets the arguments to its variables.
12
+ #
13
+ # @param [Hash] args the arguments that will be placed on each variable.
14
+ #
15
+ # @return [Simplified::Album] a simplified album object.
16
+ #
17
+ def initialize(args = {}); super(args); end;
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ #
6
+ # This class is kept only to provide a better visualization.
7
+ #
8
+ class Simplified::Artist < Models::Artist
9
+
10
+ #
11
+ # Sets the arguments to its variables.
12
+ #
13
+ # @param [Hash] args the arguments that will be placed on each variable.
14
+ #
15
+ # @return [Simplified::Artist] a simplified artist object.
16
+ #
17
+ def initialize(args = {}); super(args); end;
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ #
6
+ # This class is kept only to provide a better visualization.
7
+ #
8
+ class Simplified::Track < Models::Track
9
+
10
+ #
11
+ # Sets the arguments to its variables.
12
+ #
13
+ # @param [Hash] args the arguments that will be placed on each variable.
14
+ #
15
+ # @return [Simplified::Track] a simplified track object.
16
+ #
17
+ def initialize(args = {}); super(args); end;
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ #
6
+ # This class is kept only to provide a better visualization.
7
+ #
8
+ class Simplified::User < Models::User
9
+
10
+ #
11
+ # Sets the arguments to its variables.
12
+ #
13
+ # @param [Hash] args the arguments that will be placed on each variable.
14
+ #
15
+ # @return [Simplified::User] a simplified user object.
16
+ #
17
+ def initialize(args = {}); super(args); end;
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,11 @@
1
+ module Spotify
2
+ module Models
3
+ module Simplified
4
+ end
5
+ end
6
+ end
7
+
8
+ require "spotify/models/simplified/album"
9
+ require "spotify/models/simplified/artist"
10
+ require "spotify/models/simplified/track"
11
+ require "spotify/models/simplified/user"
@@ -0,0 +1,50 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class Track
6
+
7
+ attr_reader :artists, :available_markets, :disc_number, :duration_ms,
8
+ :explicit, :external_urls, :href, :id, :is_playable, :linked_from,
9
+ :name, :preview_url, :track_number, :type, :uri
10
+
11
+ #
12
+ # Sets the arguments to its variables.
13
+ #
14
+ # @param [Hash] args the arguments that will be placed on each variable.
15
+ #
16
+ # @return [Track] a track object.
17
+ #
18
+ def initialize(args = {})
19
+ args = Hash(args).with_indifferent_access
20
+
21
+ # Arrays
22
+ artist = Spotify::Models::Simplified::Artist
23
+ artists = Array(args[:artists]).map { |a| artist.new(a) }
24
+
25
+ # Objects
26
+ external_urls = Spotify::Models::ExternalURL.new(args[:external_urls])
27
+ track_link = Spotify::Models::TrackLink.new(args[:linked_from])
28
+
29
+ @artists = artists
30
+ @available_markets = args[:available_markets]
31
+ @disc_number = args[:disc_number]
32
+ @duration_ms = args[:duration_ms]
33
+ @explicit = args[:explicit]
34
+ @external_urls = external_urls
35
+ @href = args[:href]
36
+ @id = args[:id]
37
+ @is_playable = args[:is_playable]
38
+ @linked_from = track_link
39
+ @name = args[:name]
40
+ @preview_url = args[:preview_url]
41
+ @track_number = args[:track_number]
42
+ @type = args[:type]
43
+ @uri = args[:uri]
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,33 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class TrackLink
6
+
7
+ attr_reader :external_urls, :href, :id, :type, :uri
8
+
9
+ #
10
+ # Sets the arguments to its variables.
11
+ #
12
+ # @param [Hash] args the arguments that will be placed on each variable.
13
+ #
14
+ # @return [TrackLink] a track link object.
15
+ #
16
+ def initialize(args = {})
17
+ args = Hash(args).with_indifferent_access
18
+
19
+ # Objects
20
+ external_urls = Spotify::Models::ExternalURL.new(args[:external_urls])
21
+
22
+ @external_urls = external_urls
23
+ @href = args[:href]
24
+ @id = args[:id]
25
+ @type = args[:type]
26
+ @uri = args[:uri]
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,41 @@
1
+ module Spotify
2
+
3
+ module Models
4
+
5
+ class User
6
+
7
+ attr_reader :display_name, :external_urls, :followers, :href,
8
+ :id, :images, :type, :uri
9
+
10
+ #
11
+ # Sets the arguments to its variables.
12
+ #
13
+ # @param [Hash] args the arguments that will be placed on each variable.
14
+ #
15
+ # @return [User] an user object.
16
+ #
17
+ def initialize(args = {})
18
+ args = Hash(args).with_indifferent_access
19
+
20
+ # Array
21
+ images = Array(args[:images]).map { |i| Spotify::Models::Image.new(i) }
22
+
23
+ # Objects
24
+ external_urls = Spotify::Models::ExternalURL.new(args[:external_urls])
25
+ follower = Spotify::Models::Follower.new(args[:followers])
26
+
27
+ @display_name = args[:display_name]
28
+ @external_urls = external_urls
29
+ @followers = follower
30
+ @href = args[:href]
31
+ @id = args[:id]
32
+ @images = images
33
+ @type = args[:type]
34
+ @uri = args[:uri]
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,27 @@
1
+ module Spotify
2
+ module Models
3
+ end
4
+ end
5
+
6
+ require "spotify/models/album"
7
+ require "spotify/models/artist"
8
+ require "spotify/models/copyright"
9
+ require "spotify/models/error"
10
+ require "spotify/models/external_id"
11
+ require "spotify/models/external_url"
12
+ require "spotify/models/follower"
13
+ require "spotify/models/image"
14
+ require "spotify/models/paging"
15
+ require "spotify/models/track"
16
+ require "spotify/models/track_link"
17
+ require "spotify/models/user"
18
+ # require "spotify/models/category"
19
+ # require "spotify/models/cursor"
20
+ # require "spotify/models/cursorbased_paging"
21
+ # require "spotify/models/paging"
22
+ # require "spotify/models/playlist_track"
23
+ # require "spotify/models/saved_album"
24
+ # require "spotify/models/saved_track"
25
+
26
+ require "spotify/models/full"
27
+ require "spotify/models/simplified"
data/lib/spotify.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "spotify/api"
2
+ require "spotify/models"
3
+ require "active_support/all"
4
+
5
+ module Spotify
6
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spotify/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spotify-ruby-api"
8
+ spec.version = Spotify::API::VERSION
9
+ spec.authors = ["Felipe Gadelha Ruoso"]
10
+ spec.email = ["felipe.gruoso@gmail.com"]
11
+
12
+ spec.summary = %q{Uses Spotify API in Ruby.}
13
+ spec.homepage = "https://github.com/felipegruoso/spotify-api"
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ # if spec.respond_to?(:metadata)
18
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+ # else
20
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ # end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.9"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+
32
+ spec.add_runtime_dependency "activesupport"
33
+ spec.add_runtime_dependency "json"
34
+ end