Class: Ably::Models::TokenRequest

Inherits:
Object
  • Object
show all
Includes:
Ably::Modules::ModelCommon
Defined in:
lib/submodules/ably-ruby/lib/ably/models/token_request.rb

Overview

TokenRequest is a class that stores the attributes of a token request

Ruby Time objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided it must always be expressed in milliseconds as the Ably API always uses milliseconds for time fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ably::Modules::ModelCommon

#==, #[], #as_json, #to_json

Methods included from Ably::Modules::MessagePack

#to_msgpack

Constructor Details

#initialize(attributes = {}) ⇒ TokenRequest

Returns a new instance of TokenRequest.

Options Hash (attributes):

  • :ttl (Integer)

    requested time to live for the token in milliseconds

  • :timestamp (Time, Integer)

    the timestamp of this request in milliseconds or as a Time

  • :key_name (String)

    API key name of the key against which this request is made

  • :capability (String)

    JSON stringified capability of the token

  • :client_id (String)

    client ID to associate with this token

  • :nonce (String)

    an opaque nonce string of at least 16 characters

  • :mac (String)

    the Message Authentication Code for this request



35
36
37
38
39
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 35

def initialize(attributes = {})
  @hash_object = IdiomaticRubyWrapper(attributes.clone)
  hash[:timestamp] = (hash[:timestamp].to_f * 1000).round if hash[:timestamp].kind_of?(Time)
  hash.freeze
end

Instance Attribute Details

#capabilityHash (readonly)



60
61
62
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 60

def capability
  JSON.parse(hash.fetch(:capability))
end

#client_idString (readonly)



67
68
69
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 67

def client_id
  hash[:client_id]
end

#hashHash (readonly)



104
105
106
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 104

def hash
  @hash_object
end

#key_nameString (readonly)



43
44
45
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 43

def key_name
  hash.fetch(:key_name)
end

#macString (readonly)



91
92
93
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 91

def mac
  hash.fetch(:mac)
end

#nonceString (readonly)



84
85
86
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 84

def nonce
  hash.fetch(:nonce)
end

#timestampTime (readonly)



76
77
78
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 76

def timestamp
  as_time_from_epoch(hash.fetch(:timestamp), granularity: :ms)
end

#ttlInteger (readonly)



52
53
54
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 52

def ttl
  hash.fetch(:ttl) / 1000
end

Instance Method Details

#persistedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Requests that the token is always persisted



98
99
100
# File 'lib/submodules/ably-ruby/lib/ably/models/token_request.rb', line 98

def persisted
  hash.fetch(:persisted)
end