Class: SelfSDK::Messages::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/messages/base.rb

Direct Known Subclasses

AuthenticationMessage, FactRequest, FactResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messaging) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/messages/base.rb', line 10

def initialize(messaging)
  @client = messaging.client
  @jwt = @client.jwt
  @messaging = messaging
  @device_id = "1"
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/messages/base.rb', line 6

def description
  @description
end

#exp_timeoutObject

Returns the value of attribute exp_timeout.



6
7
8
# File 'lib/messages/base.rb', line 6

def exp_timeout
  @exp_timeout
end

#expiresObject

Returns the value of attribute expires.



6
7
8
# File 'lib/messages/base.rb', line 6

def expires
  @expires
end

#fieldsObject

Returns the value of attribute fields.



6
7
8
# File 'lib/messages/base.rb', line 6

def fields
  @fields
end

#fromObject

Returns the value of attribute from.



6
7
8
# File 'lib/messages/base.rb', line 6

def from
  @from
end

#from_deviceObject

Returns the value of attribute from_device.



6
7
8
# File 'lib/messages/base.rb', line 6

def from_device
  @from_device
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/messages/base.rb', line 6

def id
  @id
end

#inputObject

Returns the value of attribute input.



6
7
8
# File 'lib/messages/base.rb', line 6

def input
  @input
end

#intermediaryObject

Returns the value of attribute intermediary.



6
7
8
# File 'lib/messages/base.rb', line 6

def intermediary
  @intermediary
end

#payloadObject

Returns the value of attribute payload.



6
7
8
# File 'lib/messages/base.rb', line 6

def payload
  @payload
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/messages/base.rb', line 6

def status
  @status
end

#subObject

Returns the value of attribute sub.



6
7
8
# File 'lib/messages/base.rb', line 6

def sub
  @sub
end

#toObject

Returns the value of attribute to.



6
7
8
# File 'lib/messages/base.rb', line 6

def to
  @to
end

#to_deviceObject

Returns the value of attribute to_device.



6
7
8
# File 'lib/messages/base.rb', line 6

def to_device
  @to_device
end

#typObject

Returns the value of attribute typ.



6
7
8
# File 'lib/messages/base.rb', line 6

def typ
  @typ
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/messages/base.rb', line 37

def accepted?
  status == "accepted"
end

#errored?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/messages/base.rb', line 41

def errored?
  status == "errored"
end

#rejected?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/messages/base.rb', line 33

def rejected?
  status == "rejected"
end

#requestObject



17
18
19
20
21
# File 'lib/messages/base.rb', line 17

def request
  res = @messaging.send_and_wait_for_response(proto, self)
  SelfSDK.logger.info "synchronously messaging to #{@to}:#{@to_device}"
  res
end

#send_messageObject



23
24
25
26
27
# File 'lib/messages/base.rb', line 23

def send_message
  res = @messaging.send_message proto
  SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@to_device}"
  res
end

#unauthorized?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/messages/base.rb', line 29

def unauthorized?
  status == "unauthorized"
end

#validate!(original) ⇒ Object

Raises:

  • (::StandardError)


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/messages/base.rb', line 45

def validate!(original)
  unless original.nil?
    raise ::StandardError.new("bad response audience") if @audience != original.from
    if original.intermediary.nil?
      raise ::StandardError.new("bad issuer") if @from != original.to
    else
      raise ::StandardError.new("bad issuer") if @from != original.intermediary
    end
  end
  raise ::StandardError.new("expired message") if @expires < SelfSDK::Time.now
  raise ::StandardError.new("issued too soon") if @issued > SelfSDK::Time.now
end