Class: WalmartOpen::AuthToken

Inherits:
Object
  • Object
show all
Defined in:
lib/walmart_open/auth_token.rb

Constant Summary collapse

BUFFER_TIME =

seconds

30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs, grant_time = Time.now) ⇒ AuthToken

Returns a new instance of AuthToken.



10
11
12
13
14
15
# File 'lib/walmart_open/auth_token.rb', line 10

def initialize(attrs, grant_time = Time.now)
  @expiration_time = grant_time + attrs["expires_in"]
  @token_type = attrs["token_type"]
  @access_token = attrs["access_token"]
  @time = grant_time
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/walmart_open/auth_token.rb', line 5

def access_token
  @access_token
end

#expiration_timeObject (readonly)

Returns the value of attribute expiration_time.



5
6
7
# File 'lib/walmart_open/auth_token.rb', line 5

def expiration_time
  @expiration_time
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/walmart_open/auth_token.rb', line 5

def time
  @time
end

#token_typeObject (readonly)

Returns the value of attribute token_type.



5
6
7
# File 'lib/walmart_open/auth_token.rb', line 5

def token_type
  @token_type
end

Instance Method Details

#authorization_headerObject



21
22
23
# File 'lib/walmart_open/auth_token.rb', line 21

def authorization_header
  "#{token_type.capitalize} #{access_token}"
end

#expired?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/walmart_open/auth_token.rb', line 17

def expired?
  Time.now + BUFFER_TIME >= expiration_time
end