module GroupDocs::Signature::EntityMethods

Envelope and template entities share the same set of methods.

@see GroupDocs::Signature::Envelope @see GroupDocs::Signature::Form @see GroupDocs::Signature::Template

Public Class Methods

included(klass) click to toggle source
# File lib/groupdocs/signature/shared/entity_methods.rb, line 12
def self.included(klass)
  klass.extend ClassMethods
end

Public Instance Methods

create!(options = {}, access = {}) click to toggle source

Creates template or envelope.

@example Create new template

template = GroupDocs::Signature::Template.new
template.name = "Template"
template.email_subject = "Sing this!"
template.create!

@example Create new envelope

envelope = GroupDocs::Signature::Envelope.new
envelope.name = "Envelope"
envelope.email_subject = "Sing this!"
envelope.create!

@param [Hash] options Hash of options @option options [String] :template_id Template GUID to use @option options [String] :envelope_id Envelope GUID to use @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/signature/shared/entity_methods.rb, line 60
def create!(options = {}, access = {})
  template_id = options.delete(:template_id)
  envelope_id = options.delete(:envelope_id)
  options[:templateId] = template_id if template_id
  options[:envelopeId] = envelope_id if envelope_id

  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/signature/{{client_id}}/#{class_name}"
    request[:request_body] = to_hash
  end
  api.add_params(options.merge(:name => name))
  json = api.execute!

  self.id = json[class_name.to_sym][:id]
end
delete!(access = {}) click to toggle source

Deletes template, envelope or form.

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/signature/shared/entity_methods.rb, line 134
def delete!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/signature/{{client_id}}/#{class_name.pluralize}/#{id}"
  end.execute!
end
modify!(access = {}) click to toggle source

Modifies template, envelope or form.

@example Modify template

template = GroupDocs::Signature::Template.get!("g94h5g84hj9g4gf23i40j")
template.name = "Template"
template.email_subject = "Sing this!"
template.modify!

@example Modify envelope

envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
envelope.name = "Envelope"
envelope.email_subject = "Sing this!"
envelope.modify!

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/signature/shared/entity_methods.rb, line 97
def modify!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/signature/{{client_id}}/#{class_name.pluralize}/#{id}"
    request[:request_body] = to_hash
  end.execute!
end
rename!(name, access = {}) click to toggle source

Renames template, envelope or form.

@param [String] name New template name @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/signature/shared/entity_methods.rb, line 114
def rename!(name, access = {})
  api = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/signature/{{client_id}}/#{class_name.pluralize}/#{id}"
  end
  key = (class_name == 'form' ? :new_name : :name )
  api.add_params(key => name)
  api.execute!

  self.name = name
end