Class: GroupDocs::Signature::Form
- Inherits:
-
Api::Entity
- Object
- Api::Entity
- GroupDocs::Signature::Form
- Extended by:
- ResourceMethods
- Defined in:
- lib/groupdocs/signature/form.rb
Constant Summary collapse
- STATUSES =
{ :draft => -1, :in_progress => 1, :completed => 2, :archived => 3, }
Instance Attribute Summary collapse
- #canParticipantDownloadForm ⇒ Object
- #createdTimeStamp ⇒ Object
- #documentsCount ⇒ Object
- #documentsPages ⇒ Object
- #fieldsInFinalFileName ⇒ Object
- #id ⇒ Object
- #name ⇒ Object
- #notifyOwnerOnSign ⇒ Object
- #ownerGuid ⇒ Object
- #participantsCount ⇒ Object
-
#status ⇒ Symbol
Converts status to human-readable format.
- #statusDateTime ⇒ Object
- #templateGuid ⇒ Object
- #waterMarkImage ⇒ Object
- #waterMarkText ⇒ Object
Class Method Summary collapse
-
.all!(options = {}, access = {}) ⇒ Array<GroupDocs::Signature::Envelope>
Returns a list of all forms.
-
.get!(id, options = {}, access = {}) ⇒ GroupDocs::Signature::Form
Returns form by its identifier.
Instance Method Summary collapse
-
#add_field!(field, document, opts = {}, access = {}) ⇒ Object
Adds field for document.
-
#archive!(access = {}) ⇒ Object
Archives completed form.
-
#complete!(access = {}) ⇒ Object
Completes form.
-
#create!(options = {}, access = {}) ⇒ Object
Creates form.
-
#documents!(options = {}, access = {}) ⇒ Array<GroupDocs::Document>
Returns documents array.
-
#fields!(document, access = {}) ⇒ Object
Returns an array of fields for document per participant.
-
#fields_in_final_file_name ⇒ Array<String>
Converts field names to human-readable format.
-
#fields_in_final_file_name=(fields) ⇒ Object
Converts array of field names to machine-readable format.
-
#modify_field_location!(location, field, document, recipient, access = {}) ⇒ Object
Modifies field location.
-
#modify_form_document!(document, options = {}, access = {}) ⇒ Object
Modify signature form document.
- #publish!(callbackUrl = {}, access = {}) ⇒ Object
-
#signed_documents!(path, access = {}) ⇒ String
Downloads signed documents to given path.
-
#update_from_template!(template, access = {}) ⇒ Object
Updates form adding fields from template.
Methods included from ResourceMethods
Methods included from FieldMethods
#assign_field!, #delete_field!, #delete_field_location!, #modify_field!, #rename_field!
Methods included from DocumentMethods
#add_document!, #remove_document!
Methods included from EntityMethods
#delete!, included, #modify!, #rename!
Methods inherited from Api::Entity
#initialize, #inspect, #to_hash
Methods included from Api::Helpers::Accessor
Constructor Details
This class inherits a constructor from GroupDocs::Api::Entity
Instance Attribute Details
#canParticipantDownloadForm ⇒ Object
98 99 100 |
# File 'lib/groupdocs/signature/form.rb', line 98 def canParticipantDownloadForm @canParticipantDownloadForm end |
#createdTimeStamp ⇒ Object
86 87 88 |
# File 'lib/groupdocs/signature/form.rb', line 86 def createdTimeStamp @createdTimeStamp end |
#documentsCount ⇒ Object
90 91 92 |
# File 'lib/groupdocs/signature/form.rb', line 90 def documentsCount @documentsCount end |
#documentsPages ⇒ Object
92 93 94 |
# File 'lib/groupdocs/signature/form.rb', line 92 def documentsPages @documentsPages end |
#fieldsInFinalFileName ⇒ Object
96 97 98 |
# File 'lib/groupdocs/signature/form.rb', line 96 def fieldsInFinalFileName @fieldsInFinalFileName end |
#id ⇒ Object
78 79 80 |
# File 'lib/groupdocs/signature/form.rb', line 78 def id @id end |
#name ⇒ Object
80 81 82 |
# File 'lib/groupdocs/signature/form.rb', line 80 def name @name end |
#notifyOwnerOnSign ⇒ Object
106 107 108 |
# File 'lib/groupdocs/signature/form.rb', line 106 def notifyOwnerOnSign @notifyOwnerOnSign end |
#ownerGuid ⇒ Object
82 83 84 |
# File 'lib/groupdocs/signature/form.rb', line 82 def ownerGuid @ownerGuid end |
#participantsCount ⇒ Object
94 95 96 |
# File 'lib/groupdocs/signature/form.rb', line 94 def participantsCount @participantsCount end |
#status ⇒ Symbol
Converts status to human-readable format.
100 101 102 |
# File 'lib/groupdocs/signature/form.rb', line 100 def status @status end |
#statusDateTime ⇒ Object
88 89 90 |
# File 'lib/groupdocs/signature/form.rb', line 88 def statusDateTime @statusDateTime end |
#templateGuid ⇒ Object
84 85 86 |
# File 'lib/groupdocs/signature/form.rb', line 84 def templateGuid @templateGuid end |
#waterMarkImage ⇒ Object
104 105 106 |
# File 'lib/groupdocs/signature/form.rb', line 104 def waterMarkImage @waterMarkImage end |
#waterMarkText ⇒ Object
102 103 104 |
# File 'lib/groupdocs/signature/form.rb', line 102 def waterMarkText @waterMarkText end |
Class Method Details
.all!(options = {}, access = {}) ⇒ Array<GroupDocs::Signature::Envelope>
Returns a list of all forms.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/groupdocs/signature/form.rb', line 35 def self.all!( = {}, access = {}) status_id = .delete(:status_id) [:statusId] = status_id if status_id api = Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = '/signature/{{client_id}}/forms' end api.add_params() json = api.execute! json[:forms].map do |form| new(form) end end |
.get!(id, options = {}, access = {}) ⇒ GroupDocs::Signature::Form
Returns form by its identifier.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/groupdocs/signature/form.rb', line 63 def self.get!(id, = {}, access = {}) if [:public] json = Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/signature/public/forms/#{id}" end.execute! new(json[:form]) else super(id, access) end end |
Instance Method Details
#add_field!(field, document, opts = {}, access = {}) ⇒ Object
Adds field for document.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/groupdocs/signature/form.rb', line 306 def add_field!(field, document, opts = {}, access = {}) field.is_a?(GroupDocs::Signature::Field) or raise ArgumentError, "Field should be GroupDocs::Signature::Field object, received: #{field.inspect}" document.is_a?(GroupDocs::Document) or raise ArgumentError, "Document should be GroupDocs::Document object, received: #{document.inspect}" field.location or raise ArgumentError, "You have to specify field location, received: #{field.location.inspect}" opts[:force_new_field] = true if opts[:force_new_field].nil? payload = field.to_hash # field itself payload.merge!(field.location.to_hash) # location should added in plain view (i.e. not "location": {...}) payload.merge!(:forceNewField => opts[:force_new_field]) # create new field flag Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/#{document.file.guid}/field/#{field.id}" request[:request_body] = payload end.execute! end |
#archive!(access = {}) ⇒ Object
Archives completed form.
253 254 255 256 257 258 259 |
# File 'lib/groupdocs/signature/form.rb', line 253 def archive!(access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/signature/{{client_id}}/forms/#{id}/archive" end.execute! end |
#complete!(access = {}) ⇒ Object
Completes form.
238 239 240 241 242 243 244 |
# File 'lib/groupdocs/signature/form.rb', line 238 def complete!(access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/signature/{{client_id}}/forms/#{id}/complete" end.execute! end |
#create!(options = {}, access = {}) ⇒ Object
Creates form.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/groupdocs/signature/form.rb', line 167 def create!( = {}, access = {}) #template_id = options.delete(:template_id) #assembly_id = options.delete(:assembly_id) #options[:templateId] = template_id if template_id #options[:assemblyId] = assembly_id if assembly_id api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = '/signature/{{client_id}}/form' request[:request_body] = to_hash end api.add_params(.merge(:name => name)) json = api.execute! self.id = json[:form][:id] end |
#documents!(options = {}, access = {}) ⇒ Array<GroupDocs::Document>
Returns documents array.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/groupdocs/signature/form.rb', line 197 def documents!( = {}, access = {}) client_id = client_id([:public]) json = Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/signature/#{client_id}/forms/#{id}/documents" end.execute! json[:documents].map do |document| id = document[:documentId] || document[:id] file = Storage::File.new(:guid => id, :name => document[:name]) Document.new(document.merge(:file => file)) end end |
#fields!(document, access = {}) ⇒ Object
Returns an array of fields for document per participant.
270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/groupdocs/signature/form.rb', line 270 def fields!(document, access = {}) document.is_a?(GroupDocs::Document) or raise ArgumentError, "Document should be GroupDocs::Document object, received: #{document.inspect}" json = Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/#{document.file.guid}/fields" end.execute! json[:fields].map do |field| Signature::Field.new(field) end end |
#fields_in_final_file_name ⇒ Array<String>
Converts field names to human-readable format.
147 148 149 |
# File 'lib/groupdocs/signature/form.rb', line 147 def fields_in_final_file_name @fieldsInFinalFileName.split(',') if @fieldsInFinalFileName end |
#fields_in_final_file_name=(fields) ⇒ Object
Converts array of field names to machine-readable format.
135 136 137 138 139 140 141 |
# File 'lib/groupdocs/signature/form.rb', line 135 def fields_in_final_file_name=(fields) if fields.is_a?(Array) fields = fields.join(',') end @fieldsInFinalFileName = fields end |
#modify_field_location!(location, field, document, recipient, access = {}) ⇒ Object
Modifies field location.
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/groupdocs/signature/form.rb', line 350 def modify_field_location!(location, field, document, recipient, access = {}) location.is_a?(GroupDocs::Signature::Field::Location) or raise ArgumentError, "Location should be GroupDocs::Signature::Field::Location object, received: #{location.inspect}" field.is_a?(GroupDocs::Signature::Field) or raise ArgumentError, "Field should be GroupDocs::Signature::Field object, received: #{field.inspect}" document.is_a?(GroupDocs::Document) or raise ArgumentError, "Document should be GroupDocs::Document object, received: #{document.inspect}" Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/#{document.file.guid}/fields/#{field.id}/locations/#{location.id}" request[:request_body] = location.to_hash end.execute! end |
#modify_form_document!(document, options = {}, access = {}) ⇒ Object
Modify signature form document
407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/groupdocs/signature/form.rb', line 407 def modify_form_document!(document, = {}, access = {}) document.is_a?(GroupDocs::Document) or raise ArgumentError, "Document should be GroupDocs::Document object, received: #{document.inspect}" Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/signature/{{client_id}}/forms/#{id}/document/#{document.file.guid}/" request[:request_body] = end.execute! end |
#publish!(callbackUrl = {}, access = {}) ⇒ Object
222 223 224 225 226 227 228 229 |
# File 'lib/groupdocs/signature/form.rb', line 222 def publish!(callbackUrl = {}, access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/signature/{{client_id}}/forms/#{id}/publish" request[:request_body] = callbackUrl end.execute! end |
#signed_documents!(path, access = {}) ⇒ String
Downloads signed documents to given path. If there is only one file in envelope, it’s saved as PDF. If there are two or more files in envelope, it’s saved as ZIP.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/groupdocs/signature/form.rb', line 430 def signed_documents!(path, access = {}) response = Api::Request.new do |request| request[:access] = access request[:method] = :DOWNLOAD request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/get" end.execute! filepath = "#{path}/#{name}." if documents!.size == 1 filepath << 'pdf' else filepath << 'zip' end Object::File.open(filepath, 'wb') do |file| file.write(response) end filepath end |
#update_from_template!(template, access = {}) ⇒ Object
Updates form adding fields from template.
375 376 377 378 379 380 381 382 383 384 |
# File 'lib/groupdocs/signature/form.rb', line 375 def update_from_template!(template, access = {}) template.is_a?(GroupDocs::Signature::Template) or raise ArgumentError, "Template should be GroupDocs::Signature::Template object, received: #{template.inspect}" Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/signature/{{client_id}}/forms/#{form.id}/templates/#{template.id}" end.execute! end |