Class: Lockitron::Auth
- Inherits:
-
Object
- Object
- Lockitron::Auth
- Defined in:
- lib/lockitron/auth.rb
Instance Method Summary collapse
- #authorization_url ⇒ Object
-
#initialize(params = {}) ⇒ Auth
constructor
A new instance of Auth.
- #token ⇒ Object
- #token_from_code(auth_code) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Auth
Returns a new instance of Auth.
4 5 6 7 8 9 10 |
# File 'lib/lockitron/auth.rb', line 4 def initialize(params = {}) @client_id = params[:client_id] @client_secret = params[:client_secret] @redirect_uri = params[:redirect_uri] @oauth_client = OAuth2::Client.new(@client_id, @client_secret, site: API_ENDPOINT) @oauth_client.[:token_url] = "/v2/oauth/token" end |
Instance Method Details
#authorization_url ⇒ Object
20 21 22 |
# File 'lib/lockitron/auth.rb', line 20 def "#{Lockitron::API_ENDPOINT}/oauth/authorize?client_id=#{@client_id}&response_type=code&redirect_uri=#{@redirect_uri}" end |
#token ⇒ Object
16 17 18 |
# File 'lib/lockitron/auth.rb', line 16 def token @token.token end |
#token_from_code(auth_code) ⇒ Object
12 13 14 |
# File 'lib/lockitron/auth.rb', line 12 def token_from_code auth_code @token = @oauth_client.auth_code.get_token(auth_code, redirect_uri: @redirect_uri) end |