spotify 12.5.3 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,18 +1,96 @@
1
1
  module Spotify
2
2
  class API
3
3
  # @!group AlbumBrowse
4
+
5
+ # @example
6
+ # # this is called some time later, as a result of calling {#session_process_events}
7
+ # browse_callback = proc do |album_browse|
8
+ # puts "Album browse has completed!"
9
+ # end
10
+ # album_browse = Spotify.albumbrowse_create(session, album, browse_callback, nil)
11
+ #
12
+ # @note make *very* sure the callback proc is not garbage collected before it is called!
13
+ # @param [Session] session
14
+ # @param [Album] album
15
+ # @param [Proc<AlbumBrowse, FFI::Pointer>] callback
16
+ # @param [FFI::Pointer] userdata
17
+ # @return [AlbumBrowse] a request for browsing an album
18
+ # @method albumbrowse_create(session, album, albumbrowse_complete_callback, userdata)
4
19
  attach_function :albumbrowse_create, [ Session, Album, :albumbrowse_complete_cb, :userdata ], AlbumBrowse
20
+
21
+ # @param [AlbumBrowse] album_browse
22
+ # @return [Boolean] true if the album browse request has completed
23
+ # @method albumbrowse_is_loaded(album_browse)
5
24
  attach_function :albumbrowse_is_loaded, [ AlbumBrowse ], :bool
6
- attach_function :albumbrowse_error, [ AlbumBrowse ], :error
25
+
26
+ # @param [AlbumBrowse] album_browse
27
+ # @return [Symbol] album browsing error code
28
+ # @method albumbrowse_error(album_browse)
29
+ attach_function :albumbrowse_error, [ AlbumBrowse ], APIError
30
+
31
+ # @see #albumbrowse_is_loaded
32
+ # @note the album browse request must have completed, or this function always return nil.
33
+ # @param [AlbumBrowse] album_browse
34
+ # @return [Album, nil] the album being browsed
35
+ # @method albumbrowse_album(album_browse)
7
36
  attach_function :albumbrowse_album, [ AlbumBrowse ], Album
37
+
38
+ # @see #albumbrowse_is_loaded
39
+ # @note the album browse request must have completed, or this function always return nil.
40
+ # @param [AlbumBrowse] album_browse
41
+ # @return [Artist, nil] the authoring artist of the album being browsed
42
+ # @method albumbrowse_artist(album_browse)
8
43
  attach_function :albumbrowse_artist, [ AlbumBrowse ], Artist
44
+
45
+ # @see #albumbrowse_is_loaded
46
+ # @see #albumbrowse_copyright
47
+ # @note the album browse request must have completed, or this function always return 0.
48
+ # @param [AlbumBrowse] album_browse
49
+ # @return [Integer] number of copyright strings on the album being browsed
50
+ # @method albumbrowse_num_copyrights(album_browse)
9
51
  attach_function :albumbrowse_num_copyrights, [ AlbumBrowse ], :int
52
+
53
+ # @see #albumbrowse_is_loaded
54
+ # @see #albumbrowse_num_copyrights
55
+ # @note if index is out of range, returns nil.
56
+ # @param [AlbumBrowse] album_browse
57
+ # @param [Integer] index number within 0...{#albumbrowse_num_copyrights}
58
+ # @return [String, nil] the copyright string at index
59
+ # @method albumbrowse_copyright(album_browse, index)
10
60
  attach_function :albumbrowse_copyright, [ AlbumBrowse, :int ], UTF8String
61
+
62
+ # @see #albumbrowse_is_loaded
63
+ # @see #albumbrowse_track
64
+ # @note the album browse request must have completed, or this function always return 0.
65
+ # @param [AlbumBrowse] album_browse
66
+ # @return [Integer] number of tracks on the album being browsed
67
+ # @method albumbrowse_num_tracks(album_browse)
11
68
  attach_function :albumbrowse_num_tracks, [ AlbumBrowse ], :int
69
+
70
+ # @see #albumbrowse_is_loaded
71
+ # @see #albumbrowse_num_tracks
72
+ # @note if index is out of range, returns nil.
73
+ # @param [AlbumBrowse] album_browse
74
+ # @param [Integer] index number within 0...{#albumbrowse_num_tracks}
75
+ # @return [Track, nil] the track at index
76
+ # @method albumbrowse_track(album_browse, index)
12
77
  attach_function :albumbrowse_track, [ AlbumBrowse, :int ], Track
78
+
79
+ # @see #albumbrowse_is_loaded
80
+ # @note the album browse request must have completed, or this function always return an empty string.
81
+ # @param [AlbumBrowse] album_browse
82
+ # @return [String] the review for the album being browsed
83
+ # @method albumbrowse_review(album_browse)
13
84
  attach_function :albumbrowse_review, [ AlbumBrowse ], UTF8String
85
+
86
+ # @see #albumbrowse_is_loaded
87
+ # @note the album browse request must have completed, or this function will return an undefined value.
88
+ # @param [AlbumBrowse] album_browse
89
+ # @return [Integer] the time (in ms) that was spent waiting for the Spotify backend to serve the request, -1 if served from local cache
90
+ # @method albumbrowse_backend_request_duration(album_browse)
14
91
  attach_function :albumbrowse_backend_request_duration, [ AlbumBrowse ], :int
15
- attach_function :albumbrowse_add_ref, [ AlbumBrowse ], :error
16
- attach_function :albumbrowse_release, [ AlbumBrowse ], :error
92
+
93
+ attach_function :albumbrowse_add_ref, [ AlbumBrowse ], APIError
94
+ attach_function :albumbrowse_release, [ AlbumBrowse ], APIError
17
95
  end
18
96
  end
@@ -1,10 +1,29 @@
1
1
  module Spotify
2
2
  class API
3
3
  # @!group Artist
4
+
5
+ # @see #artist_is_loaded
6
+ # @note the artist must be loaded, or this function always return an empty string.
7
+ # @param [Artist] artist
8
+ # @return [String] name of the artist
9
+ # @method artist_name(artist)
4
10
  attach_function :artist_name, [ Artist ], UTF8String
11
+
12
+ # @param [Artist] artist
13
+ # @return [Boolean] true if the artist is populated with data
14
+ # @method artist_is_loaded(artist)
5
15
  attach_function :artist_is_loaded, [ Artist ], :bool
16
+
17
+ # @see #image_create
18
+ # @see #artist_is_loaded
19
+ # @note the artist must be loaded, or this function always return nil.
20
+ # @param [Artist] artist
21
+ # @param [Symbol] image_size one of :normal, :small, :large
22
+ # @return [String, nil] image ID to pass to {#image_create}, or nil if the artist has no image
23
+ # @method artist_portrait(artist, image_size)
6
24
  attach_function :artist_portrait, [ Artist, :image_size ], ImageID
7
- attach_function :artist_add_ref, [ Artist ], :error
8
- attach_function :artist_release, [ Artist ], :error
25
+
26
+ attach_function :artist_add_ref, [ Artist ], APIError
27
+ attach_function :artist_release, [ Artist ], APIError
9
28
  end
10
29
  end
@@ -1,23 +1,141 @@
1
1
  module Spotify
2
2
  class API
3
3
  # @!group ArtistBrowse
4
+
5
+ # @example
6
+ # # this is called some time later, as a result of calling {#session_process_events}
7
+ # browse_callback = proc do |artist_browse|
8
+ # puts "Artist browse has completed!"
9
+ # end
10
+ # artist_browse = Spotify.artistbrowse_create(session, artist, :no_albums, browse_callback, nil)
11
+ #
12
+ # @note make *very* sure the callback proc is not garbage collected before it is called!
13
+ # @param [Session] session
14
+ # @param [Artist] artist
15
+ # @param [Symbol] type one of :full, :no_tracks, :no_albums
16
+ # @param [Proc<ArtistBrowse, FFI::Pointer>] callback
17
+ # @param [FFI::Pointer] userdata
18
+ # @return [ArtistBrowse] a request for browsing an artist
19
+ # @method artistbrowse_create(session, artist, type, callback, userdata)
4
20
  attach_function :artistbrowse_create, [ Session, Artist, :artistbrowse_type, :artistbrowse_complete_cb, :userdata ], ArtistBrowse
21
+
22
+ # @param [ArtistBrowse] artist_browse
23
+ # @return [Boolean] true if the artist browse request has completed
24
+ # @method artistbrowse_is_loaded(artist_browse)
5
25
  attach_function :artistbrowse_is_loaded, [ ArtistBrowse ], :bool
6
- attach_function :artistbrowse_error, [ ArtistBrowse ], :error
26
+
27
+ # @param [ArtistBrowse] artist_browse
28
+ # @return [Symbol] artist browsing error code
29
+ # @method artistbrowse_error(artist_browse)
30
+ attach_function :artistbrowse_error, [ ArtistBrowse ], APIError
31
+
32
+ # @see #artistbrowse_is_loaded
33
+ # @note the artist browse request must have completed, or this function always return nil.
34
+ # @param [ArtistBrowse] artist_browse
35
+ # @return [Artist, nil] the artist being browsed
36
+ # @method artistbrowse_artist(artist_browse)
7
37
  attach_function :artistbrowse_artist, [ ArtistBrowse ], Artist
38
+
39
+ # @see #artistbrowse_is_loaded
40
+ # @see #artistbrowse_portrait
41
+ # @note the artist browse request must have completed, or this function always return 0.
42
+ # @param [ArtistBrowse] artist_browse
43
+ # @return [Integer] number of artist portraits
44
+ # @method artistbrowse_num_portraits(artist_browse)
8
45
  attach_function :artistbrowse_num_portraits, [ ArtistBrowse ], :int
46
+
47
+ # @see #artistbrowse_is_loaded
48
+ # @see #artistbrowse_num_portraits
49
+ # @note if index is out of range, returns nil.
50
+ # @param [ArtistBrowse] artist_browse
51
+ # @param [Integer] index number within 0...{#artistbrowse_num_portraits}
52
+ # @return [String, nil] image ID to pass to {#image_create}
53
+ # @method artistbrowse_portrait(artist_browse, index)
9
54
  attach_function :artistbrowse_portrait, [ ArtistBrowse, :int ], ImageID
55
+
56
+ # @see #artistbrowse_is_loaded
57
+ # @see #artistbrowse_track
58
+ # @note the artist browse request must have completed, or this function always return 0.
59
+ # @param [ArtistBrowse] artist_browse
60
+ # @return [Integer] number of artist tracks
61
+ # @method artistbrowse_num_tracks(artist_browse)
10
62
  attach_function :artistbrowse_num_tracks, [ ArtistBrowse ], :int
63
+
64
+ # @see #artistbrowse_is_loaded
65
+ # @see #artistbrowse_num_tracks
66
+ # @note if index is out of range, returns nil.
67
+ # @param [ArtistBrowse] artist_browse
68
+ # @param [Integer] index number within 0...{#artistbrowse_num_tracks}
69
+ # @return [Track, nil] the track at index
70
+ # @method artistbrowse_track(artist_browse, index)
11
71
  attach_function :artistbrowse_track, [ ArtistBrowse, :int ], Track
72
+
73
+ # @see #artistbrowse_is_loaded
74
+ # @see #artistbrowse_album
75
+ # @note the artist browse request must have completed, or this function always return 0.
76
+ # @param [ArtistBrowse] artist_browse
77
+ # @return [Integer] number of artist albums
78
+ # @method artistbrowse_num_albums(artist_browse)
12
79
  attach_function :artistbrowse_num_albums, [ ArtistBrowse ], :int
80
+
81
+ # @see #artistbrowse_is_loaded
82
+ # @see #artistbrowse_num_albums
83
+ # @note if index is out of range, returns nil.
84
+ # @param [ArtistBrowse] artist_browse
85
+ # @param [Integer] index number within 0...{#artistbrowse_num_albums}
86
+ # @return [Track, nil] the album at index
87
+ # @method artistbrowse_album(artist_browse, index)
13
88
  attach_function :artistbrowse_album, [ ArtistBrowse, :int ], Album
89
+
90
+ # @see #artistbrowse_is_loaded
91
+ # @see #artistbrowse_similar_artist
92
+ # @note the artist browse request must have completed, or this function always return 0.
93
+ # @param [ArtistBrowse] artist_browse
94
+ # @return [Integer] number of similar artists
95
+ # @method artistbrowse_num_similar_artists(artist_browse)
14
96
  attach_function :artistbrowse_num_similar_artists, [ ArtistBrowse ], :int
97
+
98
+ # @see #artistbrowse_is_loaded
99
+ # @see #artistbrowse_num_similar_artists
100
+ # @note if index is out of range, returns nil.
101
+ # @param [ArtistBrowse] artist_browse
102
+ # @param [Integer] index number within 0...{#artistbrowse_num_similar_artists}
103
+ # @return [Track, nil] a similar artist at index
104
+ # @method artistbrowse_similar_artist(artist_browse, index)
15
105
  attach_function :artistbrowse_similar_artist, [ ArtistBrowse, :int ], Artist
106
+
107
+ # @see #artistbrowse_is_loaded
108
+ # @note the artist browse request must have completed, or this function always return an empty string.
109
+ # @param [ArtistBrowse] artist_browse
110
+ # @return [String] the review for the artist being browsed
111
+ # @method artistbrowse_biography(artist_browse)
16
112
  attach_function :artistbrowse_biography, [ ArtistBrowse ], UTF8String
113
+
114
+ # @see #artistbrowse_is_loaded
115
+ # @note the artist browse request must have completed, or this function will return an undefined value.
116
+ # @param [ArtistBrowse] artist_browse
117
+ # @return [Integer] the time (in ms) that was spent waiting for the Spotify backend to serve the request, -1 if served from local cache
118
+ # @method artistbrowse_backend_request_duration(artist_browse)
17
119
  attach_function :artistbrowse_backend_request_duration, [ ArtistBrowse ], :int
120
+
121
+ # @see #artistbrowse_is_loaded
122
+ # @see #artistbrowse_tophit_track
123
+ # @note the artist browse request must have completed, or this function always return 0.
124
+ # @param [ArtistBrowse] artist_browse
125
+ # @return [Integer] number of tophit tracks
126
+ # @method artistbrowse_num_tophit_tracks(artist_browse)
18
127
  attach_function :artistbrowse_num_tophit_tracks, [ ArtistBrowse ], :int
128
+
129
+ # @see #artistbrowse_is_loaded
130
+ # @see #artistbrowse_num_tophit_tracks
131
+ # @note if index is out of range, returns nil.
132
+ # @param [ArtistBrowse] artist_browse
133
+ # @param [Integer] index number within 0...{#artistbrowse_num_tophit_tracks}
134
+ # @return [Track, nil] the tophit track at index
135
+ # @method artistbrowse_tophit_track(artist_browse, index)
19
136
  attach_function :artistbrowse_tophit_track, [ ArtistBrowse, :int ], Track
20
- attach_function :artistbrowse_add_ref, [ ArtistBrowse ], :error
21
- attach_function :artistbrowse_release, [ ArtistBrowse ], :error
137
+
138
+ attach_function :artistbrowse_add_ref, [ ArtistBrowse ], APIError
139
+ attach_function :artistbrowse_release, [ ArtistBrowse ], APIError
22
140
  end
23
141
  end
@@ -1,6 +1,10 @@
1
1
  module Spotify
2
2
  class API
3
3
  # @!group Error
4
- attach_function :error_message, [ :error ], UTF8String
4
+
5
+ # @param [Error] error
6
+ # @return [String] explanatory error message for an error code
7
+ # @method error_message(error)
8
+ attach_function :error_message, [ APIError ], UTF8String
5
9
  end
6
10
  end
@@ -1,16 +1,82 @@
1
1
  module Spotify
2
2
  class API
3
3
  # @!group Image
4
+
5
+ # @param [Session] session
6
+ # @param [String] image_id
7
+ # @return [Image] image from an image id
8
+ # @method image_create(session, image_id)
4
9
  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
10
+
11
+ # Add a callback that will be invoked when the image is loaded.
12
+ #
13
+ # @note make *very* sure the callback proc is not garbage collected before it is called!
14
+ # @see #image_remove_load_callback
15
+ # @param [Image] image
16
+ # @param [Proc<Image, FFI::Pointer>] callback
17
+ # @param [FFI::Pointer] userdata
18
+ # @return [Symbol] error code
19
+ # @method image_add_load_callback(image, callback, userdata)
20
+ attach_function :image_add_load_callback, [ Image, :image_loaded_cb, :userdata ], APIError
21
+
22
+ # Remove an image load callback previously added with {#image_add_load_callback}.
23
+ #
24
+ # @see #image_add_load_callback
25
+ # @param [Image] image
26
+ # @param [Proc<Image, FFI::Pointer>] callback
27
+ # @param [FFI::Pointer] userdata
28
+ # @return [Symbol] error code
29
+ # @method image_remove_load_callback(image, callback, userdata)
30
+ attach_function :image_remove_load_callback, [ Image, :image_loaded_cb, :userdata ], APIError
31
+
32
+ # @note Images that don't exist in Spotify can also return true.
33
+ # @param [Image] image
34
+ # @return [Boolean] true if the image information has been retrieved
35
+ # @method image_is_loaded(image)
7
36
  attach_function :image_is_loaded, [ Image ], :bool
8
- attach_function :image_error, [ Image ], :error
37
+
38
+ # @param [Image] image
39
+ # @return [Symbol] image error code
40
+ # @method image_error(image)
41
+ attach_function :image_error, [ Image ], APIError
42
+
43
+ # @see #image_is_loaded
44
+ # @note the image must be loaded, or this function always return :unknown.
45
+ # @param [Image] image
46
+ # @return [Symbol] image format, one of :unknown, or :jpeg
47
+ # @method image_format(image)
9
48
  attach_function :image_format, [ Image ], :imageformat
10
- attach_function :image_data, [ Image, :buffer_out ], :pointer
49
+
50
+ # Retrieves raw image data.
51
+ #
52
+ # @example
53
+ # Spotify.image_data(image) # => "\xFF\xD8\xFF\xE0…
54
+ #
55
+ # @see #image_is_loaded
56
+ # @note the image must be loaded, or this function always return nil.
57
+ # @param [Image] image
58
+ # @return [String, nil] raw image data, or nil if no image data available
59
+ # @method image_data(image)
60
+ attach_function :image_data, [ Image, :buffer_out ], :pointer do |image|
61
+ with_buffer(:size_t, clear: true) do |image_size_buffer|
62
+ data = sp_image_data(image, image_size_buffer)
63
+ image_size = image_size_buffer.read_size_t
64
+ data.read_bytes(image_size) if image_size > 0
65
+ end
66
+ end
67
+
68
+ # @param [Image] image
69
+ # @return [String] image id
70
+ # @method image_image_id(image)
11
71
  attach_function :image_image_id, [ Image ], ImageID
72
+
73
+ # @param [Session] session
74
+ # @param [Link] link
75
+ # @return [Image, nil] image pointed to by link, or nil if link is not a valid image link
76
+ # @method image_create_from_link(session, link)
12
77
  attach_function :image_create_from_link, [ Session, Link ], Image
13
- attach_function :image_add_ref, [ Image ], :error
14
- attach_function :image_release, [ Image ], :error
78
+
79
+ attach_function :image_add_ref, [ Image ], APIError
80
+ attach_function :image_release, [ Image ], APIError
15
81
  end
16
82
  end
@@ -1,9 +1,38 @@
1
1
  module Spotify
2
2
  class API
3
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
4
+
5
+ # Post an array of tracks to a Spotify user's inbox.
6
+ #
7
+ # @example
8
+ # callback = proc do |inbox|
9
+ # puts "Message posted."
10
+ # end
11
+ # inbox = Spotify.inbox_post_tracks(session, "burgestrand", tracks, "You must listen to these!", callback, nil)
12
+ #
13
+ # @param [Session] session
14
+ # @param [String] username canonical username of recipient
15
+ # @param [Array<Track>, Track] tracks
16
+ # @param [String] message message to attach to post
17
+ # @param [Proc<Inbox, FFI::Pointer] callback to call on completion
18
+ # @param [FFI::Pointer] userdata
19
+ # @return [Inbox]
20
+ # @method inbox_post_tracks(session, username, tracks, message, callback, userdata)
21
+ attach_function :inbox_post_tracks, [ Session, UTF8String, :array, :int, UTF8String, :inboxpost_complete_cb, :userdata ], Inbox do |session, username, tracks, message, callback, userdata|
22
+ tracks = Array(tracks)
23
+
24
+ with_buffer(Spotify::Track, size: tracks.length) do |tracks_buffer|
25
+ tracks_buffer.write_array_of_pointer(tracks)
26
+ sp_inbox_post_tracks(session, username, tracks_buffer, tracks.length, message, callback, userdata)
27
+ end
28
+ end
29
+
30
+ # @param [Inbox] inbox
31
+ # @return [Symbol] error status of inbox post
32
+ # @method inbox_error(inbox)
33
+ attach_function :inbox_error, [ Inbox ], APIError
34
+
35
+ attach_function :inbox_add_ref, [ Inbox ], APIError
36
+ attach_function :inbox_release, [ Inbox ], APIError
8
37
  end
9
38
  end
@@ -1,25 +1,138 @@
1
1
  module Spotify
2
2
  class API
3
3
  # @!group Link
4
+
5
+ # Create a Link from a Spotify URI or Spotify HTTP URL.
6
+ #
7
+ # @param [String] spotify_uri can be regular spotify URI, or spotify HTTP URL
8
+ # @return [Link]
9
+ # @method link_create_from_string(spotify_uri)
4
10
  attach_function :link_create_from_string, [ BestEffortString ], Link
11
+
12
+ # @param [Track] track
13
+ # @param [Integer] offset number of milliseconds into track to link to
14
+ # @return [Link, nil]
15
+ # @method link_create_from_track(track, offset)
5
16
  attach_function :link_create_from_track, [ Track, :int ], Link
17
+
18
+ # @param [Album] album
19
+ # @return [Link, nil]
20
+ # @method link_create_from_album(album)
6
21
  attach_function :link_create_from_album, [ Album ], Link
22
+
23
+ # @param [Artist] artist
24
+ # @return [Link, nil]
25
+ # @method link_create_from_artist(artist)
7
26
  attach_function :link_create_from_artist, [ Artist ], Link
27
+
28
+ # @param [Search] search
29
+ # @return [Link, nil]
30
+ # @method link_create_from_search(search)
8
31
  attach_function :link_create_from_search, [ Search ], Link
32
+
33
+ # @param [Playlist] playlist
34
+ # @return [Link, nil]
35
+ # @method link_create_from_playlist(playlist)
9
36
  attach_function :link_create_from_playlist, [ Playlist ], Link
37
+
38
+ # @param [Artist] artist
39
+ # @param [Symbol] image_size one of :normal, :small, :large
40
+ # @return [Link, nil]
41
+ # @method link_create_from_artist_portrait(artist, image_size)
10
42
  attach_function :link_create_from_artist_portrait, [ Artist, :image_size ], Link
43
+
44
+ # @see #artistbrowse_num_portraits
45
+ # @param [ArtistBrowse] artist_browse
46
+ # @param [Integer] index number within 0...{#artistbrowse_num_portraits}
47
+ # @return [Link, nil]
48
+ # @method link_create_from_artistbrowse_portrait(artist_browse, index)
11
49
  attach_function :link_create_from_artistbrowse_portrait, [ ArtistBrowse, :int ], Link
50
+
51
+ # @param [Album] album
52
+ # @param [Symbol] image_size one of :normal, :small, :large
53
+ # @return [Link, nil]
54
+ # @method link_create_from_album_cover(album, image_size)
12
55
  attach_function :link_create_from_album_cover, [ Album, :image_size ], Link
56
+
57
+ # @example image id from spotify URI
58
+ # image_id = ":\xD94#\xAD\xD9\x97f\xE0-V6\x05\xC6\xE7n\xD2\xB0\xE4P"
59
+ # image_uri = "spotify:image:3ad93423add99766e02d563605c6e76ed2b0e450"
60
+ # image = Spotify.image_create(session, image_id)
61
+ # image_link = Spotify.link_create_from_image(image)
62
+ #
63
+ # # And here are some cool equivalents:
64
+ # image_id == ["3ad93423add99766e02d563605c6e76ed2b0e450"].pack("H40")
65
+ # image_uri == "spotify:image:#{image_id.unpack("H40")[0]}"
66
+ # image_link == Spotify.link_create_from_string(image_uri)
67
+ # image == Spotify.image_create_from_link(session, image_link)
68
+ #
69
+ # @param [Image] image
70
+ # @return [Link]
71
+ # @method link_create_from_image(image)
13
72
  attach_function :link_create_from_image, [ Image ], Link
73
+
74
+ # @param [User] user
75
+ # @return [Link]
76
+ # @method link_create_from_user(user)
14
77
  attach_function :link_create_from_user, [ User ], Link
15
- attach_function :link_as_string, [ Link, :buffer_out, :int ], :int
78
+
79
+ # Retrieve string representation of link.
80
+ #
81
+ # @example
82
+ # Spotify.link_as_string(link) # => "spotify:user:burgestrand"
83
+ #
84
+ # @param [Link] link
85
+ # @return [String] string representation of the link
86
+ # @method link_as_string(link)
87
+ attach_function :link_as_string, [ Link, :buffer_out, :int ], :int do |link|
88
+ link_length = sp_link_as_string(link, nil, 0)
89
+ with_string_buffer(link_length) do |string_buffer, size|
90
+ sp_link_as_string(link, string_buffer, size)
91
+ end
92
+ end
93
+
94
+ # @param [Link] link
95
+ # @return [Symbol] type of link, one of :invalid, :track, :album, :artist, :search, :playlist, :profile, :starred, :localtrack, :image
96
+ # @method link_type(link)
16
97
  attach_function :link_type, [ Link ], :linktype
98
+
99
+ # @param [Link] link
100
+ # @return [Track, nil] track pointed to by the link, or nil if not a track
101
+ # @method link_as_track(link)
17
102
  attach_function :link_as_track, [ Link ], Track
18
- attach_function :link_as_track_and_offset, [ Link, :buffer_out ], Track
103
+
104
+ # @example
105
+ # Spotify.link_as_track_and_offset(link) # => [track, 1337]
106
+ #
107
+ # @note if the link is not a track link, this method returns nil.
108
+ # @note if no track offset is available in the link, the offset out will always be set to 0.
109
+ #
110
+ # @param [Link] link
111
+ # @return [Array<Track, Integer>, nil] track and offset (in ms) as a tuple, or nil
112
+ # @method link_as_track_and_offset(link)
113
+ attach_function :link_as_track_and_offset, [ Link, :buffer_out ], Track do |link|
114
+ with_buffer(:int) do |offset_buffer|
115
+ track = sp_link_as_track_and_offset(link, offset_buffer)
116
+ [track, offset_buffer.read_int] if track
117
+ end
118
+ end
119
+
120
+ # @param [Link] link
121
+ # @return [Album, nil] album pointed to by the link, or nil if not an album
122
+ # @method link_as_album(link)
19
123
  attach_function :link_as_album, [ Link ], Album
124
+
125
+ # @param [Link] link
126
+ # @return [Artist, nil] artist pointed to by the link, or nil if not an artist
127
+ # @method link_as_artist(link)
20
128
  attach_function :link_as_artist, [ Link ], Artist
129
+
130
+ # @param [Link] link
131
+ # @return [User, nil] user pointed to by the link, or nil if not a user
132
+ # @method link_as_user(link)
21
133
  attach_function :link_as_user, [ Link ], User
22
- attach_function :link_add_ref, [ Link ], :error
23
- attach_function :link_release, [ Link ], :error
134
+
135
+ attach_function :link_add_ref, [ Link ], APIError
136
+ attach_function :link_release, [ Link ], APIError
24
137
  end
25
138
  end