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?, #rejected?, #request, #send_message, #unauthorized?

Constructor Details

#initialize(messaging) ⇒ FactResponse

Returns a new instance of FactResponse.



16
17
18
19
# File 'lib/messages/fact_response.rb', line 16

def initialize(messaging)
  @typ = MSG_TYPE
  super
end

Instance Attribute Details

#audienceObject

Returns the value of attribute audience.



14
15
16
# File 'lib/messages/fact_response.rb', line 14

def audience
  @audience
end

#authObject

Returns the value of attribute auth.



14
15
16
# File 'lib/messages/fact_response.rb', line 14

def auth
  @auth
end

#factsObject

Returns the value of attribute facts.



14
15
16
# File 'lib/messages/fact_response.rb', line 14

def facts
  @facts
end

Instance Method Details

#attestation_values_for(name) ⇒ Object



61
62
63
64
# File 'lib/messages/fact_response.rb', line 61

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

#attestations_for(name) ⇒ Object



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

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

#auth_response?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/messages/fact_response.rb', line 92

def auth_response?
  @auth == true
end

#bodyObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/messages/fact_response.rb', line 73

def body
  encoded_facts = []
  @facts.each do |fact|
    encoded_facts.push(fact.to_hash)
  end

  { typ: MSG_TYPE,
    iss: @jwt.id,
    sub: @sub || @to,
    aud: @audience,
    iat: SelfSDK::Time.now.strftime('%FT%TZ'),
    exp: (SelfSDK::Time.now + 3600).strftime('%FT%TZ'),
    cid: @id,
    jti: SecureRandom.uuid,
    status: @status,
    facts: encoded_facts,
    auth: @auth }
end

#fact(name) ⇒ Object



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

def fact(name)
  name = @messaging.source.normalize_fact_name(name)
  @facts.select{|f| f.name == name}.first
end

#parse(input, envelope = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/messages/fact_response.rb', line 21

def parse(input, envelope=nil)
  @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]
  @auth = payload[:auth]
  @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
  if envelope
    issuer = envelope.sender.split(":")
    @from_device = issuer.last
  end
end

#validate!(original) ⇒ Object



66
67
68
69
70
71
# File 'lib/messages/fact_response.rb', line 66

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