Class: Dronetrack::OAuthHelper
- Inherits:
-
Object
- Object
- Dronetrack::OAuthHelper
- Defined in:
- lib/dronetrack/oauthhelper.rb
Instance Method Summary collapse
- #getAccessToken(getCode, &block) ⇒ Object
-
#initialize(baseUrl, clientId, clientSecret, redirectUrl) ⇒ OAuthHelper
constructor
A new instance of OAuthHelper.
Constructor Details
#initialize(baseUrl, clientId, clientSecret, redirectUrl) ⇒ OAuthHelper
Returns a new instance of OAuthHelper.
3 4 5 6 |
# File 'lib/dronetrack/oauthhelper.rb', line 3 def initialize (baseUrl, clientId, clientSecret, redirectUrl) @client = OAuth2::Client.new(clientId, clientSecret, {:site => baseUrl, :authorize_url => "#{@baseUrl}/auth/dialog", :token_url => "#{@baseUrl}/auth/token"}) @redirectUrl = redirectUrl end |
Instance Method Details
#getAccessToken(getCode, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dronetrack/oauthhelper.rb', line 8 def getAccessToken (getCode, &block) url = @client.auth_code.(:redirect_uri => @redirectUrl) b = if block_given? then block else Proc.new() end complete = Proc.new do |code| token = @client.auth_code.get_token(code, :redirect_uri => @redirectUrl) b.call token.token end getCode.call url, complete end |