Module: Discogs::Authentication
- Included in:
- Wrapper
- Defined in:
- lib/discogs/authentication.rb
Instance Method Summary collapse
- #any_authentication? ⇒ Boolean
- #auth_params ⇒ Object
-
#authenticate(request_token, verifier) ⇒ OAuth::AccessToken
Retrieves an OAuth access token from the Discogs server.
-
#authenticated?(username = nil, &block) ⇒ Boolean
Returns true if an OAuth access_token is present.
-
#get_request_token(app_key, app_secret, callback) ⇒ Hash
Retrieves an OAuth request token from the Discogs server.
-
#self_authenticating? ⇒ Boolean
Indicates whether this instance is self-authenticated.
-
#user_facing? ⇒ Boolean
Indicates whether this instance is authenticated as a user-facing app.
Instance Method Details
#any_authentication? ⇒ Boolean
26 27 28 |
# File 'lib/discogs/authentication.rb', line 26 def any_authentication? user_facing? or self_authenticating? end |
#auth_params ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/discogs/authentication.rb', line 5 def auth_params if self_authenticating? {:token => @user_token} else {} end end |
#authenticate(request_token, verifier) ⇒ OAuth::AccessToken
Retrieves an OAuth access token from the Discogs server.
52 53 54 55 56 57 58 |
# File 'lib/discogs/authentication.rb', line 52 def authenticate(request_token, verifier) if request_token.is_a?(OAuth::RequestToken) @access_token = request_token.get_access_token(:oauth_verifier => verifier) else raise OAuth::Error, "Invalid Request Token" end end |
#authenticated?(username = nil, &block) ⇒ Boolean
Returns true if an OAuth access_token is present. If a username is given, the authenticated username must match it.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/discogs/authentication.rb', line 64 def authenticated?(username=nil, &block) auth = if username any_authentication? and authenticated_username == username else any_authentication? end if block_given? auth ? yield : raise_authentication_error else auth end end |
#get_request_token(app_key, app_secret, callback) ⇒ Hash
Retrieves an OAuth request token from the Discogs server.
36 37 38 39 40 41 42 43 44 |
# File 'lib/discogs/authentication.rb', line 36 def get_request_token(app_key, app_secret, callback) consumer = OAuth::Consumer.new(app_key, app_secret, :authorize_url => "https://www.discogs.com/oauth/authorize", :site => "https://api.discogs.com") request_token = consumer.get_request_token(:oauth_callback => callback) {:request_token => request_token, :authorize_url => request_token.(:oauth_callback => callback)} end |
#self_authenticating? ⇒ Boolean
Indicates whether this instance is self-authenticated.
21 22 23 |
# File 'lib/discogs/authentication.rb', line 21 def self_authenticating? !!@user_token end |
#user_facing? ⇒ Boolean
Indicates whether this instance is authenticated as a user-facing app.
15 16 17 |
# File 'lib/discogs/authentication.rb', line 15 def user_facing? !!@access_token end |