rscrobbler 0.0.5 → 0.0.6

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 +23 -3
  2. metadata +3 -3
data/lib/rscrobbler.rb CHANGED
@@ -22,7 +22,7 @@ require 'lastfm/user'
22
22
  require 'lastfm/venue'
23
23
 
24
24
  module LastFM
25
- VERSION = '0.0.5'
25
+ VERSION = '0.0.6'
26
26
 
27
27
  HOST = 'ws.audioscrobbler.com'
28
28
  API_VERSION = '2.0'
@@ -33,6 +33,26 @@ module LastFM
33
33
  class << self
34
34
  attr_accessor :api_key, :api_secret, :username, :auth_token, :session_key, :logger
35
35
 
36
+ # Configure the module and begin a session. Once established (and successfully
37
+ # executed), the module is ready to send api calls to Last.fm.
38
+ #
39
+ # Expected usage:
40
+ # LastFM.establish_session do |session|
41
+ # session.username = ...
42
+ # session.auth_token = ...
43
+ # session.api_key = ...
44
+ # session.api_secret = ...
45
+ # end
46
+ #
47
+ # @param [Block] &block block used to configure the module's attributes
48
+ # @return [String] session key if successfully connected
49
+ # @raise [AuthenticationError] if any authentication attributes are missing
50
+ # @raise [LastFMError] if the HTTP request to Last.fm returns an error
51
+ def establish_session(&block)
52
+ yield self
53
+ self.authenticate!
54
+ end
55
+
36
56
  # Authenticate the service with provided login credentials. Use mobile
37
57
  # authentication to avoid redirecting to the website to log in.
38
58
  #
@@ -42,7 +62,7 @@ module LastFM
42
62
  [:api_key, :api_secret, :username, :auth_token].each do |cred|
43
63
  raise AuthenticationError, "Missing credential: #{cred}" unless LastFM.send(cred)
44
64
  end
45
- session_key = Auth.get_mobile_session( username, auth_token ).find_first('session/key').content
65
+ self.session_key = Auth.get_mobile_session( username, auth_token ).find_first('session/key').content
46
66
  end
47
67
 
48
68
  # Has the service been authenticated?
@@ -136,7 +156,7 @@ module LastFM
136
156
  # @private
137
157
  def generate_path( method, secure, params={} )
138
158
  params = construct_params( method, secure, params )
139
- url = "/2.0/?method=#{params.delete('method')}"
159
+ url = "/#{API_VERSION}/?method=#{params.delete('method')}"
140
160
  params.keys.each do |key|
141
161
  url << "&#{key}=#{params[key]}"
142
162
  end
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libxml-ruby
16
- requirement: &2154789180 !ruby/object:Gem::Requirement
16
+ requirement: &2168494000 !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: *2154789180
24
+ version_requirements: *2168494000
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