omniauth-lastfm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Lastfm
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,70 @@
1
+ require "multi_json"
2
+ require "oauth"
3
+ require "omniauth"
4
+ require "rest-client"
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Lastfm
9
+ include OmniAuth::Strategy
10
+
11
+ args [:api_key, :secret_key]
12
+ option :api_key, nil
13
+ option :secret_key, nil
14
+ option :name, "lastfm"
15
+ option :client_options, {
16
+ :authorize_path => "/api/auth",
17
+ :site => "http://www.last.fm"
18
+ }
19
+
20
+ attr_reader :json
21
+
22
+ def request_phase
23
+ params = {
24
+ :api_key => options.api_key,
25
+ :cb => options.client_options["callback"]
26
+ }
27
+ query_string = params.map{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join("&")
28
+ redirect "#{options.client_options.site}#{options.client_options.authorize_path}/?#{query_string}"
29
+ end
30
+
31
+ def callback_phase
32
+ token = request.params["token"]
33
+ params = { :api_key => options.api_key }
34
+ params[:token] = token
35
+ params[:api_sig] = signature(token)
36
+ params[:method] = "auth.getSession"
37
+ params[:format] = "json"
38
+ response = RestClient.get("http://ws.audioscrobbler.com/2.0/", { :params => params })
39
+ @json = MultiJson.decode(response.to_s)
40
+ super
41
+ end
42
+
43
+ uid { raw_info["name"] }
44
+
45
+ info do
46
+ { :name => raw_info["name"] }
47
+ end
48
+
49
+ extra do
50
+ { :raw_info => raw_info }
51
+ end
52
+
53
+ credentials do
54
+ { :token => raw_info["key"] }
55
+ end
56
+
57
+ def raw_info
58
+ @raw_info ||= @json["session"]
59
+ rescue ::RestClient::Exception
60
+ raise ::Timeout::Error
61
+ end
62
+
63
+ protected
64
+ def signature(token)
65
+ sign = "api_key#{options.api_key}methodauth.getSessiontoken#{token}#{options.secret_key}"
66
+ Digest::MD5.hexdigest(sign)
67
+ end
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-lastfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70341976300860 !ruby/object:Gem::Requirement
16
+ requirement: &70181137236140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.7'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70341976300860
24
+ version_requirements: *70181137236140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &70341976300340 !ruby/object:Gem::Requirement
27
+ requirement: &70181137235280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70341976300340
35
+ version_requirements: *70181137235280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: simplecov
38
- requirement: &70341976158800 !ruby/object:Gem::Requirement
38
+ requirement: &70181137234260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70341976158800
46
+ version_requirements: *70181137234260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &70341976158200 !ruby/object:Gem::Requirement
49
+ requirement: &70181137233520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70341976158200
57
+ version_requirements: *70181137233520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: omniauth-oauth
60
- requirement: &70341976157000 !ruby/object:Gem::Requirement
60
+ requirement: &70181137232920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70341976157000
68
+ version_requirements: *70181137232920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
- requirement: &70341976155320 !ruby/object:Gem::Requirement
71
+ requirement: &70181137232220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 1.6.6
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70341976155320
79
+ version_requirements: *70181137232220
80
80
  description: OmniAuth strategy for Last.fm
81
81
  email:
82
82
  - claudio@audiobox.fm
@@ -89,6 +89,7 @@ files:
89
89
  - Rakefile
90
90
  - lib/omniauth-lastfm.rb
91
91
  - lib/omniauth-lastfm/version.rb
92
+ - lib/omniauth/strategies/lastfm.rb
92
93
  - omniauth-lastfm.gemspec
93
94
  homepage: http://github.com/masterkain/omniauth-lastfm
94
95
  licenses: []