Class: Signatory::Template

Inherits:
API::Base
  • Object
show all
Defined in:
lib/signatory/template.rb

Instance Method Summary collapse

Methods inherited from API::Base

all, connection, formatted_collection_name, formatted_name, #id, instantiate_collection

Instance Method Details

#build_document(merge_fields, roles) ⇒ Object



8
9
10
11
# File 'lib/signatory/template.rb', line 8

def build_document(merge_fields, roles)
  doc_pkg = prepackage
  doc_pkg.prefill_and_send(merge_fields, roles)
end

#prefill_and_send(merge_fields, roles) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/signatory/template.rb', line 13

def prefill_and_send(merge_fields, roles)
  attributes.merge!({
    'merge_fields' => merge_fields,
    'roles' => roles,
    'action' => 'send'
  })

  doc = connection.format.decode(connection.post("/api/templates.xml", self.to_xml).body)
  Document.find(doc['guid'])
end

#prepackageObject



3
4
5
6
# File 'lib/signatory/template.rb', line 3

def prepackage
  record = connection.format.decode(post(:prepackage).body)
  Template.instantiate_record(record)
end

#to_xml(opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/signatory/template.rb', line 24

def to_xml(opts = {})
  super(opts.merge(:dasherize => false, :skip_types => true, :except => [:pages, :_type, :redirect_token, :content_type, :size, :tags])) do |b|
    b.tag!(:tags) do
      tags.split(" ").each do |tag|
        b.tag!(:tag) { b.value tag}
      end
    end unless attributes['tags'].blank?
  end
end