Class: CodePicnic::Token
- Inherits:
-
Object
- Object
- CodePicnic::Token
- Defined in:
- lib/codepicnic/token.rb
Class Attribute Summary collapse
-
.api_url ⇒ Object
Returns the value of attribute api_url.
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(client_id, client_secret) ⇒ Token
constructor
A new instance of Token.
Constructor Details
#initialize(client_id, client_secret) ⇒ Token
Returns a new instance of Token.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/codepicnic/token.rb', line 12 def initialize(client_id, client_secret) response = RestClient.post Token.api_url, { grant_type: "client_credentials", client_id: client_id, client_secret: client_secret } parsed_response = JSON.parse(response) @access_token = parsed_response["access_token"] @created_at = parsed_response["created_at"].to_i @expires_in = parsed_response["expires_in"].to_i end |
Class Attribute Details
.api_url ⇒ Object
Returns the value of attribute api_url.
7 8 9 |
# File 'lib/codepicnic/token.rb', line 7 def api_url @api_url end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/codepicnic/token.rb', line 10 def access_token @access_token end |
#created_at ⇒ Object
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/codepicnic/token.rb', line 10 def created_at @created_at end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
10 11 12 |
# File 'lib/codepicnic/token.rb', line 10 def expires_in @expires_in end |
Instance Method Details
#expired? ⇒ Boolean
25 26 27 |
# File 'lib/codepicnic/token.rb', line 25 def expired? Time.now.to_i > (@created_at + @expires_in) end |