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
Returns the value of attribute facts.
14
15
16
|
# File 'lib/messages/fact_request.rb', line 14
def facts
@facts
end
|
Returns the value of attribute options.
14
15
16
|
# File 'lib/messages/fact_request.rb', line 14
def options
@options
end
|
Instance Method Details
[View source]
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/messages/fact_request.rb', line 78
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
|
permalink
#build_response ⇒ Object
[View source]
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/messages/fact_request.rb', line 61
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
|
permalink
#parse(input, envelope = nil) ⇒ Object
[View source]
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/messages/fact_request.rb', line 42
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
|
permalink
#parse_facts(facts) ⇒ Object
[View source]
16
17
18
19
20
21
22
23
24
|
# File 'lib/messages/fact_request.rb', line 16
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
|
permalink
#populate(selfid, facts, opts) ⇒ Object
[View source]
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/messages/fact_request.rb', line 26
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
|
permalink
#share_facts(facts) ⇒ Object
[View source]
72
73
74
75
76
|
# File 'lib/messages/fact_request.rb', line 72
def share_facts(facts)
m = build_response
m.facts = parse_facts(facts)
m.send_message
end
|