Class: Zaptec::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/zaptec/credentials.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token, expires_at) ⇒ Credentials

Returns a new instance of Credentials.



5
6
7
8
# File 'lib/zaptec/credentials.rb', line 5

def initialize(access_token, expires_at)
  @access_token = access_token
  @expires_at = expires_at
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



3
4
5
# File 'lib/zaptec/credentials.rb', line 3

def access_token
  @access_token
end

#expires_atObject

Returns the value of attribute expires_at.



3
4
5
# File 'lib/zaptec/credentials.rb', line 3

def expires_at
  @expires_at
end

Class Method Details

.parse(data) ⇒ Object



14
15
16
17
18
19
# File 'lib/zaptec/credentials.rb', line 14

def self.parse(data)
  new(
    data.fetch("access_token"),
    Time.zone.at(data.fetch("expires_at")),
  )
end

Instance Method Details

#as_jsonObject



21
22
23
# File 'lib/zaptec/credentials.rb', line 21

def as_json(*)
  super.merge("expires_at" => expires_at.to_i)
end

#expired?(at = Time.zone.now) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/zaptec/credentials.rb', line 10

def expired?(at = Time.zone.now)
  expires_at.nil? || at >= expires_at
end