Sha256: 9af7d5719929381b89ed6ee972856fd3a4efe86ab0536edd7a8c8bcf27465b65

Contents?: true

Size: 512 Bytes

Versions: 1

Compression:

Stored size: 512 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

1 entries across 1 versions & 1 rubygems

Version Path
stekker_zaptec-1.2.0 lib/zaptec/credentials.rb