Class: Universign::Document

Inherits:
Object
  • Object
show all
Includes:
Safeguard
Defined in:
lib/universign/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Safeguard

included, #safeguard

Constructor Details

#initialize(options = {}) ⇒ Document

Create a new Universign::Document

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :content (Array<Byte>)

    Content of the PDF

  • :url (String)

    URL of the PDF

  • :name (String)

    Name of the PDF

  • :meta_data (Hash)

    Hash to join to the PDF



15
16
17
18
19
20
21
# File 'lib/universign/document.rb', line 15

def initialize(options = {})
  @params = HashWithIndifferentAccess.new

  options.each do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#file_contentObject (readonly)

Returns the value of attribute file_content.



5
6
7
# File 'lib/universign/document.rb', line 5

def file_content
  @file_content
end

#file_urlObject (readonly)

Returns the value of attribute file_url.



5
6
7
# File 'lib/universign/document.rb', line 5

def file_url
  @file_url
end

#nameString

The file name of this document

Returns:

  • (String)


69
70
71
# File 'lib/universign/document.rb', line 69

def name
  @name
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/universign/document.rb', line 6

def params
  @params
end

Class Method Details

.from_data(data) ⇒ Universign::Document

Create a new document from a Hash

Parameters:

  • data (Hash)

Returns:



27
28
29
30
31
32
33
# File 'lib/universign/document.rb', line 27

def self.from_data(data)
  @params = data

  document = Universign::Document.new
  document.params.merge!(@params)
  document
end

Instance Method Details

#contentArray<Byte>

The raw content of the PDF document

Returns:

  • (Array<Byte>)


38
39
40
# File 'lib/universign/document.rb', line 38

def content
  @content ||= params['content']
end

#content=(data) ⇒ Object



42
43
44
45
# File 'lib/universign/document.rb', line 42

def content=(data)
  @content         = data
  params[:content] =  XMLRPC::Base64.new(data)
end

#document_typeString

The type of this document

Returns:

  • (String)


62
63
64
# File 'lib/universign/document.rb', line 62

def document_type
  @document_type ||= params['documentType']
end

#meta_dataHash

The meta data of the PDF document

Returns:

  • (Hash)


94
95
96
# File 'lib/universign/document.rb', line 94

def 
  @meta_data ||= params['metaData']
end

#meta_data=(data) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/universign/document.rb', line 98

def meta_data=(data)
  if !data.is_a?(Hash)
    raise MetaDataMustBeAHash
  end

  @meta_data         = data
  params['metaData'] = data
end

#signature_fields=(data) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/universign/document.rb', line 78

def signature_fields=(data)
  if !data.is_a?(Array)
    raise 'SignatureFieldsMustBeAnArray'
  end

  @signature_fields = data
  params['signatureFields'] = data.map do |d|
    raise 'BadSignatureFieldType' unless d.instance_of?(SignatureField)

    d.params
  end
end

#urlString

The URL to download the PDF document

Returns:

  • (String)


50
51
52
# File 'lib/universign/document.rb', line 50

def url
  @url ||= params['url']
end

#url=(data) ⇒ Object



54
55
56
57
# File 'lib/universign/document.rb', line 54

def url=(data)
  @url          = data
  params['url'] = data
end