Class: CodePicnic::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/codepicnic/token.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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
24
25
# File 'lib/codepicnic/token.rb', line 12

def initialize(client_id, client_secret)
  puts client_id
  puts 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_urlObject

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_tokenObject

Returns the value of attribute access_token


10
11
12
# File 'lib/codepicnic/token.rb', line 10

def access_token
  @access_token
end

#created_atObject

Returns the value of attribute created_at


10
11
12
# File 'lib/codepicnic/token.rb', line 10

def created_at
  @created_at
end

#expires_inObject

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

Returns:

  • (Boolean)

27
28
29
# File 'lib/codepicnic/token.rb', line 27

def expired?
  Time.now.to_i > (@created_at + @expires_in)
end