spotify 12.2.0 → 12.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +3 -1
  2. data/.rspec +5 -0
  3. data/CHANGELOG.md +45 -27
  4. data/Gemfile +4 -0
  5. data/README.markdown +52 -19
  6. data/Rakefile +16 -7
  7. data/lib/spotify.rb +109 -8
  8. data/lib/spotify/api.rb +61 -0
  9. data/lib/spotify/api/album.rb +14 -0
  10. data/lib/spotify/api/album_browse.rb +18 -0
  11. data/lib/spotify/api/artist.rb +10 -0
  12. data/lib/spotify/api/artist_browse.rb +23 -0
  13. data/lib/spotify/api/error.rb +6 -0
  14. data/lib/spotify/api/image.rb +16 -0
  15. data/lib/spotify/api/inbox.rb +9 -0
  16. data/lib/spotify/api/link.rb +25 -0
  17. data/lib/spotify/api/playlist.rb +39 -0
  18. data/lib/spotify/api/playlist_container.rb +23 -0
  19. data/lib/spotify/api/search.rb +27 -0
  20. data/lib/spotify/api/session.rb +46 -0
  21. data/lib/spotify/api/toplist_browse.rb +17 -0
  22. data/lib/spotify/api/track.rb +26 -0
  23. data/lib/spotify/api/user.rb +10 -0
  24. data/lib/spotify/defines.rb +109 -0
  25. data/lib/spotify/error.rb +62 -0
  26. data/lib/spotify/managed_pointer.rb +90 -0
  27. data/lib/spotify/objects.rb +16 -0
  28. data/lib/spotify/objects/album.rb +5 -0
  29. data/lib/spotify/objects/album_browse.rb +5 -0
  30. data/lib/spotify/objects/artist.rb +5 -0
  31. data/lib/spotify/objects/artist_browse.rb +5 -0
  32. data/lib/spotify/objects/image.rb +5 -0
  33. data/lib/spotify/objects/inbox.rb +5 -0
  34. data/lib/spotify/objects/link.rb +5 -0
  35. data/lib/spotify/objects/playlist.rb +5 -0
  36. data/lib/spotify/objects/playlist_container.rb +5 -0
  37. data/lib/spotify/objects/search.rb +5 -0
  38. data/lib/spotify/objects/session.rb +20 -0
  39. data/lib/spotify/objects/toplist_browse.rb +5 -0
  40. data/lib/spotify/objects/track.rb +5 -0
  41. data/lib/spotify/objects/user.rb +5 -0
  42. data/lib/spotify/structs.rb +46 -0
  43. data/lib/spotify/structs/audio_buffer_stats.rb +10 -0
  44. data/lib/spotify/structs/audio_format.rb +12 -0
  45. data/lib/spotify/structs/offline_sync_status.rb +24 -0
  46. data/lib/spotify/structs/playlist_callbacks.rb +32 -0
  47. data/lib/spotify/structs/playlist_container_callbacks.rb +14 -0
  48. data/lib/spotify/structs/session_callbacks.rb +48 -0
  49. data/lib/spotify/structs/session_config.rb +64 -0
  50. data/lib/spotify/structs/subscribers.rb +31 -0
  51. data/lib/spotify/types.rb +3 -0
  52. data/lib/spotify/types/image_id.rb +5 -0
  53. data/lib/spotify/types/nul_string.rb +51 -0
  54. data/lib/spotify/types/utf8_string.rb +24 -28
  55. data/lib/spotify/util.rb +36 -0
  56. data/lib/spotify/version.rb +7 -2
  57. data/spec/api-linux.xml +1887 -0
  58. data/spec/api-mac.xml +1886 -0
  59. data/spec/spec_helper.rb +20 -0
  60. data/spec/spotify/api_spec.rb +62 -0
  61. data/spec/spotify/defines_spec.rb +22 -0
  62. data/spec/spotify/enums_spec.rb +9 -0
  63. data/spec/spotify/managed_pointer_spec.rb +75 -0
  64. data/spec/spotify/spotify_spec.rb +69 -0
  65. data/spec/spotify/structs/session_config_spec.rb +20 -0
  66. data/spec/spotify/structs/struct_spec.rb +34 -0
  67. data/spec/spotify/structs/subscribers_spec.rb +31 -0
  68. data/spec/spotify/structs_spec.rb +19 -0
  69. data/spec/spotify/types/image_id_spec.rb +44 -0
  70. data/spec/spotify/types/nul_string_spec.rb +31 -0
  71. data/spec/spotify/types/utf8_string_spec.rb +24 -0
  72. data/spec/support/hook_spotify.rb +37 -0
  73. data/spec/support/spotify_util.rb +17 -0
  74. data/spotify.gemspec +6 -11
  75. metadata +99 -26
  76. data/lib/spotify/error_wrappers.rb +0 -165
  77. data/lib/spotify/functions.rb +0 -755
  78. data/lib/spotify/gc_wrappers.rb +0 -105
  79. data/lib/spotify/types/pointer.rb +0 -59
  80. data/spec/spotify_spec.rb +0 -467
data/.gitignore CHANGED
@@ -4,4 +4,6 @@
4
4
  Gemfile.lock
5
5
  pkg/*
6
6
  doc/
7
- .yardoc
7
+ .yardoc
8
+ .rbx
9
+ *.rbc
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ -fp
2
+ -Ilib
3
+ -I.
4
+ --colour
5
+ --require spec/spec_helper
@@ -1,3 +1,20 @@
1
+ [v12.3.0][]
2
+ -----------
3
+ Lots of internal and external changes. You could almost say it’s a rewrite.
4
+
5
+ - [0ee03487a] added a Spotify::ManagedPointer (new Spotify::AutoPointer) for every object
6
+ - [0ee03487a] all functions now always return auto pointers
7
+ - [a88920c22] it’s now possible to create a Spotify::Subscriber with a count
8
+ - [aa26b1ed2] have all callbacks retain their pointer
9
+ - [a72469b04] use new libspotify gem for attaching libspotify dynamic library
10
+ - renamed the repository from libspotify-ruby to spotify
11
+ - [345b47472] all structs can now be initialized with a hash
12
+ - [e54f1c806] SessionConfig now accepts string as application key
13
+ - [37f1f883d] Added Spotify.try(method), and removed bang-calling notation
14
+ - [6e51b6c4e] Added a mutex around every Spotify API call
15
+
16
+ I might’ve missed something. Read the commits for the nitty gritty.
17
+
1
18
  [v12.2.0][]
2
19
  -----------
3
20
  - fix SessionConfig missing ca_certs_filename struct field on Linux
@@ -130,30 +147,31 @@ v0.0.0
130
147
  ------
131
148
  - release to register rubygems.org name
132
149
 
133
- [v12.2.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v12.0.3...v12.2.0
134
- [v12.0.3]: https://github.com/Burgestrand/libspotify-ruby/compare/v12.0.2...v12.0.3
135
- [v12.0.2]: https://github.com/Burgestrand/libspotify-ruby/compare/v12.0.1...v12.0.2
136
- [v12.0.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v12.0.0...v12.0.1
137
- [v12.0.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v11.0.2...v12.0.0
138
- [v11.0.2]: https://github.com/Burgestrand/libspotify-ruby/compare/v11.0.1...v11.0.2
139
- [v11.0.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v11.0.0...v11.0.1
140
- [v11.0.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.3.0...v11.0.0
141
- [v10.3.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.2.2...v10.3.0
142
- [v10.2.2]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.2.1...v10.2.2
143
- [v10.2.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.2.0...v10.2.1
144
- [v10.2.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.1.1...v10.2.0
145
- [v10.1.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.1.0...v10.1.1
146
- [v10.1.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v10.0.0...v10.1.0
147
- [v10.0.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v9.1.0...v10.0.0
148
- [v9.1.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v9.0.1...v9.1.0
149
- [v9.0.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v9.0.0...v9.0.1
150
- [v9.0.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v8.0.5...v9.0.0
151
- [v8.0.5]: https://github.com/Burgestrand/libspotify-ruby/compare/v8.0.2...v8.0.5
152
- [v8.0.2]: https://github.com/Burgestrand/libspotify-ruby/compare/v8.0.1...v8.0.2
153
- [v8.0.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v8.0.0...v8.0.1
154
- [v8.0.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v7.0.4...v8.0.0
155
- [v7.0.4]: https://github.com/Burgestrand/libspotify-ruby/compare/v7.0.3...v7.0.4
156
- [v7.0.3]: https://github.com/Burgestrand/libspotify-ruby/compare/v7.0.2...v7.0.3
157
- [v7.0.2]: https://github.com/Burgestrand/libspotify-ruby/compare/v7.0.1...v7.0.2
158
- [v7.0.1]: https://github.com/Burgestrand/libspotify-ruby/compare/v7.0.0...v7.0.1
159
- [v7.0.0]: https://github.com/Burgestrand/libspotify-ruby/compare/v0.0.0...v7.0.0
150
+ [v12.3.0]: https://github.com/Burgestrand/spotify/compare/v12.2.0...v12.3.0
151
+ [v12.2.0]: https://github.com/Burgestrand/spotify/compare/v12.0.3...v12.2.0
152
+ [v12.0.3]: https://github.com/Burgestrand/spotify/compare/v12.0.2...v12.0.3
153
+ [v12.0.2]: https://github.com/Burgestrand/spotify/compare/v12.0.1...v12.0.2
154
+ [v12.0.1]: https://github.com/Burgestrand/spotify/compare/v12.0.0...v12.0.1
155
+ [v12.0.0]: https://github.com/Burgestrand/spotify/compare/v11.0.2...v12.0.0
156
+ [v11.0.2]: https://github.com/Burgestrand/spotify/compare/v11.0.1...v11.0.2
157
+ [v11.0.1]: https://github.com/Burgestrand/spotify/compare/v11.0.0...v11.0.1
158
+ [v11.0.0]: https://github.com/Burgestrand/spotify/compare/v10.3.0...v11.0.0
159
+ [v10.3.0]: https://github.com/Burgestrand/spotify/compare/v10.2.2...v10.3.0
160
+ [v10.2.2]: https://github.com/Burgestrand/spotify/compare/v10.2.1...v10.2.2
161
+ [v10.2.1]: https://github.com/Burgestrand/spotify/compare/v10.2.0...v10.2.1
162
+ [v10.2.0]: https://github.com/Burgestrand/spotify/compare/v10.1.1...v10.2.0
163
+ [v10.1.1]: https://github.com/Burgestrand/spotify/compare/v10.1.0...v10.1.1
164
+ [v10.1.0]: https://github.com/Burgestrand/spotify/compare/v10.0.0...v10.1.0
165
+ [v10.0.0]: https://github.com/Burgestrand/spotify/compare/v9.1.0...v10.0.0
166
+ [v9.1.0]: https://github.com/Burgestrand/spotify/compare/v9.0.1...v9.1.0
167
+ [v9.0.1]: https://github.com/Burgestrand/spotify/compare/v9.0.0...v9.0.1
168
+ [v9.0.0]: https://github.com/Burgestrand/spotify/compare/v8.0.5...v9.0.0
169
+ [v8.0.5]: https://github.com/Burgestrand/spotify/compare/v8.0.2...v8.0.5
170
+ [v8.0.2]: https://github.com/Burgestrand/spotify/compare/v8.0.1...v8.0.2
171
+ [v8.0.1]: https://github.com/Burgestrand/spotify/compare/v8.0.0...v8.0.1
172
+ [v8.0.0]: https://github.com/Burgestrand/spotify/compare/v7.0.4...v8.0.0
173
+ [v7.0.4]: https://github.com/Burgestrand/spotify/compare/v7.0.3...v7.0.4
174
+ [v7.0.3]: https://github.com/Burgestrand/spotify/compare/v7.0.2...v7.0.3
175
+ [v7.0.2]: https://github.com/Burgestrand/spotify/compare/v7.0.1...v7.0.2
176
+ [v7.0.1]: https://github.com/Burgestrand/spotify/compare/v7.0.0...v7.0.1
177
+ [v7.0.0]: https://github.com/Burgestrand/spotify/compare/v0.0.0...v7.0.0
data/Gemfile CHANGED
@@ -1,2 +1,6 @@
1
1
  source :rubygems
2
2
  gemspec
3
+
4
+ gem 'pry'
5
+ gem 'yard'
6
+ gem 'redcarpet'
@@ -1,39 +1,72 @@
1
- Ruby FFI bindings for [libspotify][]
2
- ====================================
1
+ Ruby bindings for [libspotify][] ([![Build Status](https://secure.travis-ci.org/Burgestrand/spotify.png?branch=master)](http://travis-ci.org/Burgestrand/spotify))
2
+ ================================
3
3
 
4
4
  The libspotify C API package allows third party developers to write
5
5
  applications that utilize the Spotify music streaming service.
6
6
 
7
- [Spotify][] is a really nice music streaming service, and being able to interact with it in an API is awesome. However, because libspotify is a C library, writing applications with it is cumbersome and error-prone compared to doing it in Ruby. As I found myself needing to do this one day, knowing I’d rather not be writing it in C, this gem was born.
7
+ [Spotify][] is a really nice music streaming service, and being able to interact
8
+ with it in an API is awesome. libspotify itself is however written in C, making
9
+ it unavailable or cumbersome to use for many developers.
8
10
 
9
- Spotify, the gem, is a thin layer of Ruby atop the [libspotify][] C library. It allows developers to use libspotify without writing a line of C, thanks to [Ruby FFI](https://rubygems.org/gems/ffi). Do note that there is no sugar-coating, and no attempts of abstraction will be made.
11
+ This project aims to allow Ruby developers access to all of the libspotify C API,
12
+ without needing to reach down to C. However, to use this library to it’s full extent
13
+ you will need to learn how to use the Ruby FFI API.
10
14
 
11
- You want easy-to-use Ruby bindings for libspotify?
15
+ The Spotify gem has:
16
+
17
+ - [100% API coverage][], including callback support. You’ll be able to use any function from the libspotify library.
18
+ - [Automatic garbage collection][]. Piggybacking on Ruby’s GC to manage pointer lifecycle.
19
+ - [Parallell function call protection][]. libspotify is not thread-safe, but Spotify protects you.
20
+ - [Type conversion][]. Special pointers for every Spotify type.
21
+
22
+ [100% API coverage]: http://rdoc.info/github/Burgestrand/spotify/master/Spotify/API
23
+ [Automatic garbage collection]: http://rdoc.info/github/Burgestrand/spotify/master/Spotify/ManagedPointer
24
+ [Parallell function call protection]: http://rdoc.info/github/Burgestrand/spotify/master/Spotify#method_missing-class_method
25
+ [Type conversion]: http://rdoc.info/github/Burgestrand/spotify/master/Spotify/ManagedPointer
26
+
27
+ The Spotify gem is aimed at experienced developers
12
28
  --------------------------------------------------
13
- Then you should check out [Hallon][]! While libspotify-ruby is just the simplest bindings to libspotify possible, Hallon works really hard to make libspotify a joy to use in Ruby.
29
+ As the raw libspotify API is exposed, the Spotify gem is best coupled with a supporting
30
+ library. This library would take a more focused approach to which kind of applications
31
+ you can write using it. The Spotify gem itself, however, has very few opinions.
14
32
 
15
- Finally, if you, for some reason, are having trouble deciding if you should use libspotify-ruby or Hallon, you should probably use Hallon.
33
+ Known supporting libraries:
16
34
 
17
- (anecdotal note: this code base was previously a part of Hallon, but I decided to extract it and make a gem out of it)
35
+ - [Hallon](https://github.com/Burgestrand/Hallon), the original. Currently Hallon is simply
36
+ a more convenient Spotify gem, written on top of the Spotify gem. It is diverging from its
37
+ previous path, now towards a more focused and opinionated framework. If you’re unsure of
38
+ what to use, start with the Hallon gem!
18
39
 
19
- [libspotify]: http://developer.spotify.com/en/libspotify/overview/
20
- [Spotify]: https://www.spotify.com/
21
- [Hallon]: https://github.com/Burgestrand/Hallon
40
+ Do not let this stop you! Despite my harsh words the Spotify API is well suited for experimentation,
41
+ and it can be awfully fun to play with. If you need any assitance feel free to post a message
42
+ on the mailing list: [ruby-hallon@googlegroups.com][] (<https://groups.google.com/d/forum/ruby-hallon>).
43
+
44
+ Manually installing libspotify
45
+ ------------------------------
46
+ By default, Spotify uses [the libspotify gem](https://rubygems.org/gems/libspotify) which means you do
47
+ not need to install libspotify yourself. However, if your platform is not supported by the libspotify
48
+ gem you will need to install libspotify yourself.
49
+
50
+ Please note, that if your platform is not supported by the libspotify gem I’d very much appreciate it
51
+ if you could create an issue on [libspotify gem issue tracker](https://github.com/Burgestrand/libspotify/issues)
52
+ so I can fix the build for your platform.
22
53
 
23
- Need help installing libspotify?
24
- --------------------------------
25
- You’re in luck! I’ve got you covered in Hallon’s wiki: [How to install libspotify](https://github.com/Burgestrand/Hallon/wiki/How-to-install-libspotify)!
54
+ While you’re waiting for the issue to resolve you could install libspotify manually. I’ve provided
55
+ instructions on how to do this in Hallon’s wiki: [How to install libspotify](https://github.com/Burgestrand/Hallon/wiki/How-to-install-libspotify)!
26
56
 
27
57
  A note about versioning scheme
28
58
  ------------------------------
29
59
  Given a version `X.Y.Z`, each segment corresponds to:
30
60
 
31
- - X reflects supported libspotify version (12.1.45 => 12)
32
- - Y is increased **only** on non-backwards-compatible bug fixes or feature additions
33
- - Z is increased on backwards-compatible bug fixes or feature additions
34
-
35
- When X increases (support for new libspotify versions) there are **no guarantees** of backwards-compatibility.
61
+ - X reflects supported libspotify version (12.1.45 => 12). There are __no guarantees__ of backwards-compatibility!
62
+ - Y(major).Z(minor) follows [semantic versioning (semver.org)][]. Y is for backwards-**incompatible** changes, Z is for backwards-**compatible** changes.
36
63
 
37
64
  License
38
65
  -------
39
66
  X11 license, see the LICENSE document for details.
67
+
68
+ [semantic versioning (semver.org)]: http://semver.org/
69
+ [ruby-hallon@googlegroups.com]: mailto:ruby-hallon@googlegroups.com
70
+ [libspotify]: http://developer.spotify.com/en/libspotify/overview/
71
+ [Spotify]: https://www.spotify.com/
72
+ [Hallon]: https://github.com/Burgestrand/Hallon
data/Rakefile CHANGED
@@ -5,9 +5,20 @@ rescue LoadError
5
5
  # do not require bundler rake tasks
6
6
  end
7
7
 
8
+ begin
9
+ require 'yard'
10
+ YARD::Rake::YardocTask.new('yard:doc') do |task|
11
+ task.options = ['--no-stats']
12
+ end
13
+
14
+ task 'yard:stats' do
15
+ YARD::CLI::Stats.run('--list-undoc')
16
+ end
8
17
 
9
- require 'yard'
10
- YARD::Rake::YardocTask.new
18
+ task :yard => ['yard:doc', 'yard:stats']
19
+ rescue LoadError
20
+ puts "WARN: YARD not available. You may install documentation dependencies via bundler."
21
+ end
11
22
 
12
23
  desc "re-generate spec/api.h.xml"
13
24
  task :gen do
@@ -18,14 +29,12 @@ task :console do
18
29
  exec "irb", "-Ilib", "-rspotify"
19
30
  end
20
31
 
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test_mac) do |spec|
23
- spec.pattern = 'spec/*_spec.rb'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:test_mac) do |spec|
24
34
  spec.ruby_opts = ['-r ./spec/mac-platform']
25
35
  end
26
36
 
27
- Rake::TestTask.new(:test_linux) do |spec|
28
- spec.pattern = 'spec/*_spec.rb'
37
+ RSpec::Core::RakeTask.new(:test_linux) do |spec|
29
38
  spec.ruby_opts = ['-r ./spec/linux-platform']
30
39
  end
31
40
 
@@ -1,11 +1,112 @@
1
- # coding: utf-8
2
- require 'spotify/version'
1
+ # encoding: utf-8
3
2
  require 'ffi'
3
+ require 'libspotify'
4
+ require 'monitor'
5
+
6
+ # Spotify module allows you to place calls against the Spotify::API.
7
+ #
8
+ # @see method_missing method_missing on calling the API
9
+ # @see Spotify::API Spotify::API on available libspotify methods
10
+ # @see http://developer.spotify.com/en/libspotify/docs/ official libspotify documentation
11
+ module Spotify
12
+ # API is the class which has all libspotify functions attached.
13
+ #
14
+ # All functions are attached as both instance methods and class methods, mainly
15
+ # because that’s how FFI works it’s magic with attach_function. However, as this
16
+ # is a class it allows to be instantiated.
17
+ #
18
+ # @note The API is private because this class is an implementation detail.
19
+ #
20
+ # @note You should never call any Spotify::API.method() directly, but instead
21
+ # you should call them via Spotify.method(). libspotify is not thread-safe,
22
+ # but it is documented to be okay to call the API from multiple threads *if*
23
+ # you only call one function at a time, which is ensured by the lock in the
24
+ # Spotify module.
25
+ #
26
+ # @api private
27
+ class API
28
+ extend FFI::Library
29
+
30
+ begin
31
+ ffi_lib [LIBSPOTIFY_BIN, 'libspotify', '/Library/Frameworks/libspotify.framework/libspotify']
32
+ rescue LoadError
33
+ puts <<-ERROR.gsub(/^ */, '')
34
+ Failed to load the `libspotify` library. It is possible that the libspotify gem
35
+ does not exist for your platform, in which case you’ll need to install it manually.
36
+
37
+ For manual installation instructions, please see:
38
+ https://github.com/Burgestrand/Hallon/wiki/How-to-install-libspotify
39
+ ERROR
40
+ raise
41
+ end
42
+ end
4
43
 
5
- require 'spotify/types/pointer'
6
- require 'spotify/types/utf8_string'
7
- require 'spotify/types/image_id'
44
+ @__api__ = Spotify::API
45
+ @__api__.extend(MonitorMixin)
8
46
 
9
- require 'spotify/functions'
10
- require 'spotify/gc_wrappers'
11
- require 'spotify/error_wrappers'
47
+ class << self
48
+ # Like send, but raises an error if the method returns a non-OK error.
49
+ #
50
+ # @example calling a method that returns an error
51
+ # Spotify.relogin(session) # => :invalid_indata
52
+ # Spotify.try(:relogin, session) # => raises Spotify::Error
53
+ #
54
+ # @note Works for non-error returning methods as well, it just does
55
+ # not do anything interesting.
56
+ #
57
+ # @param [#to_s] name
58
+ # @param args
59
+ # @raise [Spotify::Error] if an error other than :ok is returned
60
+ def try(name, *args, &block)
61
+ public_send(name, *args, &block).tap do |error|
62
+ error, symbol = Spotify::Error.disambiguate(error)
63
+ next if symbol.nil?
64
+ next if symbol == :ok
65
+ raise Error.new(symbol)
66
+ end
67
+ end
68
+
69
+ # Asks the underlying Spotify API if it responds to `name`.
70
+ #
71
+ # @example
72
+ # Spotify.respond_to?(:error_message) # => true
73
+ #
74
+ # @example retrieving a method handle
75
+ # Spotify.metod(:error_message) # => #<Method: Spotify.error_message>
76
+ #
77
+ # @param [Symbol, String] name
78
+ # @param [Boolean] include_private
79
+ # @return [Boolean] true if the API supports the given method.
80
+ def respond_to_missing?(name, include_private = false)
81
+ @__api__.synchronize do
82
+ @__api__.respond_to?(name, include_private)
83
+ end
84
+ end
85
+
86
+ # Calls the any method on the underlying {Spotify::API}.
87
+ #
88
+ # @example calling the API
89
+ # Spotify.link_create_from_string("spotify:user:burgestrand") # => #<Spotify::Link address=0x0deadbeef>
90
+ #
91
+ # @note Spotify protects all calls to {Spotify::API} with a lock, so it is
92
+ # considered safe to call the API from different threads. The lock
93
+ # is re-entrant.
94
+ #
95
+ # @param [Symbol, String] name
96
+ # @param [Object, …] args
97
+ def method_missing(name, *args, &block)
98
+ @__api__.synchronize do
99
+ @__api__.send(name, *args, &block)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ require 'spotify/version'
106
+ require 'spotify/util'
107
+ require 'spotify/types'
108
+ require 'spotify/error'
109
+ require 'spotify/objects'
110
+ require 'spotify/defines'
111
+ require 'spotify/structs'
112
+ require 'spotify/api'
@@ -0,0 +1,61 @@
1
+ module Spotify
2
+ class API
3
+ # @!macro [attach] attach_function
4
+ # @!method $1(…)
5
+ # @!scope class
6
+ # @!scope instance
7
+ # @example method signature (shows arguments)
8
+ # $*
9
+ # @return [${-1}]
10
+ #
11
+ # Overloaded to ensure all methods are defined as blocking,
12
+ # and they return a managed pointer with the correct refcount.
13
+ #
14
+ # @param [#to_s] name function name sans `sp_` prefix.
15
+ # @param [Array] args
16
+ # @param [Object] returns
17
+ def self.attach_function(c_name = nil, name, args, returns)
18
+ if returns.respond_to?(:retaining_class) && name !~ /create/
19
+ returns = returns.retaining_class
20
+ end
21
+
22
+ options = { :blocking => true }
23
+ c_name ||= "sp_#{name}"
24
+ super(name, c_name, args, returns, options)
25
+ end
26
+
27
+ # Now, make sure we have the right libspotify version.
28
+
29
+ # @!group Miscellaneous
30
+
31
+ # @see Spotify::API_BUILD
32
+ attach_function :build_id, [], UTF8String
33
+
34
+ # @!endgroup
35
+ end
36
+
37
+ # @return [String] libspotify build ID.
38
+ API_BUILD = Spotify.build_id
39
+
40
+ # No support yet for "similar" versions, so it’s a hard requirement
41
+ # on the libspotify version. It *must* be the same, even patch version.
42
+ unless API_BUILD.include?(Spotify::API_VERSION)
43
+ raise LoadError, "libspotify v#{build_id} is incompatible with ruby spotify v#{VERSION}(#{API_VERSION})"
44
+ end
45
+ end
46
+
47
+ require 'spotify/api/album'
48
+ require 'spotify/api/album_browse'
49
+ require 'spotify/api/artist'
50
+ require 'spotify/api/artist_browse'
51
+ require 'spotify/api/error'
52
+ require 'spotify/api/image'
53
+ require 'spotify/api/inbox'
54
+ require 'spotify/api/link'
55
+ require 'spotify/api/playlist'
56
+ require 'spotify/api/playlist_container'
57
+ require 'spotify/api/search'
58
+ require 'spotify/api/session'
59
+ require 'spotify/api/toplist_browse'
60
+ require 'spotify/api/track'
61
+ require 'spotify/api/user'
@@ -0,0 +1,14 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Album
4
+ attach_function :album_is_loaded, [ Album ], :bool
5
+ attach_function :album_is_available, [ Album ], :bool
6
+ attach_function :album_artist, [ Album ], Artist
7
+ attach_function :album_cover, [ Album, :image_size ], ImageID
8
+ attach_function :album_name, [ Album ], UTF8String
9
+ attach_function :album_year, [ Album ], :int
10
+ attach_function :album_type, [ Album ], :albumtype
11
+ attach_function :album_add_ref, [ Album ], :error
12
+ attach_function :album_release, [ Album ], :error
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Spotify
2
+ class API
3
+ # @!group AlbumBrowse
4
+ attach_function :albumbrowse_create, [ Session, Album, :albumbrowse_complete_cb, :userdata ], AlbumBrowse
5
+ attach_function :albumbrowse_is_loaded, [ AlbumBrowse ], :bool
6
+ attach_function :albumbrowse_error, [ AlbumBrowse ], :error
7
+ attach_function :albumbrowse_album, [ AlbumBrowse ], Album
8
+ attach_function :albumbrowse_artist, [ AlbumBrowse ], Artist
9
+ attach_function :albumbrowse_num_copyrights, [ AlbumBrowse ], :int
10
+ attach_function :albumbrowse_copyright, [ AlbumBrowse, :int ], UTF8String
11
+ attach_function :albumbrowse_num_tracks, [ AlbumBrowse ], :int
12
+ attach_function :albumbrowse_track, [ AlbumBrowse, :int ], Track
13
+ attach_function :albumbrowse_review, [ AlbumBrowse ], UTF8String
14
+ attach_function :albumbrowse_backend_request_duration, [ AlbumBrowse ], :int
15
+ attach_function :albumbrowse_add_ref, [ AlbumBrowse ], :error
16
+ attach_function :albumbrowse_release, [ AlbumBrowse ], :error
17
+ end
18
+ end