Class: SelfSDK::Messages::FactResponse

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

Constant Summary collapse

MSG_TYPE =
"identities.facts.query.resp"

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #exp_timeout, #expires, #fields, #from, #from_device, #id, #input, #intermediary, #payload, #status, #sub, #to, #to_device, #typ

Instance Method Summary collapse

Methods inherited from Base

#accepted?, #encrypt_message, #errored?, #initialize, #rejected?, #request, #send_message, #unauthorized?

Constructor Details

This class inherits a constructor from SelfSDK::Messages::Base

Instance Attribute Details

#audienceObject

Returns the value of attribute audience.


12
13
14
# File 'lib/messages/fact_response.rb', line 12

def audience
  @audience
end

#factsObject

Returns the value of attribute facts.


12
13
14
# File 'lib/messages/fact_response.rb', line 12

def facts
  @facts
end

Instance Method Details

#attestation_values_for(name) ⇒ Object

[View source]

49
50
51
52
# File 'lib/messages/fact_response.rb', line 49

def attestation_values_for(name)
  a = attestations_for(name)
  a.map{|a| a.value}
end

#attestations_for(name) ⇒ Object

[View source]

43
44
45
46
47
# File 'lib/messages/fact_response.rb', line 43

def attestations_for(name)
  f = fact(name)
  return [] if f.nil?
  f.attestations
end

#fact(name) ⇒ Object

[View source]

38
39
40
41
# File 'lib/messages/fact_response.rb', line 38

def fact(name)
  name = SelfSDK::fact_name(name)
  @facts.select{|f| f.name == name}.first
end

#parse(input) ⇒ Object

[View source]

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/messages/fact_response.rb', line 14

def parse(input)
  @input = input
  @typ = MSG_TYPE
  @payload = get_payload input
  @id = payload[:cid]
  @from = payload[:iss]
  @to = payload[:sub]
  @expires = ::Time.parse(payload[:exp])
  @issued = ::Time.parse(payload[:iat])
  @audience = payload[:aud]
  @status = payload[:status]
  @facts = []
  payload[:facts] = [] if payload[:facts].nil?
  payload[:facts].each do |f|
    begin
      fact = SelfSDK::Messages::Fact.new(@messaging)
      fact.parse(f)
      @facts.push(fact)
    rescue StandardError => e
      SelfSDK.logger.info e.message
    end
  end
end

#validate!(original) ⇒ Object

[View source]

54
55
56
57
58
59
# File 'lib/messages/fact_response.rb', line 54

def validate!(original)
  super
  @facts.each do |f|
    f.validate! original
  end
end