class SelfSDK::Messages::FactRequest
Constants
- DEFAULT_EXP_TIMEOUT
- MSG_TYPE
Attributes
facts[RW]
options[RW]
Public Instance Methods
body()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
proto(to_device)
click to toggle source
# File lib/messages/fact_request.rb, line 97 def proto(to_device) @to_device = to_device if @intermediary.nil? recipient = "#{@to}:#{@to_device}" ciphertext = encrypt_message(@jwt.prepare(body), @to, @to_device) else recipient = "#{@intermediary}:#{@to_device}" ciphertext = encrypt_message(@jwt.prepare(body), @intermediary, @to_device) end m = SelfMsg::Message.new m.id = SecureRandom.uuid m.sender = "#{@jwt.id}:#{@messaging.device_id}" m.recipient = recipient m.ciphertext = ciphertext m end