lastfm 1.17.0 → 1.18.0

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.
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  gem.name = %q{lastfm}
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "1.17.0"
15
+ gem.version = "1.18.0"
16
16
 
17
17
  gem.add_dependency "xml-simple"
18
18
  gem.add_dependency "httparty"
@@ -1,8 +1,12 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Album < Base
4
- regular_method :get_info, [:artist, :album], [] do |response|
4
+ regular_method(
5
+ :get_info,
6
+ :required => any_params([:artist, :album], :mbid)
7
+ ) do |response|
5
8
  result = response.xml['album']
9
+
6
10
  result['releasedate'].lstrip! unless result['releasedate'].empty?
7
11
  result
8
12
  end
@@ -1,39 +1,74 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Artist < Base
4
- regular_method :get_top_tracks, [:artist], [] do |response|
4
+ regular_method(
5
+ :get_top_tracks,
6
+ :required => [:artist]
7
+ ) do |response|
5
8
  response.xml['toptracks']['track']
6
9
  end
7
10
 
8
- regular_method :get_top_albums, [:artist], [] do |response|
11
+ regular_method(
12
+ :get_top_albums,
13
+ :required => [:artist]
14
+ ) do |response|
9
15
  response.xml['topalbums']['album']
10
16
  end
11
17
 
12
- regular_method :get_info, [:artist], [] do |response|
18
+ regular_method(
19
+ :get_info,
20
+ :required => [:artist]
21
+ ) do |response|
13
22
  response.xml['artist']
14
23
  end
15
24
 
16
- regular_method :get_events, [:artist], [] do |response|
25
+ regular_method(
26
+ :get_events,
27
+ :required => [:artist]
28
+ ) do |response|
17
29
  response.xml['events']['event']
18
30
  end
19
31
 
20
- regular_method :get_images, [:artist], [] do |response|
32
+ regular_method(
33
+ :get_images,
34
+ :required => [:artist]
35
+ ) do |response|
21
36
  response.xml['images']['image']
22
37
  end
23
38
 
24
- regular_method :get_similar, [:artist], [] do |response|
39
+ regular_method(:get_similar,
40
+ :required => [:artist]
41
+ ) do |response|
25
42
  response.xml['similarartists']['artist']
26
43
  end
27
44
 
28
- regular_method :get_tags, [:artist], [[:user, nil], [:mbid, nil], [:autocorrect, nil]] do |response|
45
+ regular_method(
46
+ :get_tags,
47
+ :required => [:artist],
48
+ :optional => [
49
+ [:user, nil],
50
+ [:mbid, nil],
51
+ [:autocorrect, nil]
52
+ ]
53
+ ) do |response|
29
54
  response.xml['tags']['tag']
30
55
  end
31
-
32
- regular_method :get_top_fans, [:artist], [] do |response|
56
+
57
+ regular_method(
58
+ :get_top_fans,
59
+ :required => [:artist]
60
+ ) do |response|
33
61
  response.xml['topfans']['user']
34
62
  end
35
63
 
36
- regular_method :search, [:artist], [[:limit, nil], [:page, nil]]
64
+ regular_method(
65
+ :search,
66
+ :required => [:artist],
67
+ :optional => [
68
+ [:limit, nil],
69
+ [:page, nil]
70
+ ]
71
+ )
37
72
  end
38
73
  end
39
74
  end
@@ -1,15 +1,21 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Auth < Base
4
- method_for_authentication :get_token, [], [] do |response|
4
+ method_for_authentication :get_token do |response|
5
5
  response.xml['token']
6
6
  end
7
7
 
8
- method_for_authentication :get_session, [:token], [] do |response|
8
+ method_for_authentication(
9
+ :get_session,
10
+ :required => [:token]
11
+ ) do |response|
9
12
  response.xml['session']
10
13
  end
11
14
 
12
- method_for_secure_authentication :get_mobile_session, [:username, :password], [] do |response|
15
+ method_for_secure_authentication(
16
+ :get_mobile_session,
17
+ :required => [:username, :password]
18
+ ) do |response|
13
19
  response.xml['session']
14
20
  end
15
21
  end
@@ -1,36 +1,58 @@
1
1
  class Lastfm
2
+ class AnyParams
3
+ attr_reader :candidates
4
+
5
+ def initialize(candidates)
6
+ @candidates = candidates
7
+ end
8
+ end
9
+
2
10
  module MethodCategory
3
11
  class Base
4
12
  class << self
5
- def write_method(id, mandatory, optional = [])
6
- __define_method(:write_request, id, mandatory, optional) do |response|
13
+ def any_params(*args)
14
+ AnyParams.new(args)
15
+ end
16
+
17
+ def write_method(id, params = {})
18
+ __define_method(:write_request, id, params) do |response|
7
19
  response.success?
8
20
  end
9
21
  end
10
22
 
11
- def method_with_authentication(id, mandatory, optional = [], &block)
12
- __define_method(:request_with_authentication, id, mandatory, optional, &block)
23
+ def method_with_authentication(id, params = {}, &block)
24
+ __define_method(:request_with_authentication, id, params, &block)
13
25
  end
14
26
 
15
- def method_for_authentication(id, mandatory, optional = [], &block)
16
- __define_method(:request_for_authentication, id, mandatory, optional, &block)
27
+ def method_for_authentication(id, params = {}, &block)
28
+ __define_method(:request_for_authentication, id, params, &block)
17
29
  end
18
30
 
19
- def method_for_secure_authentication(id, mandatory, optional = [], &block)
20
- __define_method(:request_for_secure_authentication, id, mandatory, optional, &block)
31
+ def method_for_secure_authentication(id, params = {}, &block)
32
+ __define_method(:request_for_secure_authentication, id, params, &block)
21
33
  end
22
34
 
23
- def regular_method(id, mandatory, optional = [], &block)
24
- __define_method(:request, id, mandatory, optional, &block)
35
+ def regular_method(id, params = {}, &block)
36
+ __define_method(:request, id, params, &block)
25
37
  end
26
38
 
27
- def __define_method(method, id, mandatory, optional, &block)
39
+ def __define_method(method, id, params, &block)
28
40
  unless block
29
41
  block = Proc.new { |response| response.xml }
30
42
  end
31
43
 
32
44
  define_method(id) do |*args|
33
- block.call(send(method, id.to_s.camelize(:lower), Lastfm::Util.build_options(args, mandatory, optional)))
45
+ block.call(
46
+ send(
47
+ method,
48
+ id.to_s.camelize(:lower),
49
+ Lastfm::Util.build_options(
50
+ args,
51
+ params[:required],
52
+ params[:optional]
53
+ )
54
+ )
55
+ )
34
56
  end
35
57
  end
36
58
  end
@@ -1,27 +1,63 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Chart < Base
4
- regular_method :get_hyped_artists, [], [[:page, nil], [:limit, nil]] do |response|
4
+ regular_method(
5
+ :get_hyped_artists,
6
+ :optional => [
7
+ [:page, nil],
8
+ [:limit, nil]
9
+ ]
10
+ ) do |response|
5
11
  response.xml['artists']['artist']
6
12
  end
7
13
 
8
- regular_method :get_hyped_tracks, [], [[:page, nil], [:limit, nil]] do |response|
14
+ regular_method(
15
+ :get_hyped_tracks,
16
+ :optional => [
17
+ [:page, nil],
18
+ [:limit, nil]
19
+ ]
20
+ ) do |response|
9
21
  response.xml['tracks']['track']
10
22
  end
11
23
 
12
- regular_method :get_loved_tracks, [], [[:page, nil], [:limit, nil]] do |response|
24
+ regular_method(
25
+ :get_loved_tracks,
26
+ :optional => [
27
+ [:page, nil],
28
+ [:limit, nil]
29
+ ]
30
+ ) do |response|
13
31
  response.xml['tracks']['track']
14
32
  end
15
33
 
16
- regular_method :get_top_artists, [], [[:page, nil], [:limit, nil]] do |response|
34
+ regular_method(
35
+ :get_top_artists,
36
+ :optional => [
37
+ [:page, nil],
38
+ [:limit, nil]
39
+ ]
40
+ ) do |response|
17
41
  response.xml['artists']['artist']
18
42
  end
19
43
 
20
- regular_method :get_top_tags, [], [[:page, nil], [:limit, nil]] do |response|
44
+ regular_method(
45
+ :get_top_tags,
46
+ :optional => [
47
+ [:page, nil],
48
+ [:limit, nil]
49
+ ]
50
+ ) do |response|
21
51
  response.xml['tags']['tag']
22
52
  end
23
53
 
24
- regular_method :get_top_tracks, [], [[:page, nil], [:limit, nil]] do |response|
54
+ regular_method(
55
+ :get_top_tracks,
56
+ :optional => [
57
+ [:page, nil],
58
+ [:limit, nil]
59
+ ]
60
+ ) do |response|
25
61
  response.xml['tracks']['track']
26
62
  end
27
63
  end
@@ -1,7 +1,10 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Event < Base
4
- regular_method :get_info, [:event], [] do |response|
4
+ regular_method(
5
+ :get_info,
6
+ :required => [:event]
7
+ ) do |response|
5
8
  response.xml['event'].first
6
9
  end
7
10
  end
@@ -1,7 +1,15 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Geo < Base
4
- regular_method :get_events, [], [[:location, nil], [:distance, nil], [:limit, nil], [:page, nil]] do |response|
4
+ regular_method(
5
+ :get_events,
6
+ :optional => [
7
+ [:location, nil],
8
+ [:distance, nil],
9
+ [:limit, nil],
10
+ [:page, nil]
11
+ ]
12
+ ) do |response|
5
13
  response.xml['events']['event']
6
14
  end
7
15
  end
@@ -1,11 +1,27 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Library < Base
4
- regular_method :get_artists, [:user], [[:limit, nil], [:page, nil]] do |response|
4
+ regular_method(
5
+ :get_artists,
6
+ :required => [:user],
7
+ :optional => [
8
+ [:limit, nil],
9
+ [:page, nil]
10
+ ]
11
+ ) do |response|
5
12
  Util.force_array(response.xml['artists']['artist'])
6
13
  end
7
14
 
8
- regular_method :get_tracks, [:user], [[:artist, nil], [:album, nil], [:page, nil], [:limit, nil]] do |response|
15
+ regular_method(
16
+ :get_tracks,
17
+ :required => [:user],
18
+ :optional => [
19
+ [:artist, nil],
20
+ [:album, nil],
21
+ [:page, nil],
22
+ [:limit, nil]
23
+ ]
24
+ ) do |response|
9
25
  Util.force_array(response.xml['tracks']['track'])
10
26
  end
11
27
  end
@@ -1,8 +1,8 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Radio < Base
4
- write_method :tune, [:station]
5
- method_with_authentication :get_playlist, [], [] do |response|
4
+ write_method :tune, :required => [:station]
5
+ method_with_authentication :get_playlist do |response|
6
6
  playlist = response.xml['playlist']
7
7
  tracklist = playlist['trackList']['track']
8
8
 
@@ -1,11 +1,25 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Tag < Base
4
- regular_method :get_top_artists, [:tag], [[:limit, nil], [:page, nil]] do |response|
4
+ regular_method(
5
+ :get_top_artists,
6
+ :required => [:tag],
7
+ :optional => [
8
+ [:limit, nil],
9
+ [:page, nil]
10
+ ]
11
+ ) do |response|
5
12
  response.xml['topartists']['artist']
6
13
  end
7
14
 
8
- regular_method :get_top_tracks, [:tag], [[:limit, nil], [:page, nil]] do |response|
15
+ regular_method(
16
+ :get_top_tracks,
17
+ :required => [:tag],
18
+ :optional => [
19
+ [:limit, nil],
20
+ [:page, nil]
21
+ ]
22
+ ) do |response|
9
23
  response.xml['toptracks']['track']
10
24
  end
11
25
  end
@@ -1,7 +1,13 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Tasteometer < Base
4
- regular_method :compare, [:type1, :type2, :value1, :value2], [[:limit, nil]] do |response|
4
+ regular_method(
5
+ :compare,
6
+ :required => [:type1, :type2, :value1, :value2],
7
+ :optional => [
8
+ [:limit, nil]
9
+ ]
10
+ ) do |response|
5
11
  response.xml['comparison']['result']
6
12
  end
7
13
  end
@@ -1,38 +1,98 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class Track < Base
4
- write_method :add_tags, [:artist, :track, :tags]
5
- write_method :remove_tag, [:artist, :track, :tag]
6
- write_method :ban, [:artist, :track]
7
- write_method :love, [:artist, :track]
8
- write_method :share, [:artist, :track, :recipient], [[:message, nil]]
9
- write_method :scrobble, [:artist, :track], [[:timestamp, Proc.new { Time.now.utc.to_i }], [:album, nil], [:trackNumber, nil], [:mbid, nil], [:duration, nil], [:albumArtist, nil]]
10
- write_method :update_now_playing, [:artist, :track], [[:album, nil], [:trackNumber, nil], [:mbid, nil], [:duration, nil], [:albumArtist, nil]]
11
- write_method :unlove, [:artist, :track]
12
-
13
- regular_method :get_info, [:artist, :track], [[:username, nil]] do |response|
4
+ write_method :add_tags, :required => [:artist, :track, :tags]
5
+
6
+ write_method :remove_tag, :required => [:artist, :track, :tag]
7
+
8
+ write_method :ban, :required => [:artist, :track]
9
+
10
+ write_method :love, :required => [:artist, :track]
11
+
12
+ write_method :share, :required => [:artist, :track, :recipient], :optional => [[:message, nil]]
13
+
14
+ write_method(
15
+ :scrobble,
16
+ :required => [:artist, :track],
17
+ :optional => [
18
+ [:timestamp, Proc.new { Time.now.utc.to_i }],
19
+ [:album, nil],
20
+ [:trackNumber, nil],
21
+ [:mbid, nil],
22
+ [:duration, nil],
23
+ [:albumArtist, nil]
24
+ ]
25
+ )
26
+
27
+ write_method(
28
+ :update_now_playing,
29
+ :required => [:artist, :track],
30
+ :optional => [
31
+ [:album, nil],
32
+ [:trackNumber, nil],
33
+ [:mbid, nil],
34
+ [:duration, nil],
35
+ [:albumArtist, nil]
36
+ ]
37
+ )
38
+
39
+ write_method :unlove, :required => [:artist, :track]
40
+
41
+ regular_method(
42
+ :get_info,
43
+ :required => any_params([:artist, :track], :mbid),
44
+ :optional => [
45
+ [:username, nil]
46
+ ]
47
+ ) do |response|
14
48
  response.xml['track']
15
49
  end
16
50
 
17
- regular_method :get_correction, [:artist, :track], [] do |response|
51
+ regular_method(
52
+ :get_correction,
53
+ :required => [:artist, :track]
54
+ ) do |response|
18
55
  response.xml['corrections']['correction']
19
56
  end
20
57
 
21
- regular_method :get_top_fans, [:artist, :track], [] do |response|
58
+ regular_method(
59
+ :get_top_fans,
60
+ :required => [:artist, :track]
61
+ ) do |response|
22
62
  response.xml['topfans']['user']
23
63
  end
24
- regular_method :get_top_tags, [:artist, :track], [] do |response|
64
+
65
+ regular_method(
66
+ :get_top_tags,
67
+ :required => [:artist, :track]
68
+ ) do |response|
25
69
  response.xml['toptags']['tag']
26
70
  end
27
- regular_method :get_similar, [:artist, :track], [] do |response|
71
+
72
+ regular_method(
73
+ :get_similar,
74
+ :required => [:artist, :track]
75
+ ) do |response|
28
76
  response.xml['similartracks']['track'][1 .. -1]
29
77
  end
30
- regular_method :search, [:track], [[:artist, nil], [:limit, nil], [:page, nil]] do |response|
78
+
79
+ regular_method(
80
+ :search,
81
+ :required => [:track],
82
+ :optional => [
83
+ [:artist, nil],
84
+ [:limit, nil],
85
+ [:page, nil]
86
+ ]
87
+ ) do |response|
31
88
  response.xml['results']['trackmatches']['track'] = Util.force_array(response.xml['results']['trackmatches']['track'])
32
89
  response.xml
33
90
  end
34
91
 
35
- method_with_authentication :get_tags, [:artist, :track], [] do |response|
92
+ method_with_authentication(
93
+ :get_tags,
94
+ :required => [:artist, :track]
95
+ ) do |response|
36
96
  response.xml['tags']['tag']
37
97
  end
38
98
  end
@@ -1,26 +1,65 @@
1
1
  class Lastfm
2
2
  module MethodCategory
3
3
  class User < Base
4
- regular_method :get_friends, [:user], [[:recenttracks, nil], [:limit, nil], [:page, nil]] do |response|
4
+ regular_method(
5
+ :get_friends,
6
+ :required => [:user],
7
+ :optional => [
8
+ [:recenttracks, nil],
9
+ [:limit, nil],
10
+ [:page, nil]
11
+ ]
12
+ ) do |response|
5
13
  response.xml['friends']['user']
6
14
  end
7
15
 
8
- regular_method :get_info, [:user], [] do |response|
16
+ def get_info(*args)
17
+ method = :get_info.to_s.camelize(:lower)
18
+ response = if args.any?
19
+ options = Lastfm::Util.build_options(args, [:user], [])
20
+ request(method, options)
21
+ else
22
+ request_with_authentication(method)
23
+ end
9
24
  response.xml['user'][0]
10
25
  end
11
26
 
12
- regular_method :get_loved_tracks, [:user], [[:period, nil], [:limit, nil], [:page, nil]] do |response|
27
+ regular_method(
28
+ :get_loved_tracks,
29
+ :required => [:user],
30
+ :optional => [
31
+ [:period, nil],
32
+ [:limit, nil],
33
+ [:page, nil]
34
+ ]
35
+ ) do |response|
13
36
  response.xml['lovedtracks']['track']
14
37
  end
15
38
 
16
- regular_method :get_neighbours, [:user], [[:recenttracks, nil], [:limit, nil], [:page, nil]] do |response|
39
+ regular_method(
40
+ :get_neighbours,
41
+ :required => [:user],
42
+ :optional => [
43
+ [:recenttracks, nil],
44
+ [:limit, nil],
45
+ [:page, nil]
46
+ ]
47
+ ) do |response|
17
48
  neighbours = response.xml['neighbours']['user']
18
49
  # Ignore first "user" as this is an attribute, not an object.
19
50
  neighbours.delete_at(0) if neighbours[0].is_a? String
20
51
  neighbours
21
52
  end
22
53
 
23
- regular_method :get_personal_tags, [:user, :tag], [[:taggingtype, 'artist'], [:limit, nil], [:page, nil]] do |response|
54
+ regular_method(
55
+ :get_personal_tags,
56
+ :required => [:user, :tag],
57
+ :optional => [
58
+ [:taggingtype, 'artist'],
59
+ [:limit, nil],
60
+ [:page, nil]
61
+ ]
62
+ ) do |response|
24
63
  taggings = response.xml['taggings']
25
64
  result = if taggings['artists']
26
65
  taggings['artists']['artist']
@@ -33,43 +72,112 @@ class Lastfm
33
72
  Lastfm::Util::force_array(result)
34
73
  end
35
74
 
36
- regular_method :get_recent_tracks, [:user], [[:limit, nil], [:page, nil], [:to, nil], [:from, nil]] do |response|
75
+ regular_method(
76
+ :get_recent_tracks,
77
+ :required => [:user],
78
+ :optional => [
79
+ [:limit, nil],
80
+ [:page, nil],
81
+ [:to, nil],
82
+ [:from, nil]
83
+ ]
84
+ ) do |response|
37
85
  response.xml['recenttracks']['track']
38
86
  end
39
87
 
40
- regular_method :get_top_albums, [:user], [[:period, nil], [:limit, nil], [:page, nil]] do |response|
88
+ regular_method(
89
+ :get_top_albums,
90
+ :required => [:user],
91
+ :optional => [
92
+ [:period, nil],
93
+ [:limit, nil],
94
+ [:page, nil]
95
+ ]
96
+ ) do |response|
41
97
  response.xml['topalbums']['album']
42
98
  end
43
99
 
44
- regular_method :get_top_artists, [:user], [[:period, nil], [:limit, nil], [:page, nil]] do |response|
100
+ regular_method(
101
+ :get_top_artists,
102
+ :required => [:user],
103
+ :optional => [
104
+ [:period, nil],
105
+ [:limit, nil],
106
+ [:page, nil]
107
+ ]
108
+ ) do |response|
45
109
  response.xml['topartists']['artist']
46
110
  end
47
111
 
48
- regular_method :get_top_tags, [:user], [[:limit, nil]] do |response|
112
+ regular_method(
113
+ :get_top_tags,
114
+ :required => [:user],
115
+ :optional => [[:limit, nil]]
116
+ ) do |response|
49
117
  response.xml['toptags']['tag']
50
118
  end
51
119
 
52
- regular_method :get_top_tracks, [:user], [[:period, nil], [:limit, nil], [:page, nil]] do |response|
120
+ regular_method(
121
+ :get_top_tracks,
122
+ :required => [:user],
123
+ :optional => [
124
+ [:period, nil],
125
+ [:limit, nil],
126
+ [:page, nil]
127
+ ]
128
+ ) do |response|
53
129
  response.xml['toptracks']['track']
54
130
  end
55
131
 
56
- regular_method :get_weekly_chart_list, [:user], [[:limit, nil]] do |response|
132
+ regular_method(
133
+ :get_weekly_chart_list,
134
+ :required => [:user],
135
+ :optional => [
136
+ [:limit, nil]
137
+ ]
138
+ ) do |response|
57
139
  response.xml['weeklychartlist']['chart']
58
140
  end
59
141
 
60
- regular_method :get_weekly_artist_chart, [:user], [[:from, nil], [:to, nil], [:limit, nil]] do |response|
142
+ regular_method(
143
+ :get_weekly_artist_chart,
144
+ :required => [:user],
145
+ :optional => [
146
+ [:from, nil],
147
+ [:to, nil],
148
+ [:limit, nil]
149
+ ]
150
+ ) do |response|
61
151
  response.xml['weeklyartistchart']['artist']
62
152
  end
63
153
 
64
- regular_method :get_weekly_album_chart, [:user], [[:from, nil], [:to, nil], [:limit, nil]] do |response|
154
+ regular_method(
155
+ :get_weekly_album_chart,
156
+ :required => [:user],
157
+ :optional => [
158
+ [:from, nil],
159
+ [:to, nil],
160
+ [:limit, nil]
161
+ ]
162
+ ) do |response|
65
163
  response.xml['weeklyalbumchart']['album']
66
164
  end
67
165
 
68
- regular_method :get_weekly_track_chart, [:user], [[:from, nil], [:to, nil], [:limit, nil]] do |response|
166
+ regular_method(
167
+ :get_weekly_track_chart,
168
+ :required => [:user],
169
+ :optional => [
170
+ [:from, nil],
171
+ [:to, nil],
172
+ [:limit, nil]
173
+ ]
174
+ ) do |response|
69
175
  response.xml['weeklytrackchart']['track']
70
176
  end
71
177
 
72
- method_with_authentication :get_recommended_events, [], [] do |response|
178
+ method_with_authentication(
179
+ :get_recommended_events
180
+ ) do |response|
73
181
  response.xml['events']['event']
74
182
  end
75
183
  end
@@ -6,15 +6,26 @@ class Lastfm
6
6
 
7
7
  def self.build_options(args, mandatory, optional)
8
8
  if args.first.is_a?(Hash)
9
- build_options_from_hash(args.first, mandatory, optional)
9
+ build_options_from_hash(args.first, mandatory || [], optional || [])
10
10
  else
11
- build_options_from_array(args, mandatory, optional)
11
+ build_options_from_array(args, mandatory || [], optional || [])
12
12
  end
13
13
  end
14
14
 
15
15
  def self.build_options_from_hash(options, mandatory, optional)
16
- mandatory.each do |name|
17
- raise ArgumentError.new("%s is required" % name) unless options[name]
16
+ candidates = mandatory.kind_of?(AnyParams) ? mandatory.candidates : [mandatory]
17
+ candidates.each_with_index do |params, index|
18
+ Array(params).each do |param|
19
+ if !options.has_key?(param)
20
+ if params.equal? candidates.last
21
+ raise ArgumentError.new("%s is required" % param)
22
+ else
23
+ next
24
+ end
25
+ end
26
+ end
27
+
28
+ break
18
29
  end
19
30
 
20
31
  optional.each do |name, value|
@@ -8,7 +8,7 @@ describe '#album' do
8
8
  end
9
9
 
10
10
  describe '#get_info' do
11
- it 'should get info' do
11
+ it 'should get info by artist and album' do
12
12
  @lastfm.should_receive(:request).with('album.getInfo', {
13
13
  :artist => 'Cher', :album => 'Believe'
14
14
  }).and_return(make_response('album_get_info'))
@@ -26,5 +26,24 @@ describe '#album' do
26
26
  album['tracks']['track'][0]['duration'].should == '239'
27
27
  album['tracks']['track'][0]['url'].should == 'http://www.last.fm/music/Cher/_/Believe'
28
28
  end
29
+
30
+ it 'should get info by mbid' do
31
+ @lastfm.should_receive(:request).with('album.getInfo', {
32
+ :mbid => 'xxxxx'
33
+ }).and_return(make_response('album_get_info'))
34
+
35
+ album = @lastfm.album.get_info(:mbid => 'xxxxx')
36
+ album['name'].should == 'Believe'
37
+ album['artist'].should == 'Cher'
38
+ album['id'].should == '2026126'
39
+ album['mbid'].should == '61bf0388-b8a9-48f4-81d1-7eb02706dfb0'
40
+ album['url'].should == 'http://www.last.fm/music/Cher/Believe'
41
+ album['image'].size.should == 5
42
+ album['releasedate'].should == '6 Apr 1999, 00:00'
43
+ album['tracks']['track'].size.should == 10
44
+ album['tracks']['track'][0]['name'].should == 'Believe'
45
+ album['tracks']['track'][0]['duration'].should == '239'
46
+ album['tracks']['track'][0]['url'].should == 'http://www.last.fm/music/Cher/_/Believe'
47
+ end
29
48
  end
30
49
  end
@@ -35,7 +35,7 @@ describe '#track' do
35
35
  end
36
36
 
37
37
  describe '#get_info' do
38
- it 'should get info' do
38
+ it 'should get info by track and artist' do
39
39
  @lastfm.should_receive(:request).with('track.getInfo', {
40
40
  :artist => 'Cher',
41
41
  :track => 'Believe',
@@ -54,6 +54,24 @@ describe '#track' do
54
54
  track['toptags']['tag'].first['name'].should == 'pop'
55
55
  end
56
56
 
57
+ it 'should get info by mbid' do
58
+ @lastfm.should_receive(:request).with('track.getInfo', {
59
+ :mbid => 'xxx',
60
+ :username => nil
61
+ }
62
+ ).and_return(make_response('track_get_info'))
63
+
64
+ track = @lastfm.track.get_info(
65
+ :mbid => 'xxx'
66
+ )
67
+ track['name'].should == 'Believe'
68
+ track['album']['image'].size.should == 4
69
+ track['album']['image'].first['size'].should == 'small'
70
+ track['album']['image'].first['content'].should == 'http://userserve-ak.last.fm/serve/64s/8674593.jpg'
71
+ track['toptags']['tag'].size.should == 5
72
+ track['toptags']['tag'].first['name'].should == 'pop'
73
+ end
74
+
57
75
  it 'should get xml with force array option' do
58
76
  @lastfm.should_receive(:request).with('track.getInfo', {
59
77
  :artist => 'Cher',
@@ -8,10 +8,20 @@ describe '#user' do
8
8
  end
9
9
 
10
10
  describe '#get_info' do
11
- it 'should get user info' do
12
- @lastfm.should_receive(:request).with('user.getInfo', {:user => 'test'}).and_return(make_response('user_get_info'))
13
- info = @lastfm.user.get_info(:user => 'test')
14
- info['id'].should == '1000002'
11
+ context 'with params' do
12
+ it 'should get user info' do
13
+ @lastfm.should_receive(:request).with('user.getInfo', {:user => 'test'}).and_return(make_response('user_get_info'))
14
+ info = @lastfm.user.get_info(:user => 'test')
15
+ info['id'].should == '1000002'
16
+ end
17
+ end
18
+
19
+ context 'without params' do
20
+ it 'should get current user info' do
21
+ @lastfm.should_receive(:request).with('user.getInfo', {}, :get, true, true).and_return(make_response('user_get_info'))
22
+ info = @lastfm.user.get_info
23
+ info['id'].should == '1000002'
24
+ end
15
25
  end
16
26
  end
17
27
 
@@ -210,7 +220,7 @@ describe '#user' do
210
220
  tracks[1]['artist']['content'].should == 'Kylie Minogue'
211
221
  tracks.size.should == 2
212
222
  end
213
-
223
+
214
224
  it 'should not error when a user\'s recent tracks includes malformed data' do
215
225
  @lastfm.should_receive(:request).with('user.getRecentTracks', {
216
226
  :user => 'test',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lastfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.18.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-26 00:00:00.000000000 Z
12
+ date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml-simple
@@ -209,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  version: '0'
210
210
  segments:
211
211
  - 0
212
- hash: 3208565068622947004
212
+ hash: 1101754709663584216
213
213
  required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  none: false
215
215
  requirements:
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  version: '0'
219
219
  segments:
220
220
  - 0
221
- hash: 3208565068622947004
221
+ hash: 1101754709663584216
222
222
  requirements: []
223
223
  rubyforge_project:
224
224
  rubygems_version: 1.8.24