Class: SelfSDK::Services::Docs

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

Overview

Input class to handle document requests on self network.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messaging, url) ⇒ SelfSDK::Services::Docs

Creates a new docs service. Docs service mainly allows you to send document signature requests.

Parameters:

  • messaging (SelfSDK::Messaging)

    messaging object.



19
20
21
22
# File 'lib/services/docs.rb', line 19

def initialize(messaging, url)
  @messaging = messaging
  @self_url = url
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



11
12
13
# File 'lib/services/docs.rb', line 11

def app_id
  @app_id
end

Instance Method Details

#request_signature(recipient, body, objects, opts = {}) {|request| ... } ⇒ Object

Sends a signature request to the specified user.

you just want the body to be signed.

Parameters:

  • recipient (string)

    the recipient of the request.

  • body (string)

    the message to be displayed to the user.

  • objects (Array)

    array of objects to be signed. provide an empty array if

Yields:

  • (request)

    Invokes the given block when a response is received.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/services/docs.rb', line 31

def request_signature(recipient, body, objects, opts = {}, &block)
  jti = SecureRandom.uuid
  req = {
    jti: jti,
    typ: "document.sign.req",
    aud: recipient,
    msg: body,
    objects: [],
  }

  auth_token = @messaging.client.jwt.auth_token
  objects.each do |o|
    req[:objects] << SelfSDK::Chat::FileObject.new(auth_token, @self_url).build_from_data(
      o[:name],
      o[:data],
      o[:mime],
      opts
    ).to_payload
  end

  if block_given?
    @messaging.client.set_observer(OpenStruct.new({
      id: jti,
      to: recipient,
      from: @messaging.client.jwt.id
    }), timeout: 60 * 60 * 10, &block)

    return @messaging.send(recipient, req)
  end

  @messaging.send(recipient, req)
end

#subscribe {|request| ... } ⇒ Object

Subscribes to all document sign responses.

Yields:

  • (request)

    Invokes the given block when a response is received.



67
68
69
# File 'lib/services/docs.rb', line 67

def subscribe(&block)
  @messaging.subscribe(:document_sign_response, &block)
end