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



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

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



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

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



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

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



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

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

.token=(token) ⇒ Object



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

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

Instance Method Details

#to_json(opts = {}) ⇒ Object

the json should skip the root element



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

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