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,10 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Artist
4
+ attach_function :artist_name, [ Artist ], UTF8String
5
+ attach_function :artist_is_loaded, [ Artist ], :bool
6
+ attach_function :artist_portrait, [ Artist, :image_size ], ImageID
7
+ attach_function :artist_add_ref, [ Artist ], :error
8
+ attach_function :artist_release, [ Artist ], :error
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ module Spotify
2
+ class API
3
+ # @!group ArtistBrowse
4
+ attach_function :artistbrowse_create, [ Session, Artist, :artistbrowse_type, :artistbrowse_complete_cb, :userdata ], ArtistBrowse
5
+ attach_function :artistbrowse_is_loaded, [ ArtistBrowse ], :bool
6
+ attach_function :artistbrowse_error, [ ArtistBrowse ], :error
7
+ attach_function :artistbrowse_artist, [ ArtistBrowse ], Artist
8
+ attach_function :artistbrowse_num_portraits, [ ArtistBrowse ], :int
9
+ attach_function :artistbrowse_portrait, [ ArtistBrowse, :int ], ImageID
10
+ attach_function :artistbrowse_num_tracks, [ ArtistBrowse ], :int
11
+ attach_function :artistbrowse_track, [ ArtistBrowse, :int ], Track
12
+ attach_function :artistbrowse_num_albums, [ ArtistBrowse ], :int
13
+ attach_function :artistbrowse_album, [ ArtistBrowse, :int ], Album
14
+ attach_function :artistbrowse_num_similar_artists, [ ArtistBrowse ], :int
15
+ attach_function :artistbrowse_similar_artist, [ ArtistBrowse, :int ], Artist
16
+ attach_function :artistbrowse_biography, [ ArtistBrowse ], UTF8String
17
+ attach_function :artistbrowse_backend_request_duration, [ ArtistBrowse ], :int
18
+ attach_function :artistbrowse_num_tophit_tracks, [ ArtistBrowse ], :int
19
+ attach_function :artistbrowse_tophit_track, [ ArtistBrowse, :int ], Track
20
+ attach_function :artistbrowse_add_ref, [ ArtistBrowse ], :error
21
+ attach_function :artistbrowse_release, [ ArtistBrowse ], :error
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Error
4
+ attach_function :error_message, [ :error ], UTF8String
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Image
4
+ attach_function :image_create, [ Session, ImageID ], Image
5
+ attach_function :image_add_load_callback, [ Image, :image_loaded_cb, :userdata ], :error
6
+ attach_function :image_remove_load_callback, [ Image, :image_loaded_cb, :userdata ], :error
7
+ attach_function :image_is_loaded, [ Image ], :bool
8
+ attach_function :image_error, [ Image ], :error
9
+ attach_function :image_format, [ Image ], :imageformat
10
+ attach_function :image_data, [ Image, :buffer_out ], :pointer
11
+ attach_function :image_image_id, [ Image ], ImageID
12
+ attach_function :image_create_from_link, [ Session, Link ], Image
13
+ attach_function :image_add_ref, [ Image ], :error
14
+ attach_function :image_release, [ Image ], :error
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Inbox
4
+ attach_function :inbox_post_tracks, [ Session, UTF8String, :array, :int, UTF8String, :inboxpost_complete_cb, :userdata ], Inbox
5
+ attach_function :inbox_error, [ Inbox ], :error
6
+ attach_function :inbox_add_ref, [ Inbox ], :error
7
+ attach_function :inbox_release, [ Inbox ], :error
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Link
4
+ attach_function :link_create_from_string, [ :string ], Link
5
+ attach_function :link_create_from_track, [ Track, :int ], Link
6
+ attach_function :link_create_from_album, [ Album ], Link
7
+ attach_function :link_create_from_artist, [ Artist ], Link
8
+ attach_function :link_create_from_search, [ Search ], Link
9
+ attach_function :link_create_from_playlist, [ Playlist ], Link
10
+ attach_function :link_create_from_artist_portrait, [ Artist, :image_size ], Link
11
+ attach_function :link_create_from_artistbrowse_portrait, [ ArtistBrowse, :int ], Link
12
+ attach_function :link_create_from_album_cover, [ Album, :image_size ], Link
13
+ attach_function :link_create_from_image, [ Image ], Link
14
+ attach_function :link_create_from_user, [ User ], Link
15
+ attach_function :link_as_string, [ Link, :buffer_out, :int ], :int
16
+ attach_function :link_type, [ Link ], :linktype
17
+ attach_function :link_as_track, [ Link ], Track
18
+ attach_function :link_as_track_and_offset, [ Link, :buffer_out ], Track
19
+ attach_function :link_as_album, [ Link ], Album
20
+ attach_function :link_as_artist, [ Link ], Artist
21
+ attach_function :link_as_user, [ Link ], User
22
+ attach_function :link_add_ref, [ Link ], :error
23
+ attach_function :link_release, [ Link ], :error
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Playlist
4
+ attach_function :playlist_is_loaded, [ Playlist ], :bool
5
+ attach_function :playlist_add_callbacks, [ Playlist, PlaylistCallbacks, :userdata ], :error
6
+ attach_function :playlist_remove_callbacks, [ Playlist, PlaylistCallbacks, :userdata ], :error
7
+ attach_function :playlist_num_tracks, [ Playlist ], :int
8
+ attach_function :playlist_track, [ Playlist, :int ], Track
9
+ attach_function :playlist_track_create_time, [ Playlist, :int ], :int
10
+ attach_function :playlist_track_creator, [ Playlist, :int ], User
11
+ attach_function :playlist_track_seen, [ Playlist, :int ], :bool
12
+ attach_function :playlist_track_set_seen, [ Playlist, :int, :bool ], :error
13
+ attach_function :playlist_track_message, [ Playlist, :int ], UTF8String
14
+ attach_function :playlist_name, [ Playlist ], UTF8String
15
+ attach_function :playlist_rename, [ Playlist, UTF8String ], :error
16
+ attach_function :playlist_owner, [ Playlist ], User
17
+ attach_function :playlist_is_collaborative, [ Playlist ], :bool
18
+ attach_function :playlist_set_collaborative, [ Playlist, :bool ], :error
19
+ attach_function :playlist_set_autolink_tracks, [ Playlist, :bool ], :error
20
+ attach_function :playlist_get_description, [ Playlist ], UTF8String
21
+ attach_function :playlist_get_image, [ Playlist, :buffer_out ], :bool
22
+ attach_function :playlist_has_pending_changes, [ Playlist ], :bool
23
+ attach_function :playlist_add_tracks, [ Playlist, :array, :int, :int, Session ], :error
24
+ attach_function :playlist_remove_tracks, [ Playlist, :array, :int ], :error
25
+ attach_function :playlist_reorder_tracks, [ Playlist, :array, :int, :int ], :error
26
+ attach_function :playlist_num_subscribers, [ Playlist ], :uint
27
+ attach_function :playlist_subscribers, [ Playlist ], Subscribers
28
+ attach_function :playlist_subscribers_free, [ Subscribers ], :error
29
+ attach_function :playlist_update_subscribers, [ Session, Playlist ], :error
30
+ attach_function :playlist_is_in_ram, [ Session, Playlist ], :bool
31
+ attach_function :playlist_set_in_ram, [ Session, Playlist, :bool ], :error
32
+ attach_function :playlist_create, [ Session, Link ], Playlist
33
+ attach_function :playlist_get_offline_status, [ Session, Playlist ], :playlist_offline_status
34
+ attach_function :playlist_get_offline_download_completed, [ Session, Playlist ], :int
35
+ attach_function :playlist_set_offline_mode, [ Session, Playlist, :bool ], :error
36
+ attach_function :playlist_add_ref, [ Playlist ], :error
37
+ attach_function :playlist_release, [ Playlist ], :error
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ module Spotify
2
+ class API
3
+ # @!group PlaylistContainer
4
+ attach_function :playlistcontainer_add_callbacks, [ PlaylistContainer, PlaylistContainerCallbacks, :userdata ], :error
5
+ attach_function :playlistcontainer_remove_callbacks, [ PlaylistContainer, PlaylistContainerCallbacks, :userdata ], :error
6
+ attach_function :playlistcontainer_num_playlists, [ PlaylistContainer ], :int
7
+ attach_function :playlistcontainer_playlist, [ PlaylistContainer, :int ], Playlist
8
+ attach_function :playlistcontainer_playlist_type, [ PlaylistContainer, :int ], :playlist_type
9
+ attach_function :playlistcontainer_playlist_folder_name, [ PlaylistContainer, :int, :buffer_out, :int ], :error
10
+ attach_function :playlistcontainer_playlist_folder_id, [ PlaylistContainer, :int ], :uint64
11
+ attach_function :playlistcontainer_add_new_playlist, [ PlaylistContainer, UTF8String ], Playlist
12
+ attach_function :playlistcontainer_add_playlist, [ PlaylistContainer, Link ], Playlist
13
+ attach_function :playlistcontainer_remove_playlist, [ PlaylistContainer, :int ], :error
14
+ attach_function :playlistcontainer_move_playlist, [ PlaylistContainer, :int, :int, :bool ], :error
15
+ attach_function :playlistcontainer_add_folder, [ PlaylistContainer, :int, UTF8String ], :error
16
+ attach_function :playlistcontainer_owner, [ PlaylistContainer ], User
17
+ attach_function :playlistcontainer_is_loaded, [ PlaylistContainer ], :bool
18
+ attach_function :playlistcontainer_get_unseen_tracks, [ PlaylistContainer, Playlist, :array, :int ], :int
19
+ attach_function :playlistcontainer_clear_unseen_tracks, [ PlaylistContainer, Playlist ], :int
20
+ attach_function :playlistcontainer_add_ref, [ PlaylistContainer ], :error
21
+ attach_function :playlistcontainer_release, [ PlaylistContainer ], :error
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Search
4
+ attach_function :search_create, [ Session, UTF8String, :int, :int, :int, :int, :int, :int, :int, :int, :search_type, :search_complete_cb, :userdata ], Search
5
+ attach_function :search_is_loaded, [ Search ], :bool
6
+ attach_function :search_error, [ Search ], :error
7
+ attach_function :search_query, [ Search ], UTF8String
8
+ attach_function :search_did_you_mean, [ Search ], UTF8String
9
+ attach_function :search_num_tracks, [ Search ], :int
10
+ attach_function :search_track, [ Search, :int ], Track
11
+ attach_function :search_num_albums, [ Search ], :int
12
+ attach_function :search_album, [ Search, :int ], Album
13
+ attach_function :search_num_artists, [ Search ], :int
14
+ attach_function :search_artist, [ Search, :int ], Artist
15
+ attach_function :search_num_playlists, [ Search ], :int
16
+ attach_function :search_playlist, [ Search, :int ], Playlist
17
+ attach_function :search_playlist_name, [ Search, :int ], UTF8String
18
+ attach_function :search_playlist_uri, [ Search, :int ], UTF8String
19
+ attach_function :search_playlist_image_uri, [ Search, :int ], UTF8String
20
+ attach_function :search_total_tracks, [ Search ], :int
21
+ attach_function :search_total_albums, [ Search ], :int
22
+ attach_function :search_total_artists, [ Search ], :int
23
+ attach_function :search_total_playlists, [ Search ], :int
24
+ attach_function :search_add_ref, [ Search ], :error
25
+ attach_function :search_release, [ Search ], :error
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Session
4
+ attach_function :session_create, [ SessionConfig, :buffer_out ], :error
5
+ attach_function :session_release, [ Session ], :error
6
+ attach_function :session_process_events, [ Session, :buffer_out ], :error
7
+ attach_function :session_login, [ Session, UTF8String, :string, :bool, :string ], :error
8
+ attach_function :session_relogin, [ Session ], :error
9
+ attach_function :session_forget_me, [ Session ], :error
10
+ attach_function :session_remembered_user, [ Session, :buffer_out, :size_t ], :int
11
+ attach_function :session_user, [ Session ], User
12
+ attach_function :session_logout, [ Session ], :error
13
+ attach_function :session_connectionstate, [ Session ], :connectionstate
14
+ attach_function :session_userdata, [ Session ], :userdata
15
+ attach_function :session_set_cache_size, [ Session, :size_t ], :error
16
+ attach_function :session_player_load, [ Session, Track ], :error
17
+ attach_function :session_player_seek, [ Session, :int ], :error
18
+ attach_function :session_player_play, [ Session, :bool ], :error
19
+ attach_function :session_player_unload, [ Session ], :error
20
+ attach_function :session_player_prefetch, [ Session, Track ], :error
21
+ attach_function :session_playlistcontainer, [ Session ], PlaylistContainer
22
+ attach_function :session_inbox_create, [ Session ], Playlist
23
+ attach_function :session_starred_create, [ Session ], Playlist
24
+ attach_function :session_starred_for_user_create, [ Session, UTF8String ], Playlist
25
+ attach_function :session_publishedcontainer_for_user_create, [ Session, UTF8String ], PlaylistContainer
26
+ attach_function :session_preferred_bitrate, [ Session, :bitrate ], :error
27
+ attach_function :session_set_connection_type, [ Session, :connection_type ], :error
28
+ attach_function :session_set_connection_rules, [ Session, :connection_rules ], :error
29
+ attach_function :offline_tracks_to_sync, [ Session ], :int
30
+ attach_function :offline_num_playlists, [ Session ], :int
31
+ attach_function :offline_sync_get_status, [ Session, OfflineSyncStatus ], :bool
32
+ attach_function :offline_time_left, [ Session ], :int
33
+ attach_function :session_user_country, [ Session ], :int
34
+ attach_function :session_preferred_offline_bitrate, [ Session, :bitrate, :bool ], :error
35
+ attach_function :session_set_volume_normalization, [ Session, :bool ], :error
36
+ attach_function :session_get_volume_normalization, [ Session ], :bool
37
+ attach_function :session_flush_caches, [ Session ], :error
38
+ attach_function :session_user_name, [ Session ], :string
39
+ attach_function :session_set_private_session, [ Session, :bool ], :error
40
+ attach_function :session_is_private_session, [ Session ], :bool
41
+ attach_function :session_set_scrobbling, [ Session, :social_provider, :scrobbling_state ], :error
42
+ attach_function :session_is_scrobbling, [ Session, :social_provider, :buffer_out ], :error
43
+ attach_function :session_is_scrobbling_possible, [ Session, :social_provider, :buffer_out ], :error
44
+ attach_function :session_set_social_credentials, [ Session, :social_provider, UTF8String, :string ], :error
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ module Spotify
2
+ class API
3
+ # @!group ToplistBrowse
4
+ attach_function :toplistbrowse_create, [ Session, :toplisttype, :toplistregion, UTF8String, :toplistbrowse_complete_cb, :userdata ], ToplistBrowse
5
+ attach_function :toplistbrowse_is_loaded, [ ToplistBrowse ], :bool
6
+ attach_function :toplistbrowse_error, [ ToplistBrowse ], :error
7
+ attach_function :toplistbrowse_num_artists, [ ToplistBrowse ], :int
8
+ attach_function :toplistbrowse_artist, [ ToplistBrowse, :int ], Artist
9
+ attach_function :toplistbrowse_num_albums, [ ToplistBrowse ], :int
10
+ attach_function :toplistbrowse_album, [ ToplistBrowse, :int ], Album
11
+ attach_function :toplistbrowse_num_tracks, [ ToplistBrowse ], :int
12
+ attach_function :toplistbrowse_track, [ ToplistBrowse, :int ], Track
13
+ attach_function :toplistbrowse_backend_request_duration, [ ToplistBrowse ], :int
14
+ attach_function :toplistbrowse_add_ref, [ ToplistBrowse ], :error
15
+ attach_function :toplistbrowse_release, [ ToplistBrowse ], :error
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module Spotify
2
+ class API
3
+ # @!group Track
4
+ attach_function :track_is_loaded, [ Track ], :bool
5
+ attach_function :track_error, [ Track ], :error
6
+ attach_function :track_get_availability, [ Session, Track ], :track_availability
7
+ attach_function :track_is_local, [ Session, Track ], :bool
8
+ attach_function :track_is_autolinked, [ Session, Track ], :bool
9
+ attach_function :track_is_starred, [ Session, Track ], :bool
10
+ attach_function :track_set_starred, [ Session, :array, :int, :bool ], :error
11
+ attach_function :track_num_artists, [ Track ], :int
12
+ attach_function :track_artist, [ Track, :int ], Artist
13
+ attach_function :track_album, [ Track ], Album
14
+ attach_function :track_name, [ Track ], UTF8String
15
+ attach_function :track_duration, [ Track ], :int
16
+ attach_function :track_popularity, [ Track ], :int
17
+ attach_function :track_disc, [ Track ], :int
18
+ attach_function :track_index, [ Track ], :int
19
+ attach_function :track_is_placeholder, [ Track ], :bool
20
+ attach_function :track_get_playable, [ Session, Track ], Track
21
+ attach_function :track_offline_get_status, [ Track ], :track_offline_status
22
+ attach_function :localtrack_create, [ UTF8String, UTF8String, UTF8String, :int ], Track
23
+ attach_function :track_add_ref, [ Track ], :error
24
+ attach_function :track_release, [ Track ], :error
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ module Spotify
2
+ class API
3
+ # @!group User
4
+ attach_function :user_canonical_name, [ User ], UTF8String
5
+ attach_function :user_display_name, [ User ], UTF8String
6
+ attach_function :user_is_loaded, [ User ], :bool
7
+ attach_function :user_add_ref, [ User ], :error
8
+ attach_function :user_release, [ User ], :error
9
+ end
10
+ end
@@ -0,0 +1,109 @@
1
+ module Spotify
2
+ class API
3
+ typedef :pointer, :frames
4
+ typedef :pointer, :userdata
5
+ typedef :pointer, :array
6
+
7
+ #
8
+ # Error
9
+ #
10
+ enum :error, [:ok, 0,
11
+ :bad_api_version, :api_initialization_failed, :track_not_playable,
12
+
13
+ :bad_application_key, 5,
14
+ :bad_username_or_password, :user_banned,
15
+ :unable_to_contact_server, :client_too_old, :other_permanent,
16
+ :bad_user_agent, :missing_callback, :invalid_indata,
17
+ :index_out_of_range, :user_needs_premium, :other_transient,
18
+ :is_loading, :no_stream_available, :permission_denied,
19
+ :inbox_is_full, :no_cache, :no_such_user, :no_credentials,
20
+ :network_disabled, :invalid_device_id, :cant_open_trace_file,
21
+ :application_banned,
22
+
23
+ :offline_too_many_tracks, 31,
24
+ :offline_disk_cache, :offline_expired, :offline_not_allowed,
25
+ :offline_license_lost, :offline_license_error,
26
+
27
+ :lastfm_auth_error, 39,
28
+ :invalid_argument, :system_failure]
29
+
30
+ #
31
+ # Audio
32
+ #
33
+ enum :sampletype, [:int16] # int16_native_endian
34
+ enum :bitrate, %w(160k 320k 96k).map(&:to_sym)
35
+
36
+ #
37
+ # Session
38
+ #
39
+ enum :social_provider, [:spotify, :facebook, :lastfm]
40
+ enum :scrobbling_state, [:use_global_setting, :local_enabled, :local_disabled, :global_enabled, :global_disabled]
41
+ enum :connectionstate, [:logged_out, :logged_in, :disconnected, :undefined, :offline]
42
+ enum :connection_type, [:unknown, :none, :mobile, :mobile_roaming, :wifi, :wired]
43
+ enum :connection_rules, [:network , 0x1,
44
+ :network_if_roaming , 0x2,
45
+ :allow_sync_over_mobile, 0x4,
46
+ :allow_sync_over_wifi , 0x8]
47
+
48
+ #
49
+ # Image
50
+ #
51
+ callback :image_loaded_cb, [ Image.retaining_class, :userdata ], :void
52
+ enum :imageformat, [:unknown, -1, :jpeg]
53
+ enum :image_size, [ :normal, :small, :large ]
54
+
55
+ #
56
+ # Link
57
+ #
58
+ enum :linktype, [:invalid, :track, :album, :artist, :search,
59
+ :playlist, :profile, :starred, :localtrack, :image]
60
+
61
+ #
62
+ # Track
63
+ #
64
+ enum :availability, [:unavailable, :available, :not_streamable, :banned_by_artist]
65
+ typedef :availability, :track_availability # for automated testing
66
+ enum :track_offline_status, [:no, :waiting, :downloading, :done, :error, :done_expired, :limit_exceeded, :done_resync]
67
+
68
+ #
69
+ # Album
70
+ #
71
+ callback :albumbrowse_complete_cb, [AlbumBrowse.retaining_class, :userdata], :void
72
+ enum :albumtype, [:album, :single, :compilation, :unknown]
73
+
74
+ #
75
+ # Artist browsing
76
+ #
77
+ callback :artistbrowse_complete_cb, [ArtistBrowse.retaining_class, :userdata], :void
78
+ enum :artistbrowse_type, [:full, :no_tracks, :no_albums]
79
+
80
+ #
81
+ # Search
82
+ #
83
+ callback :search_complete_cb, [Search.retaining_class, :userdata], :void
84
+ enum :search_type, [:standard, :suggest]
85
+
86
+ #
87
+ # Playlist
88
+ #
89
+ enum :playlist_type, [:playlist, :start_folder, :end_folder, :placeholder]
90
+ enum :playlist_offline_status, [:no, :yes, :downloading, :waiting]
91
+
92
+ #
93
+ # User
94
+ #
95
+ enum :relation_type, [:unknown, :none, :unidirectional, :bidirectional]
96
+
97
+ #
98
+ # Toplist
99
+ #
100
+ callback :toplistbrowse_complete_cb, [ToplistBrowse.retaining_class, :userdata], :void
101
+ enum :toplisttype, [:artists, :albums, :tracks]
102
+ enum :toplistregion, [:everywhere, :user]
103
+
104
+ #
105
+ # Inbox
106
+ #
107
+ callback :inboxpost_complete_cb, [Inbox.retaining_class, :userdata], :void
108
+ end
109
+ end
@@ -0,0 +1,62 @@
1
+ module Spotify
2
+ # A generic error class for Spotify errors.
3
+ class Error < StandardError
4
+ class << self
5
+ # Explain a Spotify error with a descriptive message.
6
+ #
7
+ # @param [Symbol, Integer] error
8
+ # @return [String] a decriptive string of the error
9
+ def explain(error)
10
+ error, symbol = disambiguate(error)
11
+
12
+ message = []
13
+ message << "[#{symbol.to_s.upcase}]"
14
+ message << Spotify.error_message(error)
15
+ message << "(#{error})"
16
+
17
+ message.join(' ')
18
+ end
19
+
20
+ # Given a number or a symbol, find both the symbol and the error
21
+ # number it represents.
22
+ #
23
+ # @example given an integer
24
+ # Spotify::Error.disambiguate(0) # => [0, :ok]
25
+ #
26
+ # @example given a symbol
27
+ # Spotify::Error.disambiguate(:ok) # => [0, :ok]
28
+ #
29
+ # @example given bogus
30
+ # Spotify::Error.disambiguate(:bogus) # => [-1, nil]
31
+ #
32
+ # @param [Symbol, Fixnum] error
33
+ # @return [[Fixnum, Symbol]] (error code, error symbol)
34
+ def disambiguate(error)
35
+ @enum ||= Spotify.enum_type(:error)
36
+
37
+ if error.is_a? Symbol
38
+ error = @enum[symbol = error]
39
+ else
40
+ symbol = @enum[error]
41
+ end
42
+
43
+ if error.nil? || symbol.nil?
44
+ [-1, nil]
45
+ else
46
+ [error, symbol]
47
+ end
48
+ end
49
+ end
50
+
51
+ # Overridden to allow raising errors with just an error code.
52
+ #
53
+ # @param [Integer, String] code_or_message spotify error code, or string message.
54
+ def initialize(code_or_message = nil)
55
+ if code_or_message.is_a?(Integer) or code_or_message.is_a?(Symbol)
56
+ code_or_message &&= self.class.explain(code_or_message)
57
+ end
58
+
59
+ super(code_or_message)
60
+ end
61
+ end
62
+ end