spotify 12.5.3 → 12.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +20 -5
- data/CHANGELOG.md +29 -1
- data/Gemfile +5 -0
- data/MIT-LICENSE +21 -0
- data/README.markdown +75 -50
- data/Rakefile +1 -1
- data/examples/example-audio_delivery_speed.rb +48 -0
- data/examples/{audio-stream_example.rb → example-audio_stream.rb} +14 -29
- data/examples/example-console.rb +9 -0
- data/examples/example-listing_playlists.rb +89 -0
- data/examples/example-loading_object.rb +25 -0
- data/examples/example-random_related_artists.rb +53 -0
- data/examples/support.rb +106 -0
- data/lib/spotify.rb +36 -55
- data/lib/spotify/api.rb +54 -26
- data/lib/spotify/api/album.rb +45 -2
- data/lib/spotify/api/album_browse.rb +81 -3
- data/lib/spotify/api/artist.rb +21 -2
- data/lib/spotify/api/artist_browse.rb +121 -3
- data/lib/spotify/api/error.rb +5 -1
- data/lib/spotify/api/image.rb +72 -6
- data/lib/spotify/api/inbox.rb +33 -4
- data/lib/spotify/api/link.rb +117 -4
- data/lib/spotify/api/miscellaneous.rb +12 -0
- data/lib/spotify/api/playlist.rb +321 -16
- data/lib/spotify/api/playlist_container.rb +168 -9
- data/lib/spotify/api/search.rb +156 -3
- data/lib/spotify/api/session.rb +390 -26
- data/lib/spotify/api/toplist_browse.rb +74 -3
- data/lib/spotify/api/track.rb +134 -4
- data/lib/spotify/api/user.rb +18 -2
- data/lib/spotify/api_helpers.rb +47 -0
- data/lib/spotify/data_converters.rb +7 -0
- data/lib/spotify/{types → data_converters}/best_effort_string.rb +1 -1
- data/lib/spotify/{types → data_converters}/byte_string.rb +0 -0
- data/lib/spotify/data_converters/country_code.rb +30 -0
- data/lib/spotify/{types → data_converters}/image_id.rb +1 -1
- data/lib/spotify/{type_safety.rb → data_converters/type_safety.rb} +0 -0
- data/lib/spotify/{types → data_converters}/utf8_string.rb +2 -2
- data/lib/spotify/{types → data_converters}/utf8_string_pointer.rb +2 -2
- data/lib/spotify/error.rb +180 -47
- data/lib/spotify/managed_pointer.rb +32 -12
- data/lib/spotify/monkey_patches/ffi_buffer.rb +11 -0
- data/lib/spotify/monkey_patches/ffi_enums.rb +4 -0
- data/lib/spotify/monkey_patches/ffi_pointer.rb +1 -0
- data/lib/spotify/structs.rb +4 -0
- data/lib/spotify/structs/session_callbacks.rb +97 -26
- data/lib/spotify/structs/session_config.rb +1 -1
- data/lib/spotify/structs/subscribers.rb +4 -3
- data/lib/spotify/types.rb +104 -5
- data/lib/spotify/{objects → types}/album.rb +0 -0
- data/lib/spotify/{objects → types}/album_browse.rb +0 -0
- data/lib/spotify/{objects → types}/artist.rb +0 -0
- data/lib/spotify/{objects → types}/artist_browse.rb +0 -0
- data/lib/spotify/{objects → types}/image.rb +0 -0
- data/lib/spotify/{objects → types}/inbox.rb +0 -0
- data/lib/spotify/{objects → types}/link.rb +0 -0
- data/lib/spotify/{objects → types}/playlist.rb +0 -0
- data/lib/spotify/{objects → types}/playlist_container.rb +0 -0
- data/lib/spotify/{objects → types}/search.rb +0 -0
- data/lib/spotify/{objects → types}/session.rb +0 -0
- data/lib/spotify/{objects → types}/toplist_browse.rb +0 -0
- data/lib/spotify/{objects → types}/track.rb +0 -0
- data/lib/spotify/{objects → types}/user.rb +0 -0
- data/lib/spotify/util.rb +38 -35
- data/lib/spotify/version.rb +1 -1
- data/spec/spec_helper.rb +24 -13
- data/spec/spotify/api/image_spec.rb +32 -0
- data/spec/spotify/api/inbox_spec.rb +34 -0
- data/spec/spotify/api/link_spec.rb +40 -0
- data/spec/spotify/api/playlist_spec.rb +99 -0
- data/spec/spotify/api/playlistcontainer_spec.rb +82 -0
- data/spec/spotify/api/session_spec.rb +97 -0
- data/spec/spotify/api/track_spec.rb +29 -0
- data/spec/spotify/api_error_spec.rb +55 -0
- data/spec/spotify/api_spec.rb +17 -11
- data/spec/spotify/{types → data_converters}/best_effort_string_spec.rb +4 -4
- data/spec/spotify/{types → data_converters}/byte_string_spec.rb +0 -0
- data/spec/spotify/data_converters/country_code_spec.rb +16 -0
- data/spec/spotify/{types → data_converters}/image_id_spec.rb +1 -1
- data/spec/spotify/{type_safety_spec.rb → data_converters/type_safety_spec.rb} +0 -0
- data/spec/spotify/{types → data_converters}/utf8_string_pointer_spec.rb +0 -0
- data/spec/spotify/{types → data_converters}/utf8_string_spec.rb +1 -1
- data/spec/spotify/{api/functions_spec.rb → functions_spec.rb} +2 -0
- data/spec/spotify/managed_pointer_spec.rb +13 -13
- data/spec/spotify/structs/subscribers_spec.rb +5 -3
- data/spec/spotify/{defines_spec.rb → types_spec.rb} +16 -3
- data/spec/spotify/util_spec.rb +24 -0
- data/spec/spotify_spec.rb +74 -0
- data/spec/support/spotify_util.rb +6 -2
- data/spec/support/spy_output.rb +16 -0
- data/spotify.gemspec +4 -2
- metadata +111 -71
- data/examples/README.md +0 -15
- data/examples/console_example.rb +0 -22
- data/examples/example_support.rb +0 -66
- data/examples/loading-object_example.rb +0 -43
- data/examples/logging-in_example.rb +0 -58
- data/lib/spotify/defines.rb +0 -109
- data/lib/spotify/objects.rb +0 -17
- data/spec/spotify/enums_spec.rb +0 -9
- 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
|
-
#
|
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
|
-
|
30
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/spotify/structs.rb
CHANGED
@@ -1,48 +1,119 @@
|
|
1
1
|
module Spotify
|
2
2
|
# Spotify::Struct for Session callbacks.
|
3
3
|
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
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,
|
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,
|
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,
|
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,
|
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,
|
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::
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
data/lib/spotify/types.rb
CHANGED
@@ -1,5 +1,104 @@
|
|
1
|
-
require 'spotify/
|
2
|
-
|
3
|
-
require 'spotify/types/
|
4
|
-
require 'spotify/types/
|
5
|
-
require 'spotify/types/
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/spotify/util.rb
CHANGED
@@ -1,41 +1,44 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
module Spotify
|
2
|
+
# Public utility helper methods.
|
3
|
+
module Util
|
4
|
+
module_function
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
# @see platform
|
24
|
+
# @api public
|
25
|
+
# @return [Boolean] true if on Linux
|
26
|
+
def linux?
|
27
|
+
platform == :linux
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|