Class: Docusigner::Base

Inherits:
ReactiveResource::Base
  • Object
show all
Includes:
Multipart::Resource
Defined in:
lib/docusigner/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Multipart::Resource

#add_document, #encode

Class Method Details

.act_as_user(user, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/docusigner/base.rb', line 39

def act_as_user(user, &block)
  old_header = headers.delete('X-DocuSign-Act-As-User')
  headers['X-DocuSign-Act-As-User'] = user
  yield
  if old_header.nil?
    headers.delete('X-DocuSign-Act-As-User')
  else
    headers['X-DocuSign-Act-As-User'] = old_header
  end
end

.authorization=(options = {}) ⇒ Object



35
36
37
# File 'lib/docusigner/base.rb', line 35

def authorization=(options = {})
  headers['X-DocuSign-Authentication'] = "<DocuSignCredentials><Username>%{username}</Username><Password>%{password}</Password><IntegratorKey>%{integrator_key}</IntegratorKey></DocuSignCredentials>" % options
end

.connection(refresh = false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/docusigner/base.rb', line 20

def connection(refresh = false)
  if defined?(@connection) || self == Docusigner::Base
    @connection = Docusigner::Connection.new(site, format) if refresh || @connection.nil? || !@connection.is_a?(Docusigner::Connection)
    @connection.timeout = timeout if timeout
    @connection.ssl_options = ssl_options if ssl_options
    @connection
  else
    superclass.connection
  end
end

.headersObject

we want to inherit headers for authentication



14
15
16
17
18
# File 'lib/docusigner/base.rb', line 14

def headers
  @headers ||= begin
    superclass.respond_to?(:headers) ? superclass.headers.dup : {}
  end
end

.token=(token) ⇒ Object



31
32
33
# File 'lib/docusigner/base.rb', line 31

def token=(token)
  headers['Authorization'] = "Bearer #{token}"
end

Instance Method Details

#to_json(opts = {}) ⇒ Object

the json should skip the root element



91
92
93
# File 'lib/docusigner/base.rb', line 91

def to_json(opts = {})
  as_json.to_json
end