Class: SelfSDK::Services::Facts
- Inherits:
-
Object
- Object
- SelfSDK::Services::Facts
- Defined in:
- lib/services/facts.rb
Overview
Self provides this self-hosted verified intermediary. Input class to handle fact requests on self network.
Defined Under Namespace
Classes: Delegation, Fact, Group
Instance Method Summary collapse
-
#generate_deep_link(facts, callback, opts = {}) ⇒ String
Generates a deep link to authenticate with self app.
-
#generate_qr(facts, opts = {}) ⇒ String
Generates a QR code so users can send facts to your app.
-
#initialize(requester) ⇒ SelfSDK::Services::Facts
constructor
Creates a new facts service.
-
#issue(selfid, facts, opts = {}) ⇒ Object
Issues a custom fact and sends it to the user.
-
#request(selfid, facts, opts = {}) {|request| ... } ⇒ Object
Sends a fact request to the specified selfid.
-
#request_via_intermediary(selfid, facts, opts = {}, &block) ⇒ Object
Sends a request through an intermediary.
-
#subscribe(&block) ⇒ Object
Adds an observer for a fact response Whenever you receive a fact response registered observers will receive a notification.
Constructor Details
#initialize(requester) ⇒ SelfSDK::Services::Facts
Creates a new facts service. Facts service mainly manages fact requests against self users wanting to share their verified facts with your app.
21 22 23 |
# File 'lib/services/facts.rb', line 21 def initialize(requester) @requester = requester end |
Instance Method Details
#generate_deep_link(facts, callback, opts = {}) ⇒ String
Generates a deep link to authenticate with self app.
92 93 94 95 |
# File 'lib/services/facts.rb', line 92 def generate_deep_link(facts, callback, opts = {}) opts[:auth] = false @requester.generate_deep_link(facts, callback, opts) end |
#generate_qr(facts, opts = {}) ⇒ String
Generates a QR code so users can send facts to your app.
79 80 81 82 |
# File 'lib/services/facts.rb', line 79 def generate_qr(facts, opts = {}) opts[:auth] = false @requester.generate_qr(facts, opts) end |
#issue(selfid, facts, opts = {}) ⇒ Object
Issues a custom fact and sends it to the user.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/services/facts.rb', line 102 def issue(selfid, facts, opts = {}) hased_facts = [] facts.each do |f| hased_facts << f.to_hash end SelfSDK.logger.info "issuing facts for #{selfid}" msg = SelfSDK::Messages::FactIssue.new(@requester.messaging) msg.populate(selfid, hased_facts, opts) msg. end |
#request(selfid, facts, opts = {}, &block) ⇒ Object #request(selfid, facts, opts = {}) ⇒ Object
Sends a fact request to the specified selfid. An fact request allows your app to access trusted facts of your user with its permission.
45 46 47 48 |
# File 'lib/services/facts.rb', line 45 def request(selfid, facts, opts = {}, &block) opts[:auth] = false # force auth to false as you have auth service to make auth requests @requester.request(selfid, facts, opts, &block) end |
#request_via_intermediary(selfid, facts, opts = {}, &block) ⇒ Object
Sends a request through an intermediary. An intermediary is an entity trusted by the user and acting as a proxy between you and the recipient of your fact request. Intermediaries usually do not provide the original user facts, but they create its own assertions based on your request and the user’s facts.
@param selfid [string] the receiver of the authentication request.
@param [Hash] opts the options to authenticate.
@option opts [String] intermediary an intermediary identity to be used.
@return [Object] SelfSDK:::Messages::FactRequest
60 61 62 |
# File 'lib/services/facts.rb', line 60 def request_via_intermediary(selfid, facts, opts = {}, &block) @requester.request_via_intermediary(selfid, facts, opts, &block) end |
#subscribe(&block) ⇒ Object
Adds an observer for a fact response Whenever you receive a fact response registered observers will receive a notification.
@yield [request] Invokes the block with a fact response message.
68 69 70 |
# File 'lib/services/facts.rb', line 68 def subscribe(&block) @requester.subscribe(false, &block) end |