Sha256: bc8bde16b447df3638980655c011cb94add5f8ca7b80b60dd27f93d6c4aa8016

Contents?: true

Size: 513 Bytes

Versions: 2

Compression:

Stored size: 513 Bytes

Contents

module Zaptec
  class Credentials
    attr_accessor :access_token, :expires_at

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

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stekker_zaptec-1.2.2 lib/zaptec/credentials.rb
stekker_zaptec-1.2.1 lib/zaptec/credentials.rb