Class: SelfSDK::Messages::FactRequest
- Inherits:
-
Base
- Object
- Base
- SelfSDK::Messages::FactRequest
show all
- Defined in:
- lib/messages/fact_request.rb
Constant Summary
collapse
- MSG_TYPE =
"identities.facts.query.req"
- DEFAULT_EXP_TIMEOUT =
900
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?, #validate!
Instance Attribute Details
#facts ⇒ Object
Returns the value of attribute facts.
15
16
17
|
# File 'lib/messages/fact_request.rb', line 15
def facts
@facts
end
|
#options ⇒ Object
Returns the value of attribute options.
15
16
17
|
# File 'lib/messages/fact_request.rb', line 15
def options
@options
end
|
Instance Method Details
#body ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/messages/fact_request.rb', line 79
def body
b = {
typ: MSG_TYPE,
iss: @jwt.id,
sub: @to,
iat: SelfSDK::Time.now.strftime('%FT%TZ'),
exp: (SelfSDK::Time.now + @exp_timeout).strftime('%FT%TZ'),
cid: @id,
jti: SecureRandom.uuid,
facts: @facts,
}
b[:options] = @options unless (@options.nil? || @options == false)
b[:description] = @description unless (@description.nil? || @description.empty?)
b
end
|
#build_response ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/messages/fact_request.rb', line 62
def build_response
m = SelfSDK::Messages::FactResponse.new(@messaging)
m.id = @id
m.from = @to
m.to = @from
m.sub = @to
m.audience = @from
m.facts = @facts
m
end
|
#parse(input, envelope = nil) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/messages/fact_request.rb', line 43
def parse(input, envelope=nil)
@input = input
@typ = MSG_TYPE
@payload = get_payload input
@id = @payload[:cid]
@from = @payload[:iss]
@to = @payload[:sub]
@audience = payload[:aud]
@expires = @payload[:exp]
@description = @payload.include?(:description) ? @payload[:description] : nil
@facts = @payload[:facts]
@options = @payload[:options]
if envelope
issuer = envelope.sender.split(":")
@from_device = issuer.last
end
end
|
#parse_facts(facts) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/messages/fact_request.rb', line 17
def parse_facts(facts)
@facts = []
facts.each do |fact|
f = SelfSDK::Messages::Fact.new(@messaging)
f.parse(fact)
@facts << f.to_hash
end
@facts
end
|
#populate(selfid, facts, opts) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/messages/fact_request.rb', line 27
def populate(selfid, facts, opts)
@id = SecureRandom.uuid
@from = @client.jwt.id
@to = selfid
@facts = parse_facts(facts)
@id = opts[:cid] if opts.include?(:cid)
@options = opts.fetch(:options, false)
@description = opts.include?(:description) ? opts[:description] : nil
@exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
@intermediary = if opts.include?(:intermediary)
opts[:intermediary]
end
end
|
#share_facts(facts) ⇒ Object
73
74
75
76
77
|
# File 'lib/messages/fact_request.rb', line 73
def share_facts(facts)
m = build_response
m.facts = parse_facts(facts)
m.send_message
end
|