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.
12
13
14
|
# File 'lib/messages/fact_request.rb', line 12
def facts
@facts
end
|
Returns the value of attribute options.
12
13
14
|
# File 'lib/messages/fact_request.rb', line 12
def options
@options
end
|
Instance Method Details
[View source]
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/messages/fact_request.rb', line 70
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]
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/messages/fact_request.rb', line 53
def build_response
m = SelfSDK::Messages::FactResponse.new(@messaging)
m.id = @id
m.from = @to
m.to = @from
m.audience = @from
m.to_device = @messaging.device_id
m.facts = @facts
m
end
|
permalink
#parse(input) ⇒ Object
[View source]
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/messages/fact_request.rb', line 40
def parse(input)
@input = input
@typ = MSG_TYPE
@payload = get_payload input
@id = @payload[:cid]
@from = @payload[:iss]
@to = @payload[:sub]
@expires = @payload[:exp]
@description = @payload.include?(:description) ? @payload[:description] : nil
@facts = @payload[:facts]
@options = @payload[:options]
end
|
permalink
#parse_facts(facts) ⇒ Object
[View source]
14
15
16
17
18
19
20
21
22
|
# File 'lib/messages/fact_request.rb', line 14
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]
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/messages/fact_request.rb', line 24
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]
64
65
66
67
68
|
# File 'lib/messages/fact_request.rb', line 64
def share_facts(facts)
m = build_response
m.facts = parse_facts(facts)
m.send_message
end
|