Class: Ilovepdf::Tool::Signature

Inherits:
Ilovepdf::Task show all
Defined in:
lib/ilovepdf/tool/signature.rb

Constant Summary collapse

API_PARAMS =
[:brand_name,:brand_logo,
:language,:lock_order,
:message_signer,:subject_signer,:uuid_visible,:expiration_days,
:signer_reminders,:signer_reminder_days_cycle,:verify_enabled ]

Constants inherited from Ilovepdf::Task

Ilovepdf::Task::DOWNLOAD_INFO

Constants included from Ilovepdf

VERSION

Instance Attribute Summary

Attributes inherited from Ilovepdf::Task

#ignore_errors, #ignore_password, #output_filename, #packaged_filename, #result, #task_id, #tool, #try_pdf_repair

Instance Method Summary collapse

Methods inherited from Ilovepdf::Task

#add_file, #add_file_from_url, #assign_meta_value, #blob, #chained_task?, #delete!, #delete_file, #download, #download_info, #enable_file_encryption, #files, #next, #status

Methods included from Ilovepdf

root

Constructor Details

#initialize(public_key, secret_key, make_start = true) ⇒ Signature

Returns a new instance of Signature.



18
19
20
21
# File 'lib/ilovepdf/tool/signature.rb', line 18

def initialize(public_key, secret_key, make_start=true)
  self.tool = :sign
  super(public_key, secret_key, make_start)
end

Instance Method Details

#<<(receiver) ⇒ Object



91
92
93
94
95
# File 'lib/ilovepdf/tool/signature.rb', line 91

def <<(receiver)
  raise ::Ilovepdf::Errors::ArgumentError.new("value is not an Ilovepdf::Signature::Receive") unless receiver.is_a?(::Ilovepdf::Signature::Receiver)
  @signers ||= []
  @signers << receiver
end

#add_brand(name:, logo:) ⇒ Object



77
78
79
80
81
# File 'lib/ilovepdf/tool/signature.rb', line 77

def add_brand(name:,logo:)
  brand_logo_file = perform_upload_request()
  @brand_logo = brand_logo_file.server_filename
  @brand_name = name
end

#add_receiver(receiver) ⇒ Object



39
40
41
42
# File 'lib/ilovepdf/tool/signature.rb', line 39

def add_receiver(receiver)
  raise ::Ilovepdf::Errors::ArgumentError.new("value is not receiver") unless receiver.is_a?(Ilovepdf::Signature::Receiver)
  @signers << receiver
end

#brand_logo=(value) ⇒ Object



35
36
37
# File 'lib/ilovepdf/tool/signature.rb', line 35

def brand_logo=(value)
  raise ::Ilovepdf::Errors::UnsupportedFunctionalityError.new("Method not implemented")
end

#brand_name=(value) ⇒ Object



31
32
33
# File 'lib/ilovepdf/tool/signature.rb', line 31

def brand_name=(value)
  raise ::Ilovepdf::Errors::UnsupportedFunctionalityError.new("Method not implemented")
end

#email_content(subject:, body:) ⇒ Object



53
54
55
56
57
# File 'lib/ilovepdf/tool/signature.rb', line 53

def email_content(subject:,body:)
  @subject_signer = subject
  @message_signer = body
  {subject: @subject_signer,body: @message_signer}
end

#executeObject



23
24
25
# File 'lib/ilovepdf/tool/signature.rb', line 23

def execute
  @result = perform_process_request
end

#expiration_days=(value) ⇒ Object



59
60
61
62
# File 'lib/ilovepdf/tool/signature.rb', line 59

def expiration_days=(value)
  raise ::Ilovepdf::Errors::ArgumentError.new("value is not an Integer") unless value.is_a?(Integer)
  @expiration_days = value
end

#extract_api_paramsObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ilovepdf/tool/signature.rb', line 97

def extract_api_params
  params = super
  params[:task] = task_id
  params[:files] = files.map do |file|
    {server_filename: file.server_filename,filename: file.filename}
  end
  params[:signers] = signers.map do |signer|
    {
      name: signer.name,
      email: signer.email,
      phone: signer.phone,
      files: signer.elements.group_by do |element|
        element.file.server_filename
      end.inject([]) do |result,(server_filename,elements)|
        result << {
          server_filename: server_filename,
          elements: elements.map(&:to_h)
        }
        result
      end,
      type: signer.type,
      access_code: signer.access_code,
      force_signature_type: signer.force_signature_type
    }
  end
  params.crush
end

#language=(value) ⇒ Object



44
45
46
47
# File 'lib/ilovepdf/tool/signature.rb', line 44

def language=(value)
  raise ::Ilovepdf::Errors::ArgumentError.new("value is not a string") unless value.is_a?(String)
  @language = value
end

#lock_order=(value) ⇒ Object



49
50
51
# File 'lib/ilovepdf/tool/signature.rb', line 49

def lock_order=(value)
  @lock_order = !!value ? "1" : "0"
end

#reminders=(value) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ilovepdf/tool/signature.rb', line 64

def reminders=(value)
  raise ::Ilovepdf::Errors::ArgumentError.new("value is not an Integer") unless value.is_a?(Integer)
  if(value <= 0)
    @signer_reminders = false
    @signer_reminder_days_cycle = nil
  else
    @signer_reminders = true
    @signer_reminder_days_cycle = value
  end
  value
end

#send_to_signObject



125
126
127
128
129
130
# File 'lib/ilovepdf/tool/signature.rb', line 125

def send_to_sign
  body = extract_api_params
  extracted_body = RequestPayload::FormUrlEncoded.new(body).extract_to_s
  response = send_request('post', 'signature', body: extracted_body)
  response
end

#signersObject



87
88
89
# File 'lib/ilovepdf/tool/signature.rb', line 87

def signers
  @signers ||= []
end

#uuid_visible=(value) ⇒ Object



27
28
29
# File 'lib/ilovepdf/tool/signature.rb', line 27

def uuid_visible=(value)
  @uuid_visible = !!value
end

#verify_enabled=(value) ⇒ Object



83
84
85
# File 'lib/ilovepdf/tool/signature.rb', line 83

def verify_enabled=(value)
  @verify_enabled = !!value
end