spotify 12.5.3 → 12.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +20 -5
  4. data/CHANGELOG.md +29 -1
  5. data/Gemfile +5 -0
  6. data/MIT-LICENSE +21 -0
  7. data/README.markdown +75 -50
  8. data/Rakefile +1 -1
  9. data/examples/example-audio_delivery_speed.rb +48 -0
  10. data/examples/{audio-stream_example.rb → example-audio_stream.rb} +14 -29
  11. data/examples/example-console.rb +9 -0
  12. data/examples/example-listing_playlists.rb +89 -0
  13. data/examples/example-loading_object.rb +25 -0
  14. data/examples/example-random_related_artists.rb +53 -0
  15. data/examples/support.rb +106 -0
  16. data/lib/spotify.rb +36 -55
  17. data/lib/spotify/api.rb +54 -26
  18. data/lib/spotify/api/album.rb +45 -2
  19. data/lib/spotify/api/album_browse.rb +81 -3
  20. data/lib/spotify/api/artist.rb +21 -2
  21. data/lib/spotify/api/artist_browse.rb +121 -3
  22. data/lib/spotify/api/error.rb +5 -1
  23. data/lib/spotify/api/image.rb +72 -6
  24. data/lib/spotify/api/inbox.rb +33 -4
  25. data/lib/spotify/api/link.rb +117 -4
  26. data/lib/spotify/api/miscellaneous.rb +12 -0
  27. data/lib/spotify/api/playlist.rb +321 -16
  28. data/lib/spotify/api/playlist_container.rb +168 -9
  29. data/lib/spotify/api/search.rb +156 -3
  30. data/lib/spotify/api/session.rb +390 -26
  31. data/lib/spotify/api/toplist_browse.rb +74 -3
  32. data/lib/spotify/api/track.rb +134 -4
  33. data/lib/spotify/api/user.rb +18 -2
  34. data/lib/spotify/api_helpers.rb +47 -0
  35. data/lib/spotify/data_converters.rb +7 -0
  36. data/lib/spotify/{types → data_converters}/best_effort_string.rb +1 -1
  37. data/lib/spotify/{types → data_converters}/byte_string.rb +0 -0
  38. data/lib/spotify/data_converters/country_code.rb +30 -0
  39. data/lib/spotify/{types → data_converters}/image_id.rb +1 -1
  40. data/lib/spotify/{type_safety.rb → data_converters/type_safety.rb} +0 -0
  41. data/lib/spotify/{types → data_converters}/utf8_string.rb +2 -2
  42. data/lib/spotify/{types → data_converters}/utf8_string_pointer.rb +2 -2
  43. data/lib/spotify/error.rb +180 -47
  44. data/lib/spotify/managed_pointer.rb +32 -12
  45. data/lib/spotify/monkey_patches/ffi_buffer.rb +11 -0
  46. data/lib/spotify/monkey_patches/ffi_enums.rb +4 -0
  47. data/lib/spotify/monkey_patches/ffi_pointer.rb +1 -0
  48. data/lib/spotify/structs.rb +4 -0
  49. data/lib/spotify/structs/session_callbacks.rb +97 -26
  50. data/lib/spotify/structs/session_config.rb +1 -1
  51. data/lib/spotify/structs/subscribers.rb +4 -3
  52. data/lib/spotify/types.rb +104 -5
  53. data/lib/spotify/{objects → types}/album.rb +0 -0
  54. data/lib/spotify/{objects → types}/album_browse.rb +0 -0
  55. data/lib/spotify/{objects → types}/artist.rb +0 -0
  56. data/lib/spotify/{objects → types}/artist_browse.rb +0 -0
  57. data/lib/spotify/{objects → types}/image.rb +0 -0
  58. data/lib/spotify/{objects → types}/inbox.rb +0 -0
  59. data/lib/spotify/{objects → types}/link.rb +0 -0
  60. data/lib/spotify/{objects → types}/playlist.rb +0 -0
  61. data/lib/spotify/{objects → types}/playlist_container.rb +0 -0
  62. data/lib/spotify/{objects → types}/search.rb +0 -0
  63. data/lib/spotify/{objects → types}/session.rb +0 -0
  64. data/lib/spotify/{objects → types}/toplist_browse.rb +0 -0
  65. data/lib/spotify/{objects → types}/track.rb +0 -0
  66. data/lib/spotify/{objects → types}/user.rb +0 -0
  67. data/lib/spotify/util.rb +38 -35
  68. data/lib/spotify/version.rb +1 -1
  69. data/spec/spec_helper.rb +24 -13
  70. data/spec/spotify/api/image_spec.rb +32 -0
  71. data/spec/spotify/api/inbox_spec.rb +34 -0
  72. data/spec/spotify/api/link_spec.rb +40 -0
  73. data/spec/spotify/api/playlist_spec.rb +99 -0
  74. data/spec/spotify/api/playlistcontainer_spec.rb +82 -0
  75. data/spec/spotify/api/session_spec.rb +97 -0
  76. data/spec/spotify/api/track_spec.rb +29 -0
  77. data/spec/spotify/api_error_spec.rb +55 -0
  78. data/spec/spotify/api_spec.rb +17 -11
  79. data/spec/spotify/{types → data_converters}/best_effort_string_spec.rb +4 -4
  80. data/spec/spotify/{types → data_converters}/byte_string_spec.rb +0 -0
  81. data/spec/spotify/data_converters/country_code_spec.rb +16 -0
  82. data/spec/spotify/{types → data_converters}/image_id_spec.rb +1 -1
  83. data/spec/spotify/{type_safety_spec.rb → data_converters/type_safety_spec.rb} +0 -0
  84. data/spec/spotify/{types → data_converters}/utf8_string_pointer_spec.rb +0 -0
  85. data/spec/spotify/{types → data_converters}/utf8_string_spec.rb +1 -1
  86. data/spec/spotify/{api/functions_spec.rb → functions_spec.rb} +2 -0
  87. data/spec/spotify/managed_pointer_spec.rb +13 -13
  88. data/spec/spotify/structs/subscribers_spec.rb +5 -3
  89. data/spec/spotify/{defines_spec.rb → types_spec.rb} +16 -3
  90. data/spec/spotify/util_spec.rb +24 -0
  91. data/spec/spotify_spec.rb +74 -0
  92. data/spec/support/spotify_util.rb +6 -2
  93. data/spec/support/spy_output.rb +16 -0
  94. data/spotify.gemspec +4 -2
  95. metadata +111 -71
  96. data/examples/README.md +0 -15
  97. data/examples/console_example.rb +0 -22
  98. data/examples/example_support.rb +0 -66
  99. data/examples/loading-object_example.rb +0 -43
  100. data/examples/logging-in_example.rb +0 -58
  101. data/lib/spotify/defines.rb +0 -109
  102. data/lib/spotify/objects.rb +0 -17
  103. data/spec/spotify/enums_spec.rb +0 -9
  104. data/spec/spotify/spotify_spec.rb +0 -69
@@ -18,19 +18,18 @@ module Spotify
18
18
  extend Spotify::TypeSafety
19
19
 
20
20
  class << self
21
- # Releases the given pointer if it is not null.
22
- #
23
- # This method derives the release method from the class name.
21
+ # Schedules given pointer for release.
24
22
  #
25
23
  # @param [FFI::Pointer] pointer
26
24
  def release(pointer)
27
25
  unless pointer.null?
28
- # this is to circumvent the type protection
29
- pointer = type_class.new(pointer)
30
- pointer.autorelease = false
26
+ # this is to circumvent the type protection, and wrap the pointer
27
+ # with the correct type for later freeing
28
+ freeable = type_class.new(pointer)
29
+ # and this is to not make this pointer trigger release again
30
+ freeable.autorelease = false
31
31
 
32
- $stderr.puts "Spotify.#{type}_release(#{pointer.inspect})" if $DEBUG
33
- Spotify.public_send("#{type}_release", pointer)
32
+ Spotify.performer.async { freeable.free }
34
33
  end
35
34
  end
36
35
 
@@ -41,8 +40,8 @@ module Spotify
41
40
  # @param [self] pointer must be an instance of {#type_class}
42
41
  def retain(pointer)
43
42
  unless pointer.null?
44
- $stderr.puts "Spotify.#{type}_add_ref(#{pointer.inspect})" if $DEBUG
45
- Spotify.public_send("#{type}_add_ref", pointer)
43
+ Spotify.log "Spotify.#{type}_add_ref(#{pointer.inspect})"
44
+ Spotify.public_send(:"#{type}_add_ref", pointer)
46
45
  end
47
46
  end
48
47
 
@@ -56,6 +55,12 @@ module Spotify
56
55
  end
57
56
  end
58
57
 
58
+ # Casts all null pointers to nil.
59
+ def from_native(pointer, ctx)
60
+ value = super
61
+ value unless value.null?
62
+ end
63
+
59
64
  # @see https://github.com/jruby/jruby/issues/607
60
65
  # @return [Integer] size of the native type, defined for JRuby.
61
66
  def size
@@ -101,8 +106,6 @@ module Spotify
101
106
  end
102
107
  end
103
108
 
104
- protected
105
-
106
109
  # Retrieves the normalized and downcased name of self, so for
107
110
  # Spotify::Album we’ll receive just “album”.
108
111
  def type
@@ -110,6 +113,23 @@ module Spotify
110
113
  end
111
114
  end
112
115
 
116
+ # @see self.class.type
117
+ def type
118
+ self.class.type
119
+ end
120
+
121
+ # Immediately releases the underlying pointer.
122
+ #
123
+ # @note Does NOT call self.class.release.
124
+ # @note This is NOT idempotent.
125
+ def free
126
+ unless null?
127
+ self.autorelease = false
128
+ Spotify.log "Spotify.#{type}_release(#{inspect})"
129
+ Spotify.public_send(:"#{type}_release", self)
130
+ end
131
+ end
132
+
113
133
  # @return [String] string representation of self.
114
134
  def inspect
115
135
  "#<#{self.class} address=0x%x>" % address
@@ -0,0 +1,11 @@
1
+ module Spotify
2
+ module MonkeyPatches
3
+ module FFIBuffer
4
+ def null?
5
+ false
6
+ end
7
+ end
8
+
9
+ ::FFI::Buffer.send(:include, FFIBuffer)
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ # Fix for https://github.com/jruby/jruby/issues/1954
2
+ unless FFI::Enums.method_defined?(:default)
3
+ FFI::Enums.send(:attr_accessor, :default)
4
+ end
@@ -15,6 +15,7 @@ module FFI
15
15
  end
16
16
 
17
17
  alias_method(:read_size_t, "read_#{type}")
18
+ alias_method(:write_size_t, "write_#{type}")
18
19
  end
19
20
  end
20
21
  end
@@ -31,6 +31,10 @@ module Spotify
31
31
 
32
32
  super(pointer, *layout, &block)
33
33
 
34
+ if defined?(self.class::DEFAULTS)
35
+ options = self.class::DEFAULTS.merge(options)
36
+ end
37
+
34
38
  options.each_pair do |key, value|
35
39
  self[key] = value
36
40
  end
@@ -1,48 +1,119 @@
1
1
  module Spotify
2
2
  # Spotify::Struct for Session callbacks.
3
3
  #
4
- # @attr [callback(Session, :error):void] logged_in
5
- # @attr [callback(Session):void] logged_out
6
- # @attr [callback(Session):void] metadata_updated
7
- # @attr [callback(Session, :error):void] connection_error
8
- # @attr [callback(Session, UTF8String):void] message_to_user
9
- # @attr [callback(Session):void] notify_main_thread
10
- # @attr [callback(Session, AudioFormat, :frames, :int):int] music_delivery
11
- # @attr [callback(Session):void] play_token_lost
12
- # @attr [callback(Session, UTF8String):void] log_message
13
- # @attr [callback(Session):void] end_of_track
14
- # @attr [callback(Session, :error):void] streaming_error
15
- # @attr [callback(Session):void] userinfo_updated
16
- # @attr [callback(Session):void] start_playback
17
- # @attr [callback(Session):void] stop_playback
18
- # @attr [callback(Session, AudioBufferStats):void] get_audio_buffer_stats
19
- # @attr [callback(Session):void] offline_status_updated
20
- # @attr [callback(Session, :error):void] offline_error
21
- # @attr [callback(Session, :string):void] credentials_blob_updated
22
- # @attr [callback(Session):void] connectionstate_updated
23
- # @attr [callback(Session, :error):void] scrobble_error
24
- # @attr [callback(Session, :bool):void] private_session_mode_changed
4
+ # @!method logged_in(session, error)
5
+ # @param [Session] session
6
+ # @param [Symbol] error
7
+ # @!method logged_out(session)
8
+ # @param [Session] session
9
+ # @!method metadata_updated(session)
10
+ # @param [Session]
11
+ # @!method connection_error(session, error)
12
+ # @param [Session] session
13
+ # @param [Symbol] error
14
+ # @!method message_to_user(session, message)
15
+ # @param [Session] session
16
+ # @param [String] message
17
+ # @!method notify_main_thread(session)
18
+ # @param [Session] session
19
+ # @!method music_delivery(session, audio_format, frames_pointer, frames_length)
20
+ # Frames pointer is pointing to data in the format described by audio format, with interleaved channels:
21
+ #
22
+ # frames memory (16 bit = 2 byte frames, 2 channels, 3 frames):
23
+ # 00 00 # sample 1, frame 1, channel 1
24
+ # 00 00 # sample 2, frame 1, channel 2
25
+ # 00 00 # sample 3, frame 2, channel 1
26
+ # 00 00 # sample 4, frame 2, channel 2
27
+ # 00 00 # sample 5, frame 3, channel 1
28
+ # 00 00 # sample 6, frame 3, channel 2
29
+ # # end of data, 3 frames * 2 channels = 6 samples
30
+ #
31
+ # @param [Session] session
32
+ # @param [AudioFormat] audio_format
33
+ # @param [FFI::Pointer] frames_pointer
34
+ # @param [Integer] frames_length
35
+ # @return [Integer] number of consumed frames, 0..frames_length
36
+ # @!method play_token_lost(session)
37
+ # @param [Session] session
38
+ # @!method log_message(session, message)
39
+ # @param [Session] session
40
+ # @param [String] message
41
+ # @!method end_of_track(session)
42
+ # @param [Session]
43
+ # @!method streaming_error(session, error)
44
+ # @param [Session] session
45
+ # @param [Symbol] error
46
+ # @!method userinfo_updated(session)
47
+ # @param [Session] session
48
+ # @!method start_playback(session)
49
+ # @param [Session] session
50
+ # @!method stop_playback(session)
51
+ # @param [Session] session
52
+ # @!method get_audio_buffer_stats(session, stats)
53
+ # @param [Session] session
54
+ # @param [AudioBufferStats] stats
55
+ # @!method offline_status_updated(session)
56
+ # @param [Session] session
57
+ # @!method offline_error(session, error)
58
+ # @param [Session] session
59
+ # @param [Symbol] error
60
+ # @!method credentials_blob_updated(session, blob)
61
+ # @param [Session] session
62
+ # @param [String] blob
63
+ # @!method connectionstate_updated(session)
64
+ # @param [Session] session
65
+ # @!method scrobble_error(session, error)
66
+ # @param [Session] session
67
+ # @param [Symbol] error
68
+ # @!method private_session_mode_changed(session, is_private)
69
+ # @param [Session] session
70
+ # @param [Boolean] is_private
25
71
  class SessionCallbacks < Spotify::Struct
26
- layout :logged_in => callback([ Session, :error ], :void),
72
+ layout :logged_in => callback([ Session, APIError ], :void),
27
73
  :logged_out => callback([ Session ], :void),
28
74
  :metadata_updated => callback([ Session ], :void),
29
- :connection_error => callback([ Session, :error ], :void),
75
+ :connection_error => callback([ Session, APIError ], :void),
30
76
  :message_to_user => callback([ Session, UTF8String ], :void),
31
77
  :notify_main_thread => callback([ Session ], :void),
32
78
  :music_delivery => callback([ Session, AudioFormat.by_ref, :frames, :int ], :int),
33
79
  :play_token_lost => callback([ Session ], :void),
34
80
  :log_message => callback([ Session, UTF8String ], :void),
35
81
  :end_of_track => callback([ Session ], :void),
36
- :streaming_error => callback([ Session, :error ], :void),
82
+ :streaming_error => callback([ Session, APIError ], :void),
37
83
  :userinfo_updated => callback([ Session ], :void),
38
84
  :start_playback => callback([ Session ], :void),
39
85
  :stop_playback => callback([ Session ], :void),
40
86
  :get_audio_buffer_stats => callback([ Session, AudioBufferStats.by_ref ], :void),
41
87
  :offline_status_updated => callback([ Session ], :void),
42
- :offline_error => callback([ Session, :error ], :void),
88
+ :offline_error => callback([ Session, APIError ], :void),
43
89
  :credentials_blob_updated => callback([ Session, :string ], :void),
44
90
  :connectionstate_updated => callback([ Session ], :void),
45
- :scrobble_error => callback([ Session, :error ], :void),
91
+ :scrobble_error => callback([ Session, APIError ], :void),
46
92
  :private_session_mode_changed => callback([ Session, :bool ], :void)
93
+
94
+ # Sane defaults, to avoid {Spotify::API#session_logout} segfaulting.
95
+ DEFAULTS = {
96
+ connection_error: proc {},
97
+ connectionstate_updated: proc {},
98
+ credentials_blob_updated: proc {},
99
+ end_of_track: proc {},
100
+ get_audio_buffer_stats: proc {},
101
+ log_message: proc {},
102
+ logged_in: proc {},
103
+ logged_out: proc {},
104
+ message_to_user: proc {},
105
+ metadata_updated: proc {},
106
+ music_delivery: proc {},
107
+ notify_main_thread: proc {},
108
+ offline_error: proc {},
109
+ offline_status_updated: proc {},
110
+ play_token_lost: proc {},
111
+ private_session_mode_changed: proc {},
112
+ scrobble_error: proc {},
113
+ start_playback: proc {},
114
+ stop_playback: proc {},
115
+ streaming_error: proc {},
116
+ userinfo_updated: proc {},
117
+ }
47
118
  end
48
119
  end
@@ -34,7 +34,7 @@ module Spotify
34
34
  it[:proxy] = UTF8StringPointer
35
35
  it[:proxy_username] = UTF8StringPointer
36
36
  it[:proxy_password] = UTF8StringPointer
37
- it[:ca_certs_filename] = UTF8StringPointer if Spotify::API.linux?
37
+ it[:ca_certs_filename] = UTF8StringPointer if Spotify::Util.linux?
38
38
  it[:tracefile] = UTF8StringPointer
39
39
  layout(it)
40
40
 
@@ -18,9 +18,10 @@ module Spotify
18
18
  # @param [FFI::Pointer] pointer pointing to a subscribers struct
19
19
  def release(pointer)
20
20
  unless pointer.null?
21
- pointer = type_class.new(pointer)
22
- $stderr.puts "Spotify.playlist_subscribers_free(#{pointer.inspect})" if $DEBUG
23
- Spotify.playlist_subscribers_free(pointer)
21
+ Spotify.performer.async do
22
+ Spotify.log "Spotify.playlist_subscribers_free(#{pointer})"
23
+ Spotify.playlist_subscribers_free(pointer)
24
+ end
24
25
  end
25
26
  end
26
27
  end
@@ -1,5 +1,104 @@
1
- require 'spotify/types/utf8_string'
2
- require 'spotify/types/utf8_string_pointer'
3
- require 'spotify/types/image_id'
4
- require 'spotify/types/byte_string'
5
- require 'spotify/types/best_effort_string'
1
+ require 'spotify/managed_pointer'
2
+
3
+ require 'spotify/types/album'
4
+ require 'spotify/types/album_browse'
5
+ require 'spotify/types/artist'
6
+ require 'spotify/types/artist_browse'
7
+ require 'spotify/types/image'
8
+ require 'spotify/types/inbox'
9
+ require 'spotify/types/link'
10
+ require 'spotify/types/playlist'
11
+ require 'spotify/types/playlist_container'
12
+ require 'spotify/types/search'
13
+ require 'spotify/types/session'
14
+ require 'spotify/types/toplist_browse'
15
+ require 'spotify/types/track'
16
+ require 'spotify/types/user'
17
+
18
+ module Spotify
19
+ class API
20
+ typedef :pointer, :frames
21
+ typedef :pointer, :userdata
22
+ typedef :pointer, :array
23
+ typedef Spotify::APIError, :error
24
+
25
+ #
26
+ # Audio
27
+ #
28
+ enum :sampletype, [:int16] # int16_native_endian
29
+ enum :bitrate, %w(160k 320k 96k).map(&:to_sym)
30
+
31
+ #
32
+ # Session
33
+ #
34
+ enum :social_provider, [:spotify, :facebook, :lastfm]
35
+ enum :scrobbling_state, [:use_global_setting, :local_enabled, :local_disabled, :global_enabled, :global_disabled]
36
+ enum :connectionstate, [:logged_out, :logged_in, :disconnected, :undefined, :offline]
37
+ enum :connection_type, [:unknown, :none, :mobile, :mobile_roaming, :wifi, :wired]
38
+ enum :connection_rules, [:network , 0x1,
39
+ :network_if_roaming , 0x2,
40
+ :allow_sync_over_mobile, 0x4,
41
+ :allow_sync_over_wifi , 0x8]
42
+
43
+ #
44
+ # Image
45
+ #
46
+ callback :image_loaded_cb, [ Image.retaining_class, :userdata ], :void
47
+ enum :imageformat, [:unknown, -1, :jpeg]
48
+ enum :image_size, [ :normal, :small, :large ]
49
+
50
+ #
51
+ # Link
52
+ #
53
+ enum :linktype, [:invalid, :track, :album, :artist, :search,
54
+ :playlist, :profile, :starred, :localtrack, :image]
55
+
56
+ #
57
+ # Track
58
+ #
59
+ enum :availability, [:unavailable, :available, :not_streamable, :banned_by_artist]
60
+ typedef :availability, :track_availability # for automated testing
61
+ enum :track_offline_status, [:no, :waiting, :downloading, :done, :error, :done_expired, :limit_exceeded, :done_resync]
62
+
63
+ #
64
+ # Album
65
+ #
66
+ callback :albumbrowse_complete_cb, [AlbumBrowse.retaining_class, :userdata], :void
67
+ enum :albumtype, [:album, :single, :compilation, :unknown]
68
+
69
+ #
70
+ # Artist browsing
71
+ #
72
+ callback :artistbrowse_complete_cb, [ArtistBrowse.retaining_class, :userdata], :void
73
+ enum :artistbrowse_type, [:full, :no_tracks, :no_albums]
74
+
75
+ #
76
+ # Search
77
+ #
78
+ callback :search_complete_cb, [Search.retaining_class, :userdata], :void
79
+ enum :search_type, [:standard, :suggest]
80
+
81
+ #
82
+ # Playlist
83
+ #
84
+ enum :playlist_type, [:playlist, :start_folder, :end_folder, :placeholder]
85
+ enum :playlist_offline_status, [:no, :yes, :downloading, :waiting]
86
+
87
+ #
88
+ # User
89
+ #
90
+ enum :relation_type, [:unknown, :none, :unidirectional, :bidirectional]
91
+
92
+ #
93
+ # Toplist
94
+ #
95
+ callback :toplistbrowse_complete_cb, [ToplistBrowse.retaining_class, :userdata], :void
96
+ enum :toplisttype, [:artists, :albums, :tracks]
97
+ enum :toplistregion, [:everywhere, :user]
98
+
99
+ #
100
+ # Inbox
101
+ #
102
+ callback :inboxpost_complete_cb, [Inbox.retaining_class, :userdata], :void
103
+ end
104
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,41 +1,44 @@
1
- class << Spotify::API
2
- # @!group Utility
1
+ module Spotify
2
+ # Public utility helper methods.
3
+ module Util
4
+ module_function
3
5
 
4
- # Retrieves the associated value of an enum from a given symbol, raising an error if it does not exist.
5
- #
6
- # @example retrieving a value
7
- # Spotify.enum_value!(:ok, "error value") # => 0
8
- #
9
- # @example failing to retrieve a value
10
- # Spotify.enum_value!(:moo, "connection rule") # => ArgumentError, invalid connection rule: :moo
11
- #
12
- # @api public
13
- # @param [Symbol] symbol
14
- # @param [#to_s] type used as error message when the symbol does not resolve
15
- # @raise [ArgumentError] when the symbol does not exist as an enum value
16
- # @return [Integer]
17
- def enum_value!(symbol, type)
18
- enum_value(symbol) or raise ArgumentError, "invalid #{type}: #{symbol}"
19
- end
6
+ # Retrieves the associated value of an enum from a given symbol, raising an error if it does not exist.
7
+ #
8
+ # @example retrieving a value
9
+ # Spotify::Util.enum_value!(:ok, "error value") # => 0
10
+ #
11
+ # @example failing to retrieve a value
12
+ # Spotify::Util.enum_value!(:moo, "connection rule") # => ArgumentError, invalid connection rule: :moo
13
+ #
14
+ # @api public
15
+ # @param [Symbol] symbol
16
+ # @param [#to_s] type used as error message when the symbol does not resolve
17
+ # @raise [ArgumentError] when the symbol does not exist as an enum value
18
+ # @return [Integer]
19
+ def enum_value!(symbol, type)
20
+ Spotify::API.enum_value(symbol) or raise ArgumentError, "invalid #{type}: #{symbol.inspect}"
21
+ end
20
22
 
21
- # @see platform
22
- # @api public
23
- # @return [Boolean] true if on Linux
24
- def linux?
25
- platform == :linux
26
- end
23
+ # @see platform
24
+ # @api public
25
+ # @return [Boolean] true if on Linux
26
+ def linux?
27
+ platform == :linux
28
+ end
27
29
 
28
- # @api public
29
- # @return [Symbol] platform as either :mac, :windows, or :linux
30
- def platform
31
- case FFI::Platform::OS
32
- when /darwin/ then :mac
33
- when /linux/ then :linux
34
- when /windows/ then :windows
35
- else
36
- $stderr.puts "[WARN] You are running the Spotify gem on an unknown platform. (#{__FILE__}:#{__LINE__})"
37
- $stderr.puts "[WARN] Platform: #{FFI::Platform::OS}"
38
- :unknown
30
+ # @api public
31
+ # @return [Symbol] platform as either :mac, :windows, or :linux
32
+ def platform
33
+ case FFI::Platform::OS
34
+ when /darwin/ then :mac
35
+ when /linux/ then :linux
36
+ when /windows/ then :windows
37
+ else
38
+ $stderr.puts "[WARN] You are running the Spotify gem on an unknown platform. (#{__FILE__}:#{__LINE__})"
39
+ $stderr.puts "[WARN] Platform: #{FFI::Platform::OS}"
40
+ :unknown
41
+ end
39
42
  end
40
43
  end
41
44
  end