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
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ describe Spotify::UTF8String do
3
+ module C
4
+ extend FFI::Library
5
+ ffi_lib [FFI::CURRENT_PROCESS, 'c']
6
+
7
+ attach_function :strncpy, [ :pointer, Spotify::UTF8String, :size_t ], Spotify::UTF8String
8
+ end
9
+
10
+ let(:char) do
11
+ char = "\xC4"
12
+ char.force_encoding('ISO-8859-1')
13
+ char
14
+ end
15
+
16
+ it "should convert any strings to UTF-8 before reading and writing" do
17
+ dest = FFI::MemoryPointer.new(:char, 3) # two bytes for the ä, one for the NULL
18
+ result = C.strncpy(dest, char, 3)
19
+
20
+ result.encoding.should eq Encoding::UTF_8
21
+ result.should eq "Ä"
22
+ result.bytesize.should eq 2
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Hooks into FFI for extra introspection during testing.
3
+ #
4
+ require 'ffi'
5
+
6
+ $attached_methods ||= {}
7
+
8
+ module SpotifyHook
9
+ # stores function information that we can assert on later
10
+ def attach_function(name, func, arguments, returns, options)
11
+ args = [name, func, arguments.dup, returns, options]
12
+ hargs = [:name, :func, :args, :returns].zip args
13
+ $attached_methods[name.to_s] = hash = Hash[hargs]
14
+
15
+ super
16
+ end
17
+ end
18
+
19
+ module Spotify
20
+ class API
21
+ # so that Spotify cannot extend again
22
+ extend FFI::Library
23
+ extend SpotifyHook
24
+
25
+ # allows us to test for Mac/Linux independently
26
+ FFI::Platform::OS.replace(ENV.fetch('RUBY_PLATFORM') do
27
+ puts "[WARN] Tests running with default ruby platform, #{::FFI::Platform::OS}, please be"
28
+ puts "[WARN] specific in which platform to target by setting ENV[RUBY_PLATFORM]"
29
+ puts "(warnings coming from #{__FILE__}:#{__LINE__})"
30
+ puts
31
+ ::FFI::Platform::OS
32
+ end)
33
+ end
34
+ end
35
+
36
+ # All is in place, load it up
37
+ require 'spotify'
@@ -0,0 +1,17 @@
1
+ module Spotify
2
+ # used to find the actual type of a thing
3
+ def self.resolve_type(type)
4
+ if type.is_a?(Class) and type <= Spotify::ManagedPointer
5
+ type
6
+ else
7
+ type = Spotify::API.find_type(type)
8
+ type = type.type if type.respond_to?(:type)
9
+ type
10
+ end
11
+ end
12
+
13
+ # @return [Array<FFI::Struct>] all structs in Spotify namespace
14
+ def self.structs
15
+ constants.select { |x| const_get(x).is_a?(Class) && const_get(x) < FFI::Struct }
16
+ end
17
+ end
@@ -3,14 +3,9 @@ require './lib/spotify/version'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'spotify'
6
- gem.summary = 'Bare-bones Ruby bindings for libspotify'
7
- gem.description = <<-DESC
8
- Spotify for Ruby is a primitive wrapper around libspotify using Ruby FFI.
9
- If all you want is libspotify for Ruby, you should probably use at Hallon
10
- instead: https://rubygems.org/gems/hallon
11
- DESC
6
+ gem.summary = 'Low-level Ruby bindings for libspotify'
12
7
 
13
- gem.homepage = 'https://github.com/Burgestrand/libspotify-ruby'
8
+ gem.homepage = 'https://github.com/Burgestrand/spotify'
14
9
  gem.authors = ["Kim Burgestrand"]
15
10
  gem.email = ['kim@burgestrand.se']
16
11
  gem.license = 'X11 License'
@@ -20,13 +15,13 @@ Gem::Specification.new do |gem|
20
15
  gem.executables = []
21
16
  gem.require_paths = ["lib"]
22
17
 
23
- gem.version = Spotify::VERSION
24
- gem.platform = Gem::Platform::RUBY
18
+ gem.version = Spotify::VERSION
19
+ gem.platform = Gem::Platform::RUBY
25
20
  gem.required_ruby_version = '>= 1.9'
26
21
 
27
22
  gem.add_dependency 'ffi', ['~> 1.0', '>= 1.0.11']
23
+ gem.add_dependency 'libspotify', '~> 12.1.51'
28
24
  gem.add_development_dependency 'rake'
29
- gem.add_development_dependency 'yard'
30
25
  gem.add_development_dependency 'rbgccxml'
31
- gem.add_development_dependency 'minitest', '~> 3.0'
26
+ gem.add_development_dependency 'rspec'
32
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.2.0
4
+ version: 12.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -34,23 +34,23 @@ dependencies:
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.0.11
36
36
  - !ruby/object:Gem::Dependency
37
- name: rake
37
+ name: libspotify
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
43
+ version: 12.1.51
44
+ type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  none: false
48
48
  requirements:
49
- - - ! '>='
49
+ - - ~>
50
50
  - !ruby/object:Gem::Version
51
- version: '0'
51
+ version: 12.1.51
52
52
  - !ruby/object:Gem::Dependency
53
- name: yard
53
+ name: rake
54
54
  requirement: !ruby/object:Gem::Requirement
55
55
  none: false
56
56
  requirements:
@@ -82,24 +82,22 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: minitest
85
+ name: rspec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements:
89
- - - ~>
89
+ - - ! '>='
90
90
  - !ruby/object:Gem::Version
91
- version: '3.0'
91
+ version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
- - - ~>
97
+ - - ! '>='
98
98
  - !ruby/object:Gem::Version
99
- version: '3.0'
100
- description: ! " Spotify for Ruby is a primitive wrapper around libspotify using
101
- Ruby FFI.\n If all you want is libspotify for Ruby, you should probably use at
102
- Hallon\n instead: https://rubygems.org/gems/hallon\n"
99
+ version: '0'
100
+ description:
103
101
  email:
104
102
  - kim@burgestrand.se
105
103
  executables: []
@@ -108,6 +106,7 @@ extra_rdoc_files: []
108
106
  files:
109
107
  - .gemtest
110
108
  - .gitignore
109
+ - .rspec
111
110
  - .travis.yml
112
111
  - CHANGELOG.md
113
112
  - Gemfile
@@ -115,20 +114,78 @@ files:
115
114
  - README.markdown
116
115
  - Rakefile
117
116
  - lib/spotify.rb
118
- - lib/spotify/error_wrappers.rb
119
- - lib/spotify/functions.rb
120
- - lib/spotify/gc_wrappers.rb
117
+ - lib/spotify/api.rb
118
+ - lib/spotify/api/album.rb
119
+ - lib/spotify/api/album_browse.rb
120
+ - lib/spotify/api/artist.rb
121
+ - lib/spotify/api/artist_browse.rb
122
+ - lib/spotify/api/error.rb
123
+ - lib/spotify/api/image.rb
124
+ - lib/spotify/api/inbox.rb
125
+ - lib/spotify/api/link.rb
126
+ - lib/spotify/api/playlist.rb
127
+ - lib/spotify/api/playlist_container.rb
128
+ - lib/spotify/api/search.rb
129
+ - lib/spotify/api/session.rb
130
+ - lib/spotify/api/toplist_browse.rb
131
+ - lib/spotify/api/track.rb
132
+ - lib/spotify/api/user.rb
133
+ - lib/spotify/defines.rb
134
+ - lib/spotify/error.rb
135
+ - lib/spotify/managed_pointer.rb
136
+ - lib/spotify/objects.rb
137
+ - lib/spotify/objects/album.rb
138
+ - lib/spotify/objects/album_browse.rb
139
+ - lib/spotify/objects/artist.rb
140
+ - lib/spotify/objects/artist_browse.rb
141
+ - lib/spotify/objects/image.rb
142
+ - lib/spotify/objects/inbox.rb
143
+ - lib/spotify/objects/link.rb
144
+ - lib/spotify/objects/playlist.rb
145
+ - lib/spotify/objects/playlist_container.rb
146
+ - lib/spotify/objects/search.rb
147
+ - lib/spotify/objects/session.rb
148
+ - lib/spotify/objects/toplist_browse.rb
149
+ - lib/spotify/objects/track.rb
150
+ - lib/spotify/objects/user.rb
151
+ - lib/spotify/structs.rb
152
+ - lib/spotify/structs/audio_buffer_stats.rb
153
+ - lib/spotify/structs/audio_format.rb
154
+ - lib/spotify/structs/offline_sync_status.rb
155
+ - lib/spotify/structs/playlist_callbacks.rb
156
+ - lib/spotify/structs/playlist_container_callbacks.rb
157
+ - lib/spotify/structs/session_callbacks.rb
158
+ - lib/spotify/structs/session_config.rb
159
+ - lib/spotify/structs/subscribers.rb
160
+ - lib/spotify/types.rb
121
161
  - lib/spotify/types/image_id.rb
122
- - lib/spotify/types/pointer.rb
162
+ - lib/spotify/types/nul_string.rb
123
163
  - lib/spotify/types/utf8_string.rb
164
+ - lib/spotify/util.rb
124
165
  - lib/spotify/version.rb
125
166
  - spec/api-linux.h
167
+ - spec/api-linux.xml
126
168
  - spec/api-mac.h
169
+ - spec/api-mac.xml
127
170
  - spec/linux-platform.rb
128
171
  - spec/mac-platform.rb
129
- - spec/spotify_spec.rb
172
+ - spec/spec_helper.rb
173
+ - spec/spotify/api_spec.rb
174
+ - spec/spotify/defines_spec.rb
175
+ - spec/spotify/enums_spec.rb
176
+ - spec/spotify/managed_pointer_spec.rb
177
+ - spec/spotify/spotify_spec.rb
178
+ - spec/spotify/structs/session_config_spec.rb
179
+ - spec/spotify/structs/struct_spec.rb
180
+ - spec/spotify/structs/subscribers_spec.rb
181
+ - spec/spotify/structs_spec.rb
182
+ - spec/spotify/types/image_id_spec.rb
183
+ - spec/spotify/types/nul_string_spec.rb
184
+ - spec/spotify/types/utf8_string_spec.rb
185
+ - spec/support/hook_spotify.rb
186
+ - spec/support/spotify_util.rb
130
187
  - spotify.gemspec
131
- homepage: https://github.com/Burgestrand/libspotify-ruby
188
+ homepage: https://github.com/Burgestrand/spotify
132
189
  licenses:
133
190
  - X11 License
134
191
  post_install_message:
@@ -149,17 +206,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
206
  version: '0'
150
207
  segments:
151
208
  - 0
152
- hash: -1782095507785202137
209
+ hash: -1786637740749892819
153
210
  requirements: []
154
211
  rubyforge_project:
155
212
  rubygems_version: 1.8.24
156
213
  signing_key:
157
214
  specification_version: 3
158
- summary: Bare-bones Ruby bindings for libspotify
215
+ summary: Low-level Ruby bindings for libspotify
159
216
  test_files:
160
217
  - spec/api-linux.h
218
+ - spec/api-linux.xml
161
219
  - spec/api-mac.h
220
+ - spec/api-mac.xml
162
221
  - spec/linux-platform.rb
163
222
  - spec/mac-platform.rb
164
- - spec/spotify_spec.rb
223
+ - spec/spec_helper.rb
224
+ - spec/spotify/api_spec.rb
225
+ - spec/spotify/defines_spec.rb
226
+ - spec/spotify/enums_spec.rb
227
+ - spec/spotify/managed_pointer_spec.rb
228
+ - spec/spotify/spotify_spec.rb
229
+ - spec/spotify/structs/session_config_spec.rb
230
+ - spec/spotify/structs/struct_spec.rb
231
+ - spec/spotify/structs/subscribers_spec.rb
232
+ - spec/spotify/structs_spec.rb
233
+ - spec/spotify/types/image_id_spec.rb
234
+ - spec/spotify/types/nul_string_spec.rb
235
+ - spec/spotify/types/utf8_string_spec.rb
236
+ - spec/support/hook_spotify.rb
237
+ - spec/support/spotify_util.rb
165
238
  has_rdoc:
@@ -1,165 +0,0 @@
1
- # This file contains functions that automatically raise when
2
- # their libspotify function returns a non-ok error.
3
-
4
- module Spotify
5
- # Raised on error-wrapped functions when the result is non-ok.
6
- class Error < StandardError
7
- class << self
8
- # Explain a Spotify error with a descriptive message.
9
- #
10
- # @param [Symbol, Integer] error
11
- # @return [String] a decriptive string of the error
12
- def explain(error)
13
- error, symbol = disambiguate(error)
14
-
15
- message = []
16
- message << "[#{symbol.to_s.upcase}]"
17
- message << Spotify.error_message(error)
18
- message << "(#{error})"
19
-
20
- message.join(' ')
21
- end
22
-
23
- # Given a number or a symbol, find both the symbol and the error
24
- # number it represents.
25
- #
26
- # @example given an integer
27
- # Spotify::Error.disambiguate(0) # => [0, :ok]
28
- #
29
- # @example given a symbol
30
- # Spotify::Error.disambiguate(:ok) # => [0, :ok]
31
- #
32
- # @example given bogus
33
- # Spotify::Error.disambiguate(:bogus) # => [-1, nil]
34
- #
35
- # @param [Symbol, Fixnum] error
36
- # @return [[Fixnum, Symbol]] (error code, error symbol)
37
- def disambiguate(error)
38
- @enum ||= Spotify.enum_type(:error)
39
-
40
- if error.is_a? Symbol
41
- error = @enum[symbol = error]
42
- else
43
- symbol = @enum[error]
44
- end
45
-
46
- if error.nil? || symbol.nil?
47
- [-1, nil]
48
- else
49
- [error, symbol]
50
- end
51
- end
52
- end
53
- end
54
-
55
- # Wraps the function `function` so that it raises an error if
56
- # the return error is not :ok.
57
- #
58
- # @note This method is removed at the bottom of this file.
59
- #
60
- # @param [#to_s] function
61
- # @raise [NoMethodError] if `function` is not defined
62
- def self.wrap_function(function)
63
- method(function) # make sure it exists
64
- define_singleton_method("#{function}!") do |*args, &block|
65
- error = public_send(function, *args, &block)
66
- raise Error, Error.explain(error) unless error == :ok
67
- end
68
- end
69
-
70
- wrap_function :session_create
71
- wrap_function :session_release
72
- wrap_function :session_process_events
73
- wrap_function :session_login
74
- wrap_function :session_relogin
75
- wrap_function :session_forget_me
76
- wrap_function :session_logout
77
- wrap_function :session_set_cache_size
78
- wrap_function :session_player_load
79
- wrap_function :session_player_seek
80
- wrap_function :session_player_play
81
- wrap_function :session_player_unload
82
- wrap_function :session_player_prefetch
83
- wrap_function :session_preferred_bitrate
84
- wrap_function :session_set_connection_type
85
- wrap_function :session_set_connection_rules
86
- wrap_function :session_preferred_offline_bitrate
87
- wrap_function :session_set_volume_normalization
88
- wrap_function :session_flush_caches
89
- wrap_function :session_set_private_session
90
- wrap_function :session_set_scrobbling
91
- wrap_function :session_is_scrobbling
92
- wrap_function :session_is_scrobbling_possible
93
- wrap_function :session_set_social_credentials
94
-
95
- wrap_function :image_add_load_callback
96
- wrap_function :image_remove_load_callback
97
- wrap_function :image_error
98
- wrap_function :image_add_ref
99
- wrap_function :image_release
100
-
101
- wrap_function :link_add_ref
102
- wrap_function :link_release
103
-
104
- wrap_function :track_error
105
- wrap_function :track_set_starred
106
- wrap_function :track_add_ref
107
- wrap_function :track_release
108
-
109
- wrap_function :album_add_ref
110
- wrap_function :album_release
111
-
112
- wrap_function :albumbrowse_error
113
- wrap_function :albumbrowse_add_ref
114
- wrap_function :albumbrowse_release
115
-
116
- wrap_function :artist_add_ref
117
- wrap_function :artist_release
118
-
119
- wrap_function :artistbrowse_error
120
- wrap_function :artistbrowse_add_ref
121
- wrap_function :artistbrowse_release
122
-
123
- wrap_function :search_error
124
- wrap_function :search_add_ref
125
- wrap_function :search_release
126
-
127
- wrap_function :playlist_add_callbacks
128
- wrap_function :playlist_remove_callbacks
129
- wrap_function :playlist_track_set_seen
130
- wrap_function :playlist_rename
131
- wrap_function :playlist_set_collaborative
132
- wrap_function :playlist_set_autolink_tracks
133
- wrap_function :playlist_add_tracks
134
- wrap_function :playlist_remove_tracks
135
- wrap_function :playlist_reorder_tracks
136
- wrap_function :playlist_subscribers_free
137
- wrap_function :playlist_update_subscribers
138
- wrap_function :playlist_set_in_ram
139
- wrap_function :playlist_set_offline_mode
140
- wrap_function :playlist_add_ref
141
- wrap_function :playlist_release
142
-
143
- wrap_function :playlistcontainer_add_callbacks
144
- wrap_function :playlistcontainer_remove_callbacks
145
- wrap_function :playlistcontainer_playlist_folder_name
146
- wrap_function :playlistcontainer_remove_playlist
147
- wrap_function :playlistcontainer_move_playlist
148
- wrap_function :playlistcontainer_add_folder
149
- wrap_function :playlistcontainer_add_ref
150
- wrap_function :playlistcontainer_release
151
-
152
- wrap_function :user_add_ref
153
- wrap_function :user_release
154
-
155
- wrap_function :toplistbrowse_error
156
- wrap_function :toplistbrowse_add_ref
157
- wrap_function :toplistbrowse_release
158
-
159
- wrap_function :inbox_error
160
- wrap_function :inbox_add_ref
161
- wrap_function :inbox_release
162
-
163
- # Clean up
164
- class << self; undef :wrap_function; end
165
- end