34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/songbirdsh/scrobbler.rb', line 34
def setup
puts <<-EOF
Because of the way lastfm authentication works, setting up lastfm involves two steps:
Firstly, you need to register that you are developing an application. This will give you an api key and an associated 'secret'
Secondly, you need to gives your application access your lastfm account. This will give a authenticated session.
Step 1. Logging in to your lastfm account and register an application
This will launch a browser. You need to log in and fill out the API registration form
EOF
answer = ask 'Are you ready ? '
return unless answer.downcase.start_with? 'y'
"http://www.last.fm/api/account".to_launcher
preferences = {}
preferences['api_key'] = ask 'What is your API key ? '
preferences['secret'] = ask 'What is your secret ? '
puts <<-EOF
Now you've got you application details, you need to create an authentication session between your application and your lastfm account
Step 2. Authorising your application to access your lastfm account
This will launch another browser. You just need to give your application permission to access your account
EOF
preferences['user'] = ask 'What is your lastfm user name ? '
@scrobbler = SimpleScrobbler.new preferences['api_key'], preferences['secret'], preferences['user']
preferences['session_key'] = @scrobbler.fetch_session_key do |url|
url.to_launcher
ask 'Hit enter when you\'ve allowed your application access to your account'
end
@preferences['lastfm'] = preferences
end
|