Class: SelfSDK::Services::Facts

Inherits:
Object
  • Object
show all
Defined in:
lib/services/facts.rb

Overview

Input class to handle fact requests on self network.

Instance Method Summary collapse

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.

Parameters:

  • messaging (SelfSDK::Messaging)

    messaging object.

  • client (SelfSDK::Client)

    http client object.



21
22
23
# File 'lib/services/facts.rb', line 21

def initialize(requester)
  @requester = requester
end

Instance Method Details

Generates a deep link to authenticate with self app.

Parameters:

  • facts (Array)

    a list of facts to be requested.

  • callback (String)

    the url you’ll be redirected if the app is not installed.

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :selfid (String)

    the user selfid you want to authenticate.

  • :cid (String)

    The unique identifier of the authentication request.

Returns:

  • (String, String)

    conversation id or encoded body.



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.

Parameters:

  • facts (Array)

    a list of facts to be requested.

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :cid (String)

    The unique identifier of the authentication request.

  • :options (String)

    Options you want to share with the identity.

Returns:

  • (String, String)

    conversation id or encoded body.



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

#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.

Overloads:

  • #request(selfid, facts, opts = {}, &block) ⇒ Object

    Parameters:

    • selfid (string)

      the receiver of the fact request.

    • facts (Array)

      array of facts to be requested

    • opts (Hash) (defaults to: {})

      the options to process the request.

    Options Hash (opts):

    • :cid (String)

      The unique identifier of the fact request.

  • #request(selfid, facts, opts = {}) ⇒ Object

    Returns SelfSDK:::Messages::FactRequest.

    Parameters:

    • selfid (string)

      the receiver of the fact request.

    • facts (Array)

      array of facts to be requested

    • opts (Hash) (defaults to: {})

      the options to request.

    Options Hash (opts):

    • :cid (String)

      The unique identifier of the fact request.

    • :exp_timeout (Integer)

      timeout in seconds to expire the request.

    • :allowed_for (Integer)

      number of seconds for enabling recurrent requests.

    Returns:

    • (Object)

      SelfSDK:::Messages::FactRequest

Yields:

  • (request)

    Invokes the given block when a response is received. @return [Object] SelfSDK:::Messages::FactRequest



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