rscrobbler 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rscrobbler.rb +13 -13
  2. metadata +5 -4
data/lib/rscrobbler.rb CHANGED
@@ -22,18 +22,16 @@ require 'lastfm/user'
22
22
  require 'lastfm/venue'
23
23
 
24
24
  module LastFM
25
- VERSION = '0.0.4'
25
+ VERSION = '0.0.5'
26
26
 
27
27
  HOST = 'ws.audioscrobbler.com'
28
- POST_URI = URI.parse("http://#{HOST}/2.0/")
28
+ API_VERSION = '2.0'
29
29
 
30
- class RequestError < StandardError; end
30
+ class LastFMError < StandardError; end
31
31
  class AuthenticationError < StandardError; end
32
32
 
33
33
  class << self
34
-
35
- attr_accessor :api_key, :api_secret, :username, :auth_token
36
- attr_reader :session_key, :logger
34
+ attr_accessor :api_key, :api_secret, :username, :auth_token, :session_key, :logger
37
35
 
38
36
  # Authenticate the service with provided login credentials. Use mobile
39
37
  # authentication to avoid redirecting to the website to log in.
@@ -44,7 +42,7 @@ module LastFM
44
42
  [:api_key, :api_secret, :username, :auth_token].each do |cred|
45
43
  raise AuthenticationError, "Missing credential: #{cred}" unless LastFM.send(cred)
46
44
  end
47
- @session_key = Auth.get_mobile_session( username, auth_token ).find_first('session/key').content
45
+ session_key = Auth.get_mobile_session( username, auth_token ).find_first('session/key').content
48
46
  end
49
47
 
50
48
  # Has the service been authenticated?
@@ -81,7 +79,7 @@ module LastFM
81
79
  path = generate_path(method, secure, params)
82
80
  logger.debug( "Last.fm HTTP GET: #{HOST+path}" ) if logger
83
81
  response = Net::HTTP.get_response( HOST, path )
84
- check_status( LibXML::XML::Parser.string( response.body ).parse )
82
+ validate( LibXML::XML::Parser.string( response.body ).parse )
85
83
  end
86
84
 
87
85
  # Construct an HTTP POST call from params, and check the response status.
@@ -91,10 +89,11 @@ module LastFM
91
89
  # @return [LibXML::XML::Document] xml document of the data contained in the response
92
90
  # @raise [LastFMError] if the request fails
93
91
  def post( method, params )
92
+ post_uri = URI.parse("http://#{HOST}/#{API_VERSION}/")
94
93
  params = construct_params( method, :secure, params )
95
- logger.debug( "Last.fm HTTP POST: #{POST_URI}, #{params.to_s}" ) if logger
96
- response = Net::HTTP.post_form( POST_URI, params )
97
- check_status( LibXML::XML::Parser.string( response.body ).parse )
94
+ logger.debug( "Last.fm HTTP POST: #{post_uri}, #{params.to_s}" ) if logger
95
+ response = Net::HTTP.post_form( post_uri, params )
96
+ validate( LibXML::XML::Parser.string( response.body ).parse )
98
97
  end
99
98
 
100
99
  private
@@ -105,8 +104,8 @@ module LastFM
105
104
  # @return [LibXML::XML::Document] the xml document if no errors were found
106
105
  # @raise [LastFMError] if an error is found
107
106
  # @private
108
- def check_status( xml )
109
- raise RequestError, xml.find_first('error').content if xml.root.attributes['status'] == 'failed'
107
+ def validate( xml )
108
+ raise LastFMError, xml.find_first('error').content if xml.root.attributes['status'] == 'failed'
110
109
  xml
111
110
  end
112
111
 
@@ -117,6 +116,7 @@ module LastFM
117
116
  # @param [Boolean] secure whether to include session key and api signature in the parameters
118
117
  # @param [Hash] params parameters to normalize and add to
119
118
  # @return [Hash] complete, normalized parameters
119
+ # @private
120
120
  def construct_params( method, secure, params )
121
121
  params.delete_if{|k,v| v.nil? }
122
122
  params.each{|k,v| params[k] = params[k].to_s }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscrobbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000Z
12
+ date: 2011-12-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libxml-ruby
16
- requirement: &2161496200 !ruby/object:Gem::Requirement
16
+ requirement: &2154789180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2161496200
24
+ version_requirements: *2154789180
25
25
  description: rscrobbler is a Ruby gem for accessing Last.fm's API (http://www.last.fm/api).
26
26
  email:
27
27
  - sgt.floydpepper@gmail.com
@@ -72,3 +72,4 @@ signing_key:
72
72
  specification_version: 3
73
73
  summary: Last.fm API wrapper
74
74
  test_files: []
75
+ has_rdoc: