greenstripes 0.1.3

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.
@@ -0,0 +1,163 @@
1
+ # GreenStripes
2
+
3
+ # add ../ext/greenstripes to load path
4
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'ext', 'greenstripes'))
5
+
6
+ # require C extension
7
+ require 'greenstripes'
8
+
9
+ # GreenStripes
10
+ module GreenStripes
11
+ class FakeArray
12
+ include Enumerable
13
+
14
+ def initialize(target, objects)
15
+ @target = target
16
+ @num_objects_sym = "num_#{objects}".to_sym
17
+ @object_sym = objects.to_s.chop.to_sym
18
+ end
19
+
20
+ def size
21
+ @target.send(@num_objects_sym)
22
+ end
23
+
24
+ def [](index)
25
+ @target.send(@object_sym, index)
26
+ end
27
+
28
+ def each
29
+ self.size.times do |i|
30
+ yield self[i]
31
+ end
32
+ end
33
+ end
34
+
35
+ class Session
36
+ def initialize(*args) # :nodoc:
37
+ end
38
+
39
+ def to_link
40
+ Link.new(self)
41
+ end
42
+ end
43
+
44
+ class PlaylistContainer
45
+ def playlists
46
+ FakeArray.new(self, :playlists)
47
+ end
48
+ end
49
+
50
+ class Playlist
51
+ def to_link
52
+ Link.new(self)
53
+ end
54
+
55
+ def ==(other)
56
+ self.to_link == other.to_link
57
+ end
58
+
59
+ def tracks
60
+ FakeArray.new(self, :tracks)
61
+ end
62
+ end
63
+
64
+ class Search
65
+ def initialize(*args) # :nodoc:
66
+ end
67
+
68
+ def to_link
69
+ Link.new(self)
70
+ end
71
+
72
+ def ==(other)
73
+ self.to_link == other.to_link
74
+ end
75
+
76
+ def artists
77
+ FakeArray.new(self, :artists)
78
+ end
79
+
80
+ def albums
81
+ FakeArray.new(self, :albums)
82
+ end
83
+
84
+ def tracks
85
+ FakeArray.new(self, :tracks)
86
+ end
87
+ end
88
+
89
+ class ArtistBrowse
90
+ def initialize(*args) # :nodoc:
91
+ end
92
+
93
+ def tracks
94
+ FakeArray.new(self, :tracks)
95
+ end
96
+
97
+ def similar_artists
98
+ FakeArray.new(self, :similar_artists)
99
+ end
100
+ end
101
+
102
+ class AlbumBrowse
103
+ def initialize(*args) # :nodoc:
104
+ end
105
+
106
+ def tracks
107
+ FakeArray.new(self, :tracks)
108
+ end
109
+
110
+ def copyrights
111
+ FakeArray.new(self, :copyrights)
112
+ end
113
+ end
114
+
115
+ class Artist
116
+ def to_link
117
+ Link.new(self)
118
+ end
119
+
120
+ def ==(other)
121
+ self.to_link == other.to_link
122
+ end
123
+ end
124
+
125
+ class Album
126
+ def to_link
127
+ Link.new(self)
128
+ end
129
+
130
+ def ==(other)
131
+ self.to_link == other.to_link
132
+ end
133
+ end
134
+
135
+ class Track
136
+ def to_link
137
+ Link.new(self)
138
+ end
139
+
140
+ def ==(other)
141
+ self.to_link == other.to_link
142
+ end
143
+
144
+ def artists
145
+ FakeArray.new(self, :artists)
146
+ end
147
+ end
148
+
149
+ class Link
150
+ def initialize(*args) # :nodoc:
151
+ end
152
+
153
+ def ==(other)
154
+ self.to_s == other.to_s
155
+ end
156
+ end
157
+ end
158
+
159
+ class String
160
+ def to_link
161
+ ::GreenStripes::Link.new(self)
162
+ end
163
+ end
@@ -0,0 +1,9 @@
1
+ # APPLICATION_KEY should be a binary string containing your libspotify application key.
2
+ # Tip: Use Array#pack, like this: APPLICATION_KEY = [0x00, ..., 0x00].pack('C*')
3
+ APPLICATION_KEY = 'TODO'
4
+
5
+ # USERNAME should be a string containing your Spotify username.
6
+ USERNAME = 'TODO'
7
+
8
+ # PASSWORD should be a string containing your Spotify password.
9
+ PASSWORD = 'TODO'
@@ -0,0 +1,222 @@
1
+ # add ../lib to the load path
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ # add . to the load path
5
+ $:.unshift(File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'greenstripes'
9
+ require 'config'
10
+
11
+ class TestGreenStripes < Test::Unit::TestCase
12
+ def setup
13
+ # TODO: it would actually be better if this was run just once, before all tests
14
+ @session = GreenStripes::Session.new(APPLICATION_KEY, 'GreenStripes', 'tmp', 'tmp')
15
+ @session.login(USERNAME, PASSWORD)
16
+ @session.process_events until @session.connection_state == GreenStripes::ConnectionState::LOGGED_IN
17
+
18
+ # TODO: it would be better if we created a designated test playlist here
19
+ playlist_container = @session.playlist_container
20
+ @session.process_events until playlist_container.num_playlists > 0
21
+ @playlist = playlist_container.playlist(0)
22
+ @session.process_events until @playlist.loaded?
23
+ end
24
+
25
+ def teardown
26
+ @session.logout
27
+ @session.process_events until @session.connection_state == GreenStripes::ConnectionState::LOGGED_OUT
28
+ end
29
+
30
+ def test_user
31
+ user = @session.user
32
+ @session.process_events until user.loaded?
33
+ assert_not_nil(user.display_name)
34
+ assert_not_nil(user.canonical_name)
35
+ end
36
+
37
+ def test_playlist
38
+ assert_not_nil(@playlist.name)
39
+ assert_not_nil(@playlist.owner)
40
+ assert_not_nil(@playlist.collaborative?)
41
+ assert_not_equal(0, @playlist.num_tracks)
42
+ assert_not_nil(@playlist.track(0))
43
+ end
44
+
45
+ def test_search
46
+ query = 'a'
47
+ search = GreenStripes::Search.new(@session, query, 0, 1)
48
+ @session.process_events until search.loaded?
49
+ assert_equal(GreenStripes::Error::OK, search.error)
50
+ assert_equal(query, search.query)
51
+ assert_not_nil(search.did_you_mean)
52
+ assert_not_equal(0, search.num_artists)
53
+ assert_not_nil(search.artist(0))
54
+ assert_not_equal(0, search.num_albums)
55
+ assert_not_nil(search.album(0))
56
+ assert_not_equal(0, search.num_tracks)
57
+ assert_not_nil(search.track(0))
58
+ end
59
+
60
+ def test_artist_browse
61
+ track = @playlist.track(0)
62
+ @session.process_events until track.loaded?
63
+ artist_browse = GreenStripes::ArtistBrowse.new(@session, track.artist(0))
64
+ @session.process_events until artist_browse.loaded?
65
+ assert_equal(GreenStripes::Error::OK, artist_browse.error)
66
+ assert_equal(track.artist(0), artist_browse.artist)
67
+ assert_not_equal(0, artist_browse.num_tracks)
68
+ assert_not_nil(artist_browse.track(0))
69
+ assert_not_equal(0, artist_browse.num_similar_artists)
70
+ assert_not_nil(artist_browse.similar_artist(0))
71
+ assert_not_nil(artist_browse.biography)
72
+ end
73
+
74
+ def test_album_browse
75
+ track = @playlist.track(0)
76
+ @session.process_events until track.loaded?
77
+ album_browse = GreenStripes::AlbumBrowse.new(@session, track.album)
78
+ @session.process_events until album_browse.loaded?
79
+ assert_equal(GreenStripes::Error::OK, album_browse.error)
80
+ assert_equal(track.album, album_browse.album)
81
+ assert_equal(track.album.artist, album_browse.artist)
82
+ assert_not_equal(0, album_browse.num_tracks)
83
+ assert_not_nil(album_browse.track(0))
84
+ assert_not_equal(0, album_browse.num_copyrights)
85
+ assert_not_nil(album_browse.copyright(0))
86
+ assert_not_nil(album_browse.review)
87
+ end
88
+
89
+ def test_link_from_objects
90
+ track = @playlist.track(0)
91
+ search = GreenStripes::Search.new(@session, 'a', 0, 1)
92
+ @session.process_events until track.loaded? and search.loaded?
93
+ [@playlist, search, track.artist(0), track.album, track].each do |obj|
94
+ assert_kind_of(GreenStripes::Link, GreenStripes::Link.new(obj))
95
+ assert_kind_of(GreenStripes::Link, obj.to_link)
96
+ end
97
+ end
98
+
99
+ def test_link_from_strings
100
+ %w{spotify:artist:3mvkWMe6swnknwscwvGCHO
101
+ spotify:album:57SkIVhE1QfVnShjmvKw3O
102
+ spotify:track:3DTrAmImiol2ugB5wsqFcx
103
+ spotify:user:sarnesjo:playlist:3nCwOiwDiZtv9xsuEIFw4q
104
+ spotify:search:a}.each do |str|
105
+ assert_kind_of(GreenStripes::Link, GreenStripes::Link.new(str))
106
+ assert_kind_of(GreenStripes::Link, str.to_link)
107
+ end
108
+ end
109
+
110
+ def test_fake_array_for_playlist_container
111
+ playlist_container = @session.playlist_container
112
+ assert_not_equal(0, playlist_container.num_playlists)
113
+ assert_equal(playlist_container.num_playlists, playlist_container.playlists.size)
114
+ assert_not_nil(playlist_container.playlist(0))
115
+ assert_equal(playlist_container.playlist(0), playlist_container.playlists[0])
116
+ playlist_container.playlists.each do |p|
117
+ assert_not_nil(p)
118
+ end
119
+ end
120
+
121
+ def test_fake_array_for_playlist
122
+ assert_not_equal(0, @playlist.num_tracks)
123
+ assert_equal(@playlist.num_tracks, @playlist.tracks.size)
124
+ assert_not_nil(@playlist.track(0))
125
+ assert_equal(@playlist.track(0), @playlist.tracks[0])
126
+ @playlist.tracks.each do |t|
127
+ assert_not_nil(t)
128
+ end
129
+ end
130
+
131
+ def test_fake_array_for_search
132
+ query = 'a'
133
+ search = GreenStripes::Search.new(@session, query, 0, 1)
134
+ @session.process_events until search.loaded?
135
+ assert_equal(GreenStripes::Error::OK, search.error)
136
+
137
+ assert_not_equal(0, search.num_artists)
138
+ assert_equal(search.num_artists, search.artists.size)
139
+ assert_not_nil(search.artist(0))
140
+ assert_equal(search.artist(0), search.artists[0])
141
+ search.artists.each do |a|
142
+ assert_not_nil(a)
143
+ end
144
+
145
+ assert_not_equal(0, search.num_albums)
146
+ assert_equal(search.num_albums, search.albums.size)
147
+ assert_not_nil(search.album(0))
148
+ assert_equal(search.album(0), search.albums[0])
149
+ search.albums.each do |a|
150
+ assert_not_nil(a)
151
+ end
152
+
153
+ assert_not_equal(0, search.num_tracks)
154
+ assert_equal(search.num_tracks, search.tracks.size)
155
+ assert_not_nil(search.track(0))
156
+ assert_equal(search.track(0), search.tracks[0])
157
+ search.tracks.each do |t|
158
+ assert_not_nil(t)
159
+ end
160
+ end
161
+
162
+ def test_fake_array_for_artist_browse
163
+ track = @playlist.track(0)
164
+ @session.process_events until track.loaded?
165
+ artist_browse = GreenStripes::ArtistBrowse.new(@session, track.artist(0))
166
+ @session.process_events until artist_browse.loaded?
167
+ assert_equal(GreenStripes::Error::OK, artist_browse.error)
168
+
169
+ assert_not_equal(0, artist_browse.num_tracks)
170
+ assert_equal(artist_browse.num_tracks, artist_browse.tracks.size)
171
+ assert_not_nil(artist_browse.track(0))
172
+ assert_equal(artist_browse.track(0), artist_browse.tracks[0])
173
+ artist_browse.tracks.each do |t|
174
+ assert_not_nil(t)
175
+ end
176
+
177
+ assert_not_equal(0, artist_browse.num_similar_artists)
178
+ assert_equal(artist_browse.num_similar_artists, artist_browse.similar_artists.size)
179
+ assert_not_nil(artist_browse.similar_artist(0))
180
+ assert_equal(artist_browse.similar_artist(0), artist_browse.similar_artists[0])
181
+ artist_browse.similar_artists.each do |a|
182
+ assert_not_nil(a)
183
+ end
184
+ end
185
+
186
+ def test_fake_array_for_album_browse
187
+ track = @playlist.track(0)
188
+ @session.process_events until track.loaded?
189
+ album_browse = GreenStripes::AlbumBrowse.new(@session, track.album)
190
+ @session.process_events until album_browse.loaded?
191
+ assert_equal(GreenStripes::Error::OK, album_browse.error)
192
+
193
+ assert_not_equal(0, album_browse.num_tracks)
194
+ assert_equal(album_browse.num_tracks, album_browse.tracks.size)
195
+ assert_not_nil(album_browse.track(0))
196
+ assert_equal(album_browse.track(0), album_browse.tracks[0])
197
+ album_browse.tracks.each do |t|
198
+ assert_not_nil(t)
199
+ end
200
+
201
+ assert_not_equal(0, album_browse.num_copyrights)
202
+ assert_equal(album_browse.num_copyrights, album_browse.copyrights.size)
203
+ assert_not_nil(album_browse.copyright(0))
204
+ assert_equal(album_browse.copyright(0), album_browse.copyrights[0])
205
+ album_browse.copyrights.each do |c|
206
+ assert_not_nil(c)
207
+ end
208
+ end
209
+
210
+ def test_fake_array_for_track
211
+ track = @playlist.track(0)
212
+ @session.process_events until track.loaded?
213
+
214
+ assert_not_equal(0, track.num_artists)
215
+ assert_equal(track.num_artists, track.artists.size)
216
+ assert_not_nil(track.artist(0))
217
+ assert_equal(track.artist(0), track.artists[0])
218
+ track.artists.each do |a|
219
+ assert_not_nil(a)
220
+ end
221
+ end
222
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greenstripes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - "Jesper S\xC3\xA4rnesj\xC3\xB6"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-30 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jesper@sarnesjo.org
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/greenstripes/extconf.rb
22
+ extra_rdoc_files:
23
+ - ext/greenstripes/greenstripes.c
24
+ files:
25
+ - ext/greenstripes/extconf.rb
26
+ - ext/greenstripes/greenstripes.c
27
+ - lib/greenstripes.rb
28
+ has_rdoc: true
29
+ homepage: http://github.com/sarnesjo/greenstripes
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --charset=UTF-8
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Ruby bindings for libspotify
56
+ test_files:
57
+ - test/config.rb.sample
58
+ - test/test_greenstripes.rb