scrobbler-ng 2.0.10 → 2.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,9 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'rake'
5
5
  require 'rake/testtask'
6
- require 'rake/rdoctask'
7
- require 'spec/rake/spectask'
8
-
6
+
9
7
  Dir['tasks/**/*.rake'].each { |rake| load rake }
10
8
 
11
9
  task :default => 'test:unit'
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 2
3
3
  :minor: 0
4
- :patch: 10
4
+ :patch: 11
5
5
  :build:
@@ -59,7 +59,7 @@ module Scrobbler
59
59
  @listeners = childL2.content.to_i if childL2.name == 'listeners'
60
60
  @playcount = childL2.content.to_i if childL2.name == 'playcount'
61
61
  @playcount = childL2.content.to_i if childL2.name == 'plays'
62
- end
62
+ end if not child.children.nil?
63
63
  when 'similar'
64
64
  # Ignore them for the moment, they are not stored.
65
65
  when 'bio'
@@ -141,11 +141,16 @@ module Scrobbler
141
141
  #
142
142
  # @return [nil]
143
143
  def load_info
144
- doc = request('artist.getinfo', {:artist => @name})
144
+ if @mbid.nil?
145
+ req_args = {:artist => @name}
146
+ else
147
+ req_args = {:mbid => @mbid}
148
+ end
149
+ doc = request('artist.getinfo', req_args)
145
150
  doc.root.children.each do |childL1|
146
151
  next unless childL1.name == 'artist'
147
152
  load_from_xml(childL1)
148
- end
153
+ end if (not doc.root.nil?) && (not doc.root.children.nil?)
149
154
  @info_loaded = true
150
155
  end # load_info
151
156
 
@@ -13,6 +13,8 @@ end
13
13
  module Scrobbler
14
14
 
15
15
  API_URL = 'http://ws.audioscrobbler.com/' unless defined? API_URL
16
+
17
+ class ApiError < StandardError; end
16
18
 
17
19
  class Base
18
20
 
@@ -185,12 +187,25 @@ module Scrobbler
185
187
  xml = fetch_http(request_method, paramlist) if xml.nil?
186
188
  # Process it
187
189
  doc = Nokogiri::XML(xml) { |config| config.noent.noblanks.nonet }
190
+ # Validate it
191
+ validate_response_document doc
188
192
  # Write to cache
189
193
  save_to_cache(xml, parameters) if check_cache
190
194
 
191
195
  # Return the parsed result
192
196
  doc
193
197
  end
198
+
199
+ # Check response status, raise ApiError if request failed.
200
+ #
201
+ # @param [Nokogiri::XML::Document] document Response XML document.
202
+ # @return [void]
203
+ def Base.validate_response_document(document)
204
+ unless document.root and document.root['status'] == 'ok'
205
+ error_message = (document.content if document.root.child.name == 'error') rescue nil
206
+ raise ApiError, error_message
207
+ end
208
+ end
194
209
 
195
210
  # Load information into instance variables.
196
211
  #
@@ -228,7 +243,7 @@ module Scrobbler
228
243
  doc.root.children.each do |child|
229
244
  next unless child.name == parent.to_s
230
245
  root = child
231
- end
246
+ end unless doc.nil? || doc.root.nil?
232
247
  if root.nil? then
233
248
  # Sometimes Last.fm returns an empty file if we query for sth not known
234
249
  return []
@@ -66,7 +66,7 @@ module Scrobbler
66
66
  raise ArgumentError unless ['small', 'medium', 'large', 'extralarge',
67
67
  'mega'].include?(which)
68
68
  img_url = instance_variable_get("@image_#{which}")
69
- if img_url.nil? && responds_to?(:load_info)
69
+ if img_url.nil? && respond_to?(:load_info)
70
70
  load_info
71
71
  img_url = instance_variable_get("@image_#{which}")
72
72
  end
@@ -8,6 +8,7 @@ module Scrobbler
8
8
  include ImageObjectFuncs
9
9
 
10
10
  attr_reader :url, :weight, :match, :realname, :name
11
+ attr_reader :id, :country, :age, :gender, :subscriber, :playcount, :playlistcount, :registered
11
12
 
12
13
  # Alias for User.new(:xml => xml)
13
14
  #
@@ -43,6 +44,28 @@ module Scrobbler
43
44
  @realname = child.content
44
45
  when 'image'
45
46
  check_image_node(child)
47
+ when 'id'
48
+ @id = child.content.to_i
49
+ when 'country'
50
+ @country = child.content
51
+ when 'age'
52
+ @age = child.content.to_i
53
+ when 'gender'
54
+ @gender = child.content
55
+ when 'subscriber'
56
+ @subscriber = child.content == '1'
57
+ when 'playcount'
58
+ @playcount = child.content.to_i
59
+ when 'playlists'
60
+ @playlistcount = child.content.to_i
61
+ when 'registered'
62
+ @registered = Time.parse child.content
63
+ when 'id'
64
+ @id = child.content.to_i
65
+ when 'type'
66
+ @type = child.content.to_i
67
+ when 'bootstrap'
68
+ # TODO Guess meaning of 'bootstrap' field
46
69
  when 'text'
47
70
  # ignore, these are only blanks
48
71
  when '#text'
@@ -78,10 +101,18 @@ module Scrobbler
78
101
  call_pageable('user.getfriends', :friends, User, {:user => @name}.merge(opts))
79
102
  end
80
103
 
104
+ # Indicates if the info was already loaded
105
+ @info_loaded = false
106
+
81
107
  # Get information about a user profile.
82
108
  def load_info
83
- # This function requires authentication, but SimpleAuth is not yet 2.0
84
- raise NotImplementedError
109
+ unless @info_loaded
110
+ xml = Base.request 'user.getinfo', :user => @name
111
+ if xml.root['status'] == 'ok' and xml.root.children.first.name == 'user'
112
+ load_from_xml xml.root.children.first
113
+ @info_loaded = true
114
+ end
115
+ end
85
116
  end
86
117
 
87
118
  # Get the last 50 tracks loved by a user.
@@ -1,91 +1,63 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{scrobbler-ng}
8
- s.version = "2.0.10"
7
+ s.name = "scrobbler-ng"
8
+ s.version = "2.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker", "Jonathan Rudenberg", "Uwe L. Korn"]
12
- s.date = %q{2010-09-25}
13
- s.description = %q{A ruby library for accessing the Last.fm 2.0 API. It is higly optimized so that it uses less memory and parses XML (through Nokogiri) than other implementations.}
14
- s.email = %q{uwelk@xhochy.org}
12
+ s.date = "2012-01-11"
13
+ s.description = "A ruby library for accessing the Last.fm 2.0 API. It is higly optimized so that it uses less memory and parses XML (through Nokogiri) than other implementations."
14
+ s.email = "uwelk@xhochy.org"
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
19
  "MIT-LICENSE",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION.yml",
23
- "examples/album.rb",
24
- "examples/artist.rb",
25
- "examples/scrobble.rb",
26
- "examples/tag.rb",
27
- "examples/track.rb",
28
- "examples/user.rb",
29
- "lib/scrobbler.rb",
30
- "lib/scrobbler/album.rb",
31
- "lib/scrobbler/artist.rb",
32
- "lib/scrobbler/authentication.rb",
33
- "lib/scrobbler/base.rb",
34
- "lib/scrobbler/basexml.rb",
35
- "lib/scrobbler/basexmlinfo.rb",
36
- "lib/scrobbler/event.rb",
37
- "lib/scrobbler/geo.rb",
38
- "lib/scrobbler/helper/image.rb",
39
- "lib/scrobbler/helper/streamable.rb",
40
- "lib/scrobbler/library.rb",
41
- "lib/scrobbler/playlist.rb",
42
- "lib/scrobbler/radio.rb",
43
- "lib/scrobbler/session.rb",
44
- "lib/scrobbler/shout.rb",
45
- "lib/scrobbler/tag.rb",
46
- "lib/scrobbler/track.rb",
47
- "lib/scrobbler/user.rb",
48
- "lib/scrobbler/venue.rb",
49
- "scrobbler-ng.gemspec",
50
- "tasks/jeweler.rake",
51
- "tasks/rdoc.rake",
52
- "tasks/tests.rake",
53
- "tasks/yardoc.rake"
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION.yml",
23
+ "examples/album.rb",
24
+ "examples/artist.rb",
25
+ "examples/scrobble.rb",
26
+ "examples/tag.rb",
27
+ "examples/track.rb",
28
+ "examples/user.rb",
29
+ "lib/scrobbler.rb",
30
+ "lib/scrobbler/album.rb",
31
+ "lib/scrobbler/artist.rb",
32
+ "lib/scrobbler/authentication.rb",
33
+ "lib/scrobbler/base.rb",
34
+ "lib/scrobbler/basexml.rb",
35
+ "lib/scrobbler/basexmlinfo.rb",
36
+ "lib/scrobbler/event.rb",
37
+ "lib/scrobbler/geo.rb",
38
+ "lib/scrobbler/helper/image.rb",
39
+ "lib/scrobbler/helper/streamable.rb",
40
+ "lib/scrobbler/library.rb",
41
+ "lib/scrobbler/playlist.rb",
42
+ "lib/scrobbler/radio.rb",
43
+ "lib/scrobbler/session.rb",
44
+ "lib/scrobbler/shout.rb",
45
+ "lib/scrobbler/tag.rb",
46
+ "lib/scrobbler/track.rb",
47
+ "lib/scrobbler/user.rb",
48
+ "lib/scrobbler/venue.rb",
49
+ "scrobbler-ng.gemspec",
50
+ "tasks/jeweler.rake",
51
+ "tasks/rdoc.rake",
52
+ "tasks/tests.rake",
53
+ "tasks/yardoc.rake"
54
54
  ]
55
- s.homepage = %q{http://github.com/xhochy/scrobbler}
56
- s.rdoc_options = ["--charset=UTF-8"]
55
+ s.homepage = "http://github.com/xhochy/scrobbler"
57
56
  s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.7}
59
- s.summary = %q{A ruby library for accessing the last.fm v2 webservices}
60
- s.test_files = [
61
- "test/unit/tag_spec.rb",
62
- "test/unit/playlist_spec.rb",
63
- "test/unit/album_spec.rb",
64
- "test/unit/radio_spec.rb",
65
- "test/unit/event_spec.rb",
66
- "test/unit/venue_spec.rb",
67
- "test/unit/user_spec.rb",
68
- "test/unit/artist_spec.rb",
69
- "test/unit/playing_test.rb",
70
- "test/unit/simpleauth_test.rb",
71
- "test/unit/geo_spec.rb",
72
- "test/unit/library_spec.rb",
73
- "test/unit/track_spec.rb",
74
- "test/unit/authentication_spec.rb",
75
- "test/spec_helper.rb",
76
- "test/test_helper.rb",
77
- "test/mocks/library.rb",
78
- "test/mocks/rest.rb",
79
- "examples/tag.rb",
80
- "examples/track.rb",
81
- "examples/user.rb",
82
- "examples/artist.rb",
83
- "examples/scrobble.rb",
84
- "examples/album.rb"
85
- ]
57
+ s.rubygems_version = "1.8.13"
58
+ s.summary = "A ruby library for accessing the last.fm v2 webservices"
86
59
 
87
60
  if s.respond_to? :specification_version then
88
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
89
61
  s.specification_version = 3
90
62
 
91
63
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -1,4 +1,5 @@
1
- Rake::RDocTask.new do |rdoc|
1
+ require 'rdoc/task'
2
+ RDoc::Task.new do |rdoc|
2
3
  rdoc.rdoc_dir = 'rdoc'
3
4
  rdoc.title = 'scrobbler-ng'
4
5
  rdoc.options << '--line-numbers' << '--inline-source'
@@ -1,23 +1,5 @@
1
- desc "Run all tests"
2
- Spec::Rake::SpecTask.new('test:unit') do |t|
3
- t.rcov = false
4
- t.spec_opts << '--format' << 'html:spec.html'
5
- t.spec_opts << '--format' << 'progress'
6
- t.spec_opts << '-b'
7
- t.spec_files = FileList['test/unit/*_spec.rb']
8
- end
1
+ require 'rspec/core/rake_task'
9
2
 
10
- Spec::Rake::SpecTask.new('test:rcov') do |t|
11
- begin
12
- require 'rcov'
13
- t.rcov = true
14
- t.rcov_opts = ['--exclude', '/var/lib/gems']
15
- rescue LoadError
16
- t.rcov = false
17
- end
18
- t.spec_opts << '--format' << 'html:spec.html'
19
- t.spec_opts << '--format' << 'progress'
20
- t.spec_opts << '-b'
21
- t.spec_files = FileList['test/unit/*_spec.rb']
3
+ RSpec::Core::RakeTask.new(:spec) do |t|
4
+ t.pattern = 'test/unit/*_spec.rb'
22
5
  end
23
-
metadata CHANGED
@@ -1,94 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: scrobbler-ng
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 2
8
- - 0
9
- - 10
10
- version: 2.0.10
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.11
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - John Nunemaker
14
9
  - Jonathan Rudenberg
15
10
  - Uwe L. Korn
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2010-09-25 00:00:00 +02:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
14
+ date: 2012-01-11 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
24
17
  name: rspec
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &10958280 !ruby/object:Gem::Requirement
27
19
  none: false
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- hash: 13
32
- segments:
33
- - 1
34
- - 2
35
- - 9
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
36
23
  version: 1.2.9
37
24
  type: :development
38
- version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
40
- name: yard
41
25
  prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *10958280
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: &11344040 !ruby/object:Gem::Requirement
43
30
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- hash: 3
48
- segments:
49
- - 0
50
- version: "0"
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
51
35
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: fakeweb
55
36
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *11344040
38
+ - !ruby/object:Gem::Dependency
39
+ name: fakeweb
40
+ requirement: &11342900 !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
65
46
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: nokogiri
69
47
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
48
+ version_requirements: *11342900
49
+ - !ruby/object:Gem::Dependency
50
+ name: nokogiri
51
+ requirement: &11341500 !ruby/object:Gem::Requirement
71
52
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 1
78
- - 4
79
- - 2
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
80
56
  version: 1.4.2
81
57
  type: :runtime
82
- version_requirements: *id004
83
- description: A ruby library for accessing the Last.fm 2.0 API. It is higly optimized so that it uses less memory and parses XML (through Nokogiri) than other implementations.
58
+ prerelease: false
59
+ version_requirements: *11341500
60
+ description: A ruby library for accessing the Last.fm 2.0 API. It is higly optimized
61
+ so that it uses less memory and parses XML (through Nokogiri) than other implementations.
84
62
  email: uwelk@xhochy.org
85
63
  executables: []
86
-
87
64
  extensions: []
88
-
89
- extra_rdoc_files:
65
+ extra_rdoc_files:
90
66
  - README.rdoc
91
- files:
67
+ files:
92
68
  - MIT-LICENSE
93
69
  - README.rdoc
94
70
  - Rakefile
@@ -124,80 +100,28 @@ files:
124
100
  - tasks/rdoc.rake
125
101
  - tasks/tests.rake
126
102
  - tasks/yardoc.rake
127
- - test/unit/tag_spec.rb
128
- - test/unit/playlist_spec.rb
129
- - test/unit/album_spec.rb
130
- - test/unit/radio_spec.rb
131
- - test/unit/event_spec.rb
132
- - test/unit/venue_spec.rb
133
- - test/unit/user_spec.rb
134
- - test/unit/artist_spec.rb
135
- - test/unit/playing_test.rb
136
- - test/unit/simpleauth_test.rb
137
- - test/unit/geo_spec.rb
138
- - test/unit/library_spec.rb
139
- - test/unit/track_spec.rb
140
- - test/unit/authentication_spec.rb
141
- - test/spec_helper.rb
142
- - test/test_helper.rb
143
- - test/mocks/library.rb
144
- - test/mocks/rest.rb
145
- has_rdoc: true
146
103
  homepage: http://github.com/xhochy/scrobbler
147
104
  licenses: []
148
-
149
105
  post_install_message:
150
- rdoc_options:
151
- - --charset=UTF-8
152
- require_paths:
106
+ rdoc_options: []
107
+ require_paths:
153
108
  - lib
154
- required_ruby_version: !ruby/object:Gem::Requirement
109
+ required_ruby_version: !ruby/object:Gem::Requirement
155
110
  none: false
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- hash: 3
160
- segments:
161
- - 0
162
- version: "0"
163
- required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
116
  none: false
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- hash: 3
169
- segments:
170
- - 0
171
- version: "0"
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
172
121
  requirements: []
173
-
174
122
  rubyforge_project:
175
- rubygems_version: 1.3.7
123
+ rubygems_version: 1.8.13
176
124
  signing_key:
177
125
  specification_version: 3
178
126
  summary: A ruby library for accessing the last.fm v2 webservices
179
- test_files:
180
- - test/unit/tag_spec.rb
181
- - test/unit/playlist_spec.rb
182
- - test/unit/album_spec.rb
183
- - test/unit/radio_spec.rb
184
- - test/unit/event_spec.rb
185
- - test/unit/venue_spec.rb
186
- - test/unit/user_spec.rb
187
- - test/unit/artist_spec.rb
188
- - test/unit/playing_test.rb
189
- - test/unit/simpleauth_test.rb
190
- - test/unit/geo_spec.rb
191
- - test/unit/library_spec.rb
192
- - test/unit/track_spec.rb
193
- - test/unit/authentication_spec.rb
194
- - test/spec_helper.rb
195
- - test/test_helper.rb
196
- - test/mocks/library.rb
197
- - test/mocks/rest.rb
198
- - examples/tag.rb
199
- - examples/track.rb
200
- - examples/user.rb
201
- - examples/artist.rb
202
- - examples/scrobble.rb
203
- - examples/album.rb
127
+ test_files: []