Class: Ilovepdf::Task
Direct Known Subclasses
Ilovepdf::Tool::Compress, Ilovepdf::Tool::Extract, Ilovepdf::Tool::Imagepdf, Ilovepdf::Tool::Merge, Ilovepdf::Tool::Officepdf, Ilovepdf::Tool::Pagenumber, Ilovepdf::Tool::Pdfa, Ilovepdf::Tool::Pdfjpg, Ilovepdf::Tool::Protect, Ilovepdf::Tool::Repair, Ilovepdf::Tool::Rotate, Ilovepdf::Tool::Split, Ilovepdf::Tool::Unlock, Ilovepdf::Tool::ValidatePdfa, Ilovepdf::Tool::Watermark
Constant Summary collapse
- API_PARAMS =
[]
- DOWNLOAD_INFO =
[:output_filename, :output_file, :output_filetype]
Constants included from Ilovepdf
Instance Attribute Summary collapse
-
#ignore_errors ⇒ Object
Returns the value of attribute ignore_errors.
-
#ignore_password ⇒ Object
Returns the value of attribute ignore_password.
-
#output_filename ⇒ Object
Returns the value of attribute output_filename.
-
#packaged_filename ⇒ Object
Returns the value of attribute packaged_filename.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#task_id ⇒ Object
Returns the value of attribute task_id.
-
#tool ⇒ Object
Returns the value of attribute tool.
-
#try_pdf_repair ⇒ Object
Returns the value of attribute try_pdf_repair.
Instance Method Summary collapse
- #add_file(filepath) ⇒ Object
- #add_file_from_url(url) ⇒ Object
- #assign_meta_value(key, value) ⇒ Object
- #blob ⇒ Object
- #delete! ⇒ Object
- #delete_file(file) ⇒ Object
- #download(path = nil, create_directory: false) ⇒ Object
- #download_info ⇒ Object
- #enable_file_encryption(enable, new_encrypt_key = nil) ⇒ Object
- #execute ⇒ Object
- #files ⇒ Object
-
#initialize(public_key, secret_key) ⇒ Task
constructor
A new instance of Task.
-
#status ⇒ Object
- API Methods
-
Actions on task.
Methods included from Ilovepdf
Constructor Details
#initialize(public_key, secret_key) ⇒ Task
Returns a new instance of Task.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ilovepdf/task.rb', line 11 def initialize(public_key, secret_key) super(public_key, secret_key) response = perform_create_request self.worker_server = 'https://' + response.body['server'] self.task_id = response.body['task'] # Assign default values self.ignore_errors = true self.ignore_password = true self.try_pdf_repair = true end |
Instance Attribute Details
#ignore_errors ⇒ Object
Returns the value of attribute ignore_errors.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def ignore_errors @ignore_errors end |
#ignore_password ⇒ Object
Returns the value of attribute ignore_password.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def ignore_password @ignore_password end |
#output_filename ⇒ Object
Returns the value of attribute output_filename.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def output_filename @output_filename end |
#packaged_filename ⇒ Object
Returns the value of attribute packaged_filename.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def packaged_filename @packaged_filename end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/ilovepdf/task.rb', line 6 def result @result end |
#task_id ⇒ Object
Returns the value of attribute task_id.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def task_id @task_id end |
#tool ⇒ Object
Returns the value of attribute tool.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def tool @tool end |
#try_pdf_repair ⇒ Object
Returns the value of attribute try_pdf_repair.
3 4 5 |
# File 'lib/ilovepdf/task.rb', line 3 def try_pdf_repair @try_pdf_repair end |
Instance Method Details
#add_file(filepath) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ilovepdf/task.rb', line 31 def add_file(filepath) raise ArgumentError.new("No file exists in '#{filepath}'") unless ::File.exist?(filepath) file = perform_upload_request(filepath) files << file files.last end |
#add_file_from_url(url) ⇒ Object
38 39 40 41 42 |
# File 'lib/ilovepdf/task.rb', line 38 def add_file_from_url(url) file = perform_upload_url_request(url) files << file files.last end |
#assign_meta_value(key, value) ⇒ Object
23 24 25 |
# File 'lib/ilovepdf/task.rb', line 23 def (key, value) [key] = value end |
#blob ⇒ Object
60 61 62 63 |
# File 'lib/ilovepdf/task.rb', line 60 def blob download_file download_info.output_file end |
#delete! ⇒ Object
79 80 81 |
# File 'lib/ilovepdf/task.rb', line 79 def delete! send_request('delete', 'task/' + self.task_id) end |
#delete_file(file) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ilovepdf/task.rb', line 83 def delete_file(file) raise Error.new("File was already deleted") if file.deleted? file_was_found = files.find{|f| f.server_filename == file.server_filename } raise Error.new("File to delete not found") if !file_was_found response = perform_deletefile_request(file) if response.success? file.mark_as_deleted new_files = files.reject{|f| f.server_filename == file.server_filename } send(:files=, new_files) else raise ApiError.new(response, custom_msg: "No error ocurred but response was not successful when deleting the desired file") end true end |
#download(path = nil, create_directory: false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ilovepdf/task.rb', line 44 def download(path=nil, create_directory: false) download_file if path path = Pathname.new(path).to_s if path.is_a?(Pathname) path.chop! if path.end_with? '/' else path = '.' end destination = "#{path}/#{download_info.output_filename}" FileUtils.mkdir_p(path) if create_directory ::File.open(destination, 'wb'){|file| file.write(download_info.output_file) } true end |
#download_info ⇒ Object
65 66 67 |
# File 'lib/ilovepdf/task.rb', line 65 def download_info @download_info ||= Struct.new(*DOWNLOAD_INFO).new end |
#enable_file_encryption(enable, new_encrypt_key = nil) ⇒ Object
98 99 100 101 |
# File 'lib/ilovepdf/task.rb', line 98 def enable_file_encryption(enable, new_encrypt_key = nil) raise Error.new("Encryption mode cannot be assigned after uploading the files") if files.size > 0 super(enable, new_encrypt_key) end |
#execute ⇒ Object
75 76 77 |
# File 'lib/ilovepdf/task.rb', line 75 def execute @result = perform_process_request end |
#files ⇒ Object
27 28 29 |
# File 'lib/ilovepdf/task.rb', line 27 def files @files ||= [] end |
#status ⇒ Object
- API Methods
-
Actions on task
71 72 73 |
# File 'lib/ilovepdf/task.rb', line 71 def status http_response = query_task_status(worker_server,task_id) end |