glutton_lastfm 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -154,6 +154,13 @@ The following custom exceptions may be thrown by the library:
154
154
 
155
155
  /usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:330:in `pull': Missing end tag for 'HR' (got "BODY") (REXML::ParseException)
156
156
 
157
+ == Change Log
158
+
159
+ * 0.1.0 - Initial release.
160
+ * 0.1.1 - Minor post-initial release patch.
161
+ * 0.1.2 - Yanked bad fix.
162
+ * 0.1.3 - Methods that return arrays (i.e. all methods other than the info ones) were fixed for result sizes of zero or one. (See: fix_empties_or_singles)
163
+
157
164
  == Thanks
158
165
 
159
166
  Respect to the creators and maintainers of HTTParty, FakeWeb and Jeweler.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{glutton_lastfm}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wally Glutton"]
12
- s.date = %q{2010-05-10}
12
+ s.date = %q{2010-06-11}
13
13
  s.description = %q{Simple last.fm API wrapper written using HTTParty in Ruby.}
14
14
  s.email = %q{stungeye@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,7 +28,18 @@ Gem::Specification.new do |s|
28
28
  "glutton_lastfm.gemspec",
29
29
  "lib/glutton_lastfm.rb",
30
30
  "test/fixtures/artist_info_prince.xml",
31
+ "test/fixtures/artist_multi_tags_top_tags.xml",
32
+ "test/fixtures/artist_no_albums_top_albums.xml",
33
+ "test/fixtures/artist_no_events.xml",
34
+ "test/fixtures/artist_no_tags_top_tags.xml",
31
35
  "test/fixtures/invalid_api_key.xml",
36
+ "test/fixtures/known_album_album_search.xml",
37
+ "test/fixtures/known_artist_artist_search.xml",
38
+ "test/fixtures/multi_album_top_albums.xml",
39
+ "test/fixtures/one_album_top_albums.xml",
40
+ "test/fixtures/unknown_album_album_search.xml",
41
+ "test/fixtures/unknown_artist_artist_search.xml",
42
+ "test/fixtures/unknown_artist_top_albums.xml",
32
43
  "test/helper.rb",
33
44
  "test/test_glutton_lastfm.rb"
34
45
  ]
@@ -34,28 +34,41 @@ class GluttonLastfm
34
34
  end
35
35
 
36
36
  def artist_search( artist )
37
- q( :method => 'artist.search', :artist => artist )['results']['artistmatches']['artist']
37
+ query = q( :method => 'artist.search', :artist => artist )['results']
38
+ if query['artistmatches'].nil?
39
+ []
40
+ else
41
+ fix_empties_or_singles query['artistmatches'], 'artist'
42
+ end
38
43
  end
39
44
 
40
45
  def album_search( album )
41
- q( :method => 'album.search', :album => album )['results']['albummatches']['album']
46
+ query = q( :method => 'album.search', :album => album )['results']
47
+ if query['albummatches'].nil?
48
+ []
49
+ else
50
+ fix_empties_or_singles query['albummatches'], 'album'
51
+ end
42
52
  end
43
53
 
44
54
  def artist_top_albums( artist )
45
- q( :method => 'artist.gettopalbums', :artist => artist )['topalbums']['album']
55
+ query = q( :method => 'artist.gettopalbums', :artist => artist )['topalbums']
56
+ fix_empties_or_singles query, 'album'
46
57
  end
47
58
 
48
59
  def artist_top_tracks( artist )
49
- q( :method => 'artist.gettoptracks', :artist => artist )['toptracks']['track']
60
+ query = q( :method => 'artist.gettoptracks', :artist => artist )['toptracks']
61
+ fix_empties_or_singles query, 'track'
50
62
  end
51
63
 
52
64
  def artist_top_tags( artist )
53
- q( :method => 'artist.gettoptags', :artist => artist )['toptags']['tag']
65
+ query = q( :method => 'artist.gettoptags', :artist => artist )['toptags']
66
+ fix_empties_or_singles query, 'tag'
54
67
  end
55
68
 
56
69
  def artist_events( artist )
57
- response = q( :method => 'artist.getevents', :artist => artist )['events']
58
- (response['total'].to_i == 0) ? [] : response['event']
70
+ query = q( :method => 'artist.getevents', :artist => artist )['events']
71
+ fix_empties_or_singles query, 'event'
59
72
  end
60
73
 
61
74
  def album_info( artist, album )
@@ -75,6 +88,15 @@ class GluttonLastfm
75
88
  end
76
89
 
77
90
  private
91
+
92
+ # When fetching a plural resource we sometimes have to fix the returned data.
93
+ # When no data is found we return an empty array.
94
+ # When one item is found it must be placed in an array.
95
+ # Note: Extra guards are needed above for the album/artist searches.
96
+ def fix_empties_or_singles query, key
97
+ query = query[key].nil? ? [] : query[key]
98
+ (query.class == Array) ? query : [query]
99
+ end
78
100
 
79
101
  def raise_errors(response, options)
80
102
  case response.code.to_i
@@ -0,0 +1,403 @@
1
+ <lfm status="ok">
2
+ <toptags artist="Buck 65">
3
+ <tag>
4
+ <name>Hip-Hop</name>
5
+ <count>100</count>
6
+ <url>http://www.last.fm/tag/hip-hop</url>
7
+ </tag> <tag>
8
+ <name>Canadian</name>
9
+ <count>49</count>
10
+ <url>http://www.last.fm/tag/canadian</url>
11
+ </tag> <tag>
12
+ <name>hip hop</name>
13
+ <count>42</count>
14
+ <url>http://www.last.fm/tag/hip%20hop</url>
15
+ </tag> <tag>
16
+ <name>indie</name>
17
+ <count>28</count>
18
+ <url>http://www.last.fm/tag/indie</url>
19
+ </tag> <tag>
20
+ <name>rap</name>
21
+ <count>28</count>
22
+ <url>http://www.last.fm/tag/rap</url>
23
+ </tag> <tag>
24
+ <name>underground hip hop</name>
25
+ <count>17</count>
26
+ <url>http://www.last.fm/tag/underground%20hip%20hop</url>
27
+ </tag> <tag>
28
+ <name>alternative</name>
29
+ <count>13</count>
30
+ <url>http://www.last.fm/tag/alternative</url>
31
+ </tag> <tag>
32
+ <name>underground hip-hop</name>
33
+ <count>13</count>
34
+ <url>http://www.last.fm/tag/underground%20hip-hop</url>
35
+ </tag> <tag>
36
+ <name>abstract hip-hop</name>
37
+ <count>8</count>
38
+ <url>http://www.last.fm/tag/abstract%20hip-hop</url>
39
+ </tag> <tag>
40
+ <name>experimental</name>
41
+ <count>8</count>
42
+ <url>http://www.last.fm/tag/experimental</url>
43
+ </tag> <tag>
44
+ <name>hiphop</name>
45
+ <count>6</count>
46
+ <url>http://www.last.fm/tag/hiphop</url>
47
+ </tag> <tag>
48
+ <name>anticon</name>
49
+ <count>6</count>
50
+ <url>http://www.last.fm/tag/anticon</url>
51
+ </tag> <tag>
52
+ <name>alternative hip-hop</name>
53
+ <count>4</count>
54
+ <url>http://www.last.fm/tag/alternative%20hip-hop</url>
55
+ </tag> <tag>
56
+ <name>canada</name>
57
+ <count>3</count>
58
+ <url>http://www.last.fm/tag/canada</url>
59
+ </tag> <tag>
60
+ <name>alternative rap</name>
61
+ <count>3</count>
62
+ <url>http://www.last.fm/tag/alternative%20rap</url>
63
+ </tag> <tag>
64
+ <name>folk</name>
65
+ <count>3</count>
66
+ <url>http://www.last.fm/tag/folk</url>
67
+ </tag> <tag>
68
+ <name>underground rap</name>
69
+ <count>3</count>
70
+ <url>http://www.last.fm/tag/underground%20rap</url>
71
+ </tag> <tag>
72
+ <name>electronic</name>
73
+ <count>3</count>
74
+ <url>http://www.last.fm/tag/electronic</url>
75
+ </tag> <tag>
76
+ <name>singer-songwriter</name>
77
+ <count>2</count>
78
+ <url>http://www.last.fm/tag/singer-songwriter</url>
79
+ </tag> <tag>
80
+ <name>Canadian Hip-Hop</name>
81
+ <count>2</count>
82
+ <url>http://www.last.fm/tag/canadian%20hip-hop</url>
83
+ </tag> <tag>
84
+ <name>turntablism</name>
85
+ <count>2</count>
86
+ <url>http://www.last.fm/tag/turntablism</url>
87
+ </tag> <tag>
88
+ <name>indie hip-hop</name>
89
+ <count>2</count>
90
+ <url>http://www.last.fm/tag/indie%20hip-hop</url>
91
+ </tag> <tag>
92
+ <name>underground</name>
93
+ <count>2</count>
94
+ <url>http://www.last.fm/tag/underground</url>
95
+ </tag> <tag>
96
+ <name>blues</name>
97
+ <count>2</count>
98
+ <url>http://www.last.fm/tag/blues</url>
99
+ </tag> <tag>
100
+ <name>trip-hop</name>
101
+ <count>2</count>
102
+ <url>http://www.last.fm/tag/trip-hop</url>
103
+ </tag> <tag>
104
+ <name>rock</name>
105
+ <count>2</count>
106
+ <url>http://www.last.fm/tag/rock</url>
107
+ </tag> <tag>
108
+ <name>abstract hip hop</name>
109
+ <count>1</count>
110
+ <url>http://www.last.fm/tag/abstract%20hip%20hop</url>
111
+ </tag> <tag>
112
+ <name>electronica</name>
113
+ <count>1</count>
114
+ <url>http://www.last.fm/tag/electronica</url>
115
+ </tag> <tag>
116
+ <name>experimental hip-hop</name>
117
+ <count>1</count>
118
+ <url>http://www.last.fm/tag/experimental%20hip-hop</url>
119
+ </tag> <tag>
120
+ <name>Buck 65</name>
121
+ <count>1</count>
122
+ <url>http://www.last.fm/tag/buck%2065</url>
123
+ </tag> <tag>
124
+ <name>poetry</name>
125
+ <count>1</count>
126
+ <url>http://www.last.fm/tag/poetry</url>
127
+ </tag> <tag>
128
+ <name>Nova Scotia</name>
129
+ <count>1</count>
130
+ <url>http://www.last.fm/tag/nova%20scotia</url>
131
+ </tag> <tag>
132
+ <name>Indie Hip Hop</name>
133
+ <count>1</count>
134
+ <url>http://www.last.fm/tag/indie%20hip%20hop</url>
135
+ </tag> <tag>
136
+ <name>East Coast</name>
137
+ <count>1</count>
138
+ <url>http://www.last.fm/tag/east%20coast</url>
139
+ </tag> <tag>
140
+ <name>abstract</name>
141
+ <count>1</count>
142
+ <url>http://www.last.fm/tag/abstract</url>
143
+ </tag> <tag>
144
+ <name>chill</name>
145
+ <count>1</count>
146
+ <url>http://www.last.fm/tag/chill</url>
147
+ </tag> <tag>
148
+ <name>beats</name>
149
+ <count>1</count>
150
+ <url>http://www.last.fm/tag/beats</url>
151
+ </tag> <tag>
152
+ <name>jazz</name>
153
+ <count>1</count>
154
+ <url>http://www.last.fm/tag/jazz</url>
155
+ </tag> <tag>
156
+ <name>indie rap</name>
157
+ <count>1</count>
158
+ <url>http://www.last.fm/tag/indie%20rap</url>
159
+ </tag> <tag>
160
+ <name>country</name>
161
+ <count>1</count>
162
+ <url>http://www.last.fm/tag/country</url>
163
+ </tag> <tag>
164
+ <name>Favorite</name>
165
+ <count>0</count>
166
+ <url>http://www.last.fm/tag/favorite</url>
167
+ </tag> <tag>
168
+ <name>chillout</name>
169
+ <count>0</count>
170
+ <url>http://www.last.fm/tag/chillout</url>
171
+ </tag> <tag>
172
+ <name>ambient</name>
173
+ <count>0</count>
174
+ <url>http://www.last.fm/tag/ambient</url>
175
+ </tag> <tag>
176
+ <name>saw live</name>
177
+ <count>0</count>
178
+ <url>http://www.last.fm/tag/saw%20live</url>
179
+ </tag> <tag>
180
+ <name>fresh</name>
181
+ <count>0</count>
182
+ <url>http://www.last.fm/tag/fresh</url>
183
+ </tag> <tag>
184
+ <name>funky</name>
185
+ <count>0</count>
186
+ <url>http://www.last.fm/tag/funky</url>
187
+ </tag> <tag>
188
+ <name>metal</name>
189
+ <count>0</count>
190
+ <url>http://www.last.fm/tag/metal</url>
191
+ </tag> <tag>
192
+ <name>funk</name>
193
+ <count>0</count>
194
+ <url>http://www.last.fm/tag/funk</url>
195
+ </tag> <tag>
196
+ <name>canadian rap</name>
197
+ <count>0</count>
198
+ <url>http://www.last.fm/tag/canadian%20rap</url>
199
+ </tag> <tag>
200
+ <name>acid jazz</name>
201
+ <count>0</count>
202
+ <url>http://www.last.fm/tag/acid%20jazz</url>
203
+ </tag> <tag>
204
+ <name>halifax</name>
205
+ <count>0</count>
206
+ <url>http://www.last.fm/tag/halifax</url>
207
+ </tag> <tag>
208
+ <name>reflection</name>
209
+ <count>0</count>
210
+ <url>http://www.last.fm/tag/reflection</url>
211
+ </tag> <tag>
212
+ <name>Favourites</name>
213
+ <count>0</count>
214
+ <url>http://www.last.fm/tag/favourites</url>
215
+ </tag> <tag>
216
+ <name>introspection</name>
217
+ <count>0</count>
218
+ <url>http://www.last.fm/tag/introspection</url>
219
+ </tag> <tag>
220
+ <name>Fusion</name>
221
+ <count>0</count>
222
+ <url>http://www.last.fm/tag/fusion</url>
223
+ </tag> <tag>
224
+ <name>Reflective</name>
225
+ <count>0</count>
226
+ <url>http://www.last.fm/tag/reflective</url>
227
+ </tag> <tag>
228
+ <name>white rap</name>
229
+ <count>0</count>
230
+ <url>http://www.last.fm/tag/white%20rap</url>
231
+ </tag> <tag>
232
+ <name>Indie-Rock</name>
233
+ <count>0</count>
234
+ <url>http://www.last.fm/tag/indie-rock</url>
235
+ </tag> <tag>
236
+ <name>literate</name>
237
+ <count>0</count>
238
+ <url>http://www.last.fm/tag/literate</url>
239
+ </tag> <tag>
240
+ <name>amazing lyricist</name>
241
+ <count>0</count>
242
+ <url>http://www.last.fm/tag/amazing%20lyricist</url>
243
+ </tag> <tag>
244
+ <name>Oh Canada</name>
245
+ <count>0</count>
246
+ <url>http://www.last.fm/tag/oh%20canada</url>
247
+ </tag> <tag>
248
+ <name>experimental hip hop</name>
249
+ <count>0</count>
250
+ <url>http://www.last.fm/tag/experimental%20hip%20hop</url>
251
+ </tag> <tag>
252
+ <name>Broken Beat</name>
253
+ <count>0</count>
254
+ <url>http://www.last.fm/tag/broken%20beat</url>
255
+ </tag> <tag>
256
+ <name>experimental rap</name>
257
+ <count>0</count>
258
+ <url>http://www.last.fm/tag/experimental%20rap</url>
259
+ </tag> <tag>
260
+ <name>best of the wire 2005</name>
261
+ <count>0</count>
262
+ <url>http://www.last.fm/tag/best%20of%20the%20wire%202005</url>
263
+ </tag> <tag>
264
+ <name>abstract rap</name>
265
+ <count>0</count>
266
+ <url>http://www.last.fm/tag/abstract%20rap</url>
267
+ </tag> <tag>
268
+ <name>ambitious</name>
269
+ <count>0</count>
270
+ <url>http://www.last.fm/tag/ambitious</url>
271
+ </tag> <tag>
272
+ <name>Jazz Hop</name>
273
+ <count>0</count>
274
+ <url>http://www.last.fm/tag/jazz%20hop</url>
275
+ </tag> <tag>
276
+ <name>post hip-hop</name>
277
+ <count>0</count>
278
+ <url>http://www.last.fm/tag/post%20hip-hop</url>
279
+ </tag> <tag>
280
+ <name>Progressive rock</name>
281
+ <count>0</count>
282
+ <url>http://www.last.fm/tag/progressive%20rock</url>
283
+ </tag> <tag>
284
+ <name>bands ive seen live</name>
285
+ <count>0</count>
286
+ <url>http://www.last.fm/tag/bands%20ive%20seen%20live</url>
287
+ </tag> <tag>
288
+ <name>check out</name>
289
+ <count>0</count>
290
+ <url>http://www.last.fm/tag/check%20out</url>
291
+ </tag> <tag>
292
+ <name>indie rock</name>
293
+ <count>0</count>
294
+ <url>http://www.last.fm/tag/indie%20rock</url>
295
+ </tag> <tag>
296
+ <name>Hipster-Hop</name>
297
+ <count>0</count>
298
+ <url>http://www.last.fm/tag/hipster-hop</url>
299
+ </tag> <tag>
300
+ <name>Bittersweet</name>
301
+ <count>0</count>
302
+ <url>http://www.last.fm/tag/bittersweet</url>
303
+ </tag> <tag>
304
+ <name>idm</name>
305
+ <count>0</count>
306
+ <url>http://www.last.fm/tag/idm</url>
307
+ </tag> <tag>
308
+ <name>downtempo</name>
309
+ <count>0</count>
310
+ <url>http://www.last.fm/tag/downtempo</url>
311
+ </tag> <tag>
312
+ <name>Have Seen Live</name>
313
+ <count>0</count>
314
+ <url>http://www.last.fm/tag/have%20seen%20live</url>
315
+ </tag> <tag>
316
+ <name>now playing</name>
317
+ <count>0</count>
318
+ <url>http://www.last.fm/tag/now%20playing</url>
319
+ </tag> <tag>
320
+ <name>lounge</name>
321
+ <count>0</count>
322
+ <url>http://www.last.fm/tag/lounge</url>
323
+ </tag> <tag>
324
+ <name>hardcore</name>
325
+ <count>0</count>
326
+ <url>http://www.last.fm/tag/hardcore</url>
327
+ </tag> <tag>
328
+ <name>Self-Conscious</name>
329
+ <count>0</count>
330
+ <url>http://www.last.fm/tag/self-conscious</url>
331
+ </tag> <tag>
332
+ <name>Intelligent Rap</name>
333
+ <count>0</count>
334
+ <url>http://www.last.fm/tag/intelligent%20rap</url>
335
+ </tag> <tag>
336
+ <name>shit so awesome it will snap your penis in half</name>
337
+ <count>0</count>
338
+ <url>http://www.last.fm/tag/shit%20so%20awesome%20it%20will%20snap%20your%20penis%20in%20half</url>
339
+ </tag> <tag>
340
+ <name>samples</name>
341
+ <count>0</count>
342
+ <url>http://www.last.fm/tag/samples</url>
343
+ </tag> <tag>
344
+ <name>classic rock</name>
345
+ <count>0</count>
346
+ <url>http://www.last.fm/tag/classic%20rock</url>
347
+ </tag> <tag>
348
+ <name>seen live</name>
349
+ <count>0</count>
350
+ <url>http://www.last.fm/tag/seen%20live</url>
351
+ </tag> <tag>
352
+ <name>Totec Radio</name>
353
+ <count>0</count>
354
+ <url>http://www.last.fm/tag/totec%20radio</url>
355
+ </tag> <tag>
356
+ <name>Decouverte</name>
357
+ <count>0</count>
358
+ <url>http://www.last.fm/tag/decouverte</url>
359
+ </tag> <tag>
360
+ <name>great vocalist</name>
361
+ <count>0</count>
362
+ <url>http://www.last.fm/tag/great%20vocalist</url>
363
+ </tag> <tag>
364
+ <name>back and to the left</name>
365
+ <count>0</count>
366
+ <url>http://www.last.fm/tag/back%20and%20to%20the%20left</url>
367
+ </tag> <tag>
368
+ <name>ZET</name>
369
+ <count>0</count>
370
+ <url>http://www.last.fm/tag/zet</url>
371
+ </tag> <tag>
372
+ <name>General shit I like</name>
373
+ <count>0</count>
374
+ <url>http://www.last.fm/tag/general%20shit%20i%20like</url>
375
+ </tag> <tag>
376
+ <name>raspy vocals</name>
377
+ <count>0</count>
378
+ <url>http://www.last.fm/tag/raspy%20vocals</url>
379
+ </tag> <tag>
380
+ <name>want to hear</name>
381
+ <count>0</count>
382
+ <url>http://www.last.fm/tag/want%20to%20hear</url>
383
+ </tag> <tag>
384
+ <name>rappy</name>
385
+ <count>0</count>
386
+ <url>http://www.last.fm/tag/rappy</url>
387
+ </tag> <tag>
388
+ <name>shows attended</name>
389
+ <count>0</count>
390
+ <url>http://www.last.fm/tag/shows%20attended</url>
391
+ </tag> <tag>
392
+ <name>funky funk</name>
393
+ <count>0</count>
394
+ <url>http://www.last.fm/tag/funky%20funk</url>
395
+ </tag> <tag>
396
+ <name>new zic</name>
397
+ <count>0</count>
398
+ <url>http://www.last.fm/tag/new%20zic</url>
399
+ </tag> <tag>
400
+ <name>hick-hop</name>
401
+ <count>0</count>
402
+ <url>http://www.last.fm/tag/hick-hop</url>
403
+ </tag></toptags></lfm>