ilovepdf 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab9733af9742fe03c368936f81761ca6578829d9
4
- data.tar.gz: b669af4fc8cabbdbcdfe4878ae410bc9193be00d
3
+ metadata.gz: 0211e131cc78ddb6b8820c6e0945ab437fb261ee
4
+ data.tar.gz: 06818cd4287dba2b14133892f1fce8d936ad650f
5
5
  SHA512:
6
- metadata.gz: 2ec1cbd5795ff1b5cbe7f7f47bb887254fb7ed543cfb0e97fd49c8ff360f76b0fc0a1cfd9d98ba6c19681120116259e71d51afe32558bac760eaae609dd9d854
7
- data.tar.gz: aa4ce004721604ac3fe6930ea5a1bace19bd327d60e317612ccf442a3476f3a14dc3e0d7fe0523accafc122cbff05dc4c3822bcafb91ecceb0c044733c1e75a9
6
+ metadata.gz: 8735a92025a4918ea8ab6dbbaa81242c0a3e00e699eabed76b044c544376e3d19f1378dd70bd1beda9a71638cd2286e67bd61ad98d55c735b18f41e189d9eac4
7
+ data.tar.gz: 181d5b26c2d02fcffd22f07b0035bf7c458696144d2f3a1375581717ba733411628c84d9682e345a6da1366dd21c07b0a540306e20a361ed14c241846463f88f
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  iLovePDF Api - Ruby Library
2
2
  --------------------------
3
+ [![Build Status](https://travis-ci.org/ilovepdf/ilovepdf-php.svg?branch=master)](https://travis-ci.org/ilovepdf/ilovepdf-php)
3
4
  [![GitHub version](https://badge.fury.io/gh/ilovepdf%2Filovepdf-ruby.svg)](https://badge.fury.io/gh/ilovepdf%2Filovepdf-ruby)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
6
 
@@ -22,6 +23,8 @@ Develop and automate PDF processing tasks like:
22
23
  * Stamp a Watermark
23
24
  * Repair PDF
24
25
  * PDF to PDF/A
26
+ * Validate PDF/A
27
+ * Extract
25
28
 
26
29
  Each one with several settings to get your desired results.
27
30
 
@@ -103,6 +106,15 @@ end
103
106
  | packaged_filename | This allows you to specify the filename of the compressed file in case there is more than 1 file to be downloaded | |
104
107
  | output_filename | The final name of the processed file | |
105
108
 
109
+ #### Methods to query after performing the **execute** API method:
110
+ * result: It has stored the last **Ilovepdf::Response**
111
+
112
+ #### Methods to query after performing the **download** API method:
113
+ * download_info: Returns a [struct](https://ruby-doc.org/core-2.2.0/Struct.html) with the following info
114
+ * :output_filename
115
+ * :output_file
116
+ * :output_filetype
117
+
106
118
  ### Tool attributes
107
119
 
108
120
  All tools have specific attributes you can access and modify.
@@ -9,6 +9,7 @@ require 'rest-client'
9
9
  # Base classes
10
10
  require "ilovepdf/errors"
11
11
  require "ilovepdf/response"
12
+ require "ilovepdf/helper"
12
13
  require "ilovepdf/ilovepdf"
13
14
  require "ilovepdf/file"
14
15
  require "ilovepdf/task"
@@ -20,12 +21,15 @@ require 'ilovepdf/tool/merge'
20
21
  require 'ilovepdf/tool/officepdf'
21
22
  require 'ilovepdf/tool/pagenumber'
22
23
  require 'ilovepdf/tool/pdfa'
24
+ require 'ilovepdf/tool/validate_pdfa'
23
25
  require 'ilovepdf/tool/pdfjpg'
24
26
  require 'ilovepdf/tool/repair'
25
27
  require 'ilovepdf/tool/rotate'
26
28
  require 'ilovepdf/tool/split'
27
29
  require 'ilovepdf/tool/unlock'
28
30
  require 'ilovepdf/tool/watermark'
31
+ require 'ilovepdf/tool/protect'
32
+ require 'ilovepdf/tool/extract'
29
33
 
30
34
  module Ilovepdf
31
35
  class << self
@@ -47,5 +47,7 @@ module Ilovepdf
47
47
  super("Provided argument is invalid. Valid values: #{valid_values.join(', ')}")
48
48
  end
49
49
  end
50
+ class UnsupportedFunctionalityError < ::Ilovepdf::Error
51
+ end
50
52
  end
51
53
  end
@@ -0,0 +1,13 @@
1
+ module Ilovepdf
2
+ module Helper
3
+ extend self
4
+
5
+ def underscore_str(str)
6
+ str.replace(str.scan(/[A-Z][a-z]*/).join("_").downcase)
7
+ end
8
+
9
+ def camelize_str(str)
10
+ str.split('_').map(&:capitalize).join
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  module Ilovepdf
2
2
  class Ilovepdf
3
- attr_accessor :api_version, :token, :encrypt_key ,:debug
3
+ attr_accessor :api_version, :token, :encrypt_key, :debug, :timeout, :long_timeout
4
4
 
5
5
  START_SERVER = 'https://api.ilovepdf.com'.freeze
6
6
  API_VERSION = 'v1'.freeze
@@ -13,10 +13,13 @@ module Ilovepdf
13
13
  def initialize(public_key=nil, secret_key=nil)
14
14
  set_api_keys(public_key, secret_key)
15
15
  api_version = API_VERSION
16
+ self.timeout = 10
17
+ self.long_timeout = nil
16
18
  end
17
19
 
18
20
  def new_task(tool_name)
19
- task_klass = ::Ilovepdf::Tool.const_get(tool_name.to_s.capitalize) rescue false
21
+ camelized_name = Helper.camelize_str(tool_name.to_s)
22
+ task_klass = ::Ilovepdf::Tool.const_get(camelized_name) rescue false
20
23
  unless task_klass
21
24
  raise ::Ilovepdf::Error.new("Unknown tool '#{tool_name}'. Available tools: #{self.class.all_tool_names.to_s}")
22
25
  end
@@ -24,7 +27,7 @@ module Ilovepdf
24
27
  end
25
28
 
26
29
  def self.all_tool_names
27
- ::Ilovepdf::Tool.constants.map(&:downcase)
30
+ ::Ilovepdf::Tool.constants.map{|tool_name| Helper.underscore_str(tool_name.to_s)}
28
31
  end
29
32
 
30
33
  def self.raise_exceptions=(value)
@@ -62,7 +65,7 @@ module Ilovepdf
62
65
  def send_request(http_method, endpoint, extra_opts={})
63
66
  to_server = worker_server ? worker_server : START_SERVER
64
67
 
65
- timeout_to_use = LONG_JOB_ENDPOINTS.include?(endpoint.to_sym) ? nil : 10
68
+ timeout_to_use = LONG_JOB_ENDPOINTS.include?(endpoint.to_sym) ? self.long_timeout : self.timeout
66
69
  extra_opts[:body] ||= {}
67
70
  extra_opts[:headers] ||= {}
68
71
 
@@ -3,7 +3,10 @@ module Ilovepdf
3
3
  attr_accessor :task_id, :tool, :packaged_filename, :output_filename,
4
4
  :ignore_errors, :ignore_password, :try_pdf_repair
5
5
 
6
- API_PARAMS = []
6
+ attr_reader :result
7
+
8
+ API_PARAMS = []
9
+ DOWNLOAD_INFO = [:output_filename, :output_file, :output_filetype]
7
10
 
8
11
  def initialize(public_key, secret_key)
9
12
  super(public_key, secret_key)
@@ -38,8 +41,29 @@ module Ilovepdf
38
41
  files.last
39
42
  end
40
43
 
41
- def download(path=nil)
42
- download_file(path)
44
+ def download(path=nil, create_directory: false)
45
+ download_file
46
+
47
+ if path
48
+ path = Pathname.new(path).to_s if path.is_a?(Pathname)
49
+ path.chop! if path.end_with? '/'
50
+ else
51
+ path = '.'
52
+ end
53
+
54
+ destination = "#{path}/#{download_info.output_filename}"
55
+ FileUtils.mkdir_p(path) if create_directory
56
+ ::File.open(destination, 'wb'){|file| file.write(download_info.output_file) }
57
+ true
58
+ end
59
+
60
+ def blob
61
+ download_file
62
+ download_info.output_file
63
+ end
64
+
65
+ def download_info
66
+ @download_info ||= Struct.new(*DOWNLOAD_INFO).new
43
67
  end
44
68
 
45
69
  # [API Methods] Actions on task
@@ -49,7 +73,7 @@ module Ilovepdf
49
73
  end
50
74
 
51
75
  def execute
52
- perform_process_request
76
+ @result = perform_process_request
53
77
  end
54
78
 
55
79
  def delete!
@@ -87,7 +111,7 @@ module Ilovepdf
87
111
  @files = new_array_of_files
88
112
  end
89
113
 
90
- def download_file path
114
+ def download_file
91
115
  response = perform_filedownload_request
92
116
  content_disposition = response.headers[:content_disposition]
93
117
 
@@ -98,15 +122,9 @@ module Ilovepdf
98
122
  filename = match_data[1].gsub('"', '')
99
123
  end
100
124
 
101
- if path
102
- path = Pathname.new(path).to_s if path.is_a?(Pathname)
103
- path.chop! if path.end_with? '/'
104
- else
105
- path = '.'
106
- end
107
- destination = "#{path}/#{filename}"
108
- ::File.open(destination, 'wb'){|file| file.write(response.raw_body) }
109
- file = response.raw_body
125
+ download_info.output_filename = filename
126
+ download_info.output_file = response.raw_body
127
+ download_info.output_filetype = ::File.extname(filename)
110
128
  true
111
129
  end
112
130
 
@@ -0,0 +1,18 @@
1
+ module Ilovepdf
2
+ module Tool
3
+ class Extract < ::Ilovepdf::Task
4
+ API_PARAMS = [:detailed]
5
+ attr_accessor *API_PARAMS
6
+
7
+ def initialize(public_key, secret_key)
8
+ self.tool = :extract
9
+ super(public_key, secret_key)
10
+ end
11
+
12
+ def detailed
13
+ @detailed ||= false
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -9,8 +9,8 @@ module Ilovepdf
9
9
 
10
10
  attr_accessor *API_PARAMS
11
11
 
12
- VERTICAL_POSITION_VALUES = ['bottom', 'top']
13
- HORIZONTAL_POSITION_VALUES = ['left', 'middle', 'right']
12
+ VERTICAL_POSITION_VALUES = ['bottom', 'middle' ,'top']
13
+ HORIZONTAL_POSITION_VALUES = ['left', 'center', 'right']
14
14
  FONT_FAMILY_VALUES = [ 'Arial', 'Arial Unicode MS', 'Verdana', 'Courier',
15
15
  'Times New Roman', 'Comic Sans MS',
16
16
  'WenQuanYi Zen Hei', 'Lohit Marathi'
@@ -1,7 +1,7 @@
1
1
  module Ilovepdf
2
2
  module Tool
3
3
  class Pdfa < ::Ilovepdf::Task
4
- API_PARAMS = [:conformance]
4
+ API_PARAMS = [:conformance, :allow_downgrade]
5
5
  attr_accessor *API_PARAMS
6
6
 
7
7
  CONFORMANCE_VALUES = ['pdfa-1b', 'pdfa-1a', 'pdfa-2b', 'pdfa-2u',
@@ -11,6 +11,7 @@ module Ilovepdf
11
11
  def initialize(public_key, secret_key)
12
12
  self.tool = :pdfa
13
13
  super(public_key, secret_key)
14
+ self.allow_downgrade = true
14
15
  end
15
16
 
16
17
  def conformance= new_val
@@ -19,7 +20,7 @@ module Ilovepdf
19
20
  end
20
21
 
21
22
  def conformance
22
- @conformance ||= 'default'
23
+ @conformance ||= 'pdfa-2b'
23
24
  end
24
25
  end
25
26
  end
@@ -0,0 +1,31 @@
1
+ module Ilovepdf
2
+ module Tool
3
+ class ValidatePdfa < ::Ilovepdf::Task
4
+ API_PARAMS = [:conformance]
5
+ attr_accessor *API_PARAMS
6
+
7
+ CONFORMANCE_VALUES = ['pdfa-1b', 'pdfa-1a', 'pdfa-2b', 'pdfa-2u',
8
+ 'pdfa-2a', 'pdfa-3b', 'pdfa-3u', 'pdfa-3a'
9
+ ]
10
+
11
+ def initialize(public_key, secret_key)
12
+ self.tool = :validatepdfa
13
+ super(public_key, secret_key)
14
+ end
15
+
16
+ def conformance= new_val
17
+ raise Errors::ArgumentEnumError.new(CONFORMANCE_VALUES) unless CONFORMANCE_VALUES.include? new_val
18
+ @conformance = new_val
19
+ end
20
+
21
+ def conformance
22
+ @conformance ||= 'pdfa-2b'
23
+ end
24
+
25
+ private
26
+ def download_file
27
+ raise ::Ilovepdf::Errors::UnsupportedFunctionalityError.new('This tool does not download files (Check in the sample files how to use it)')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Ilovepdf
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Extract.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # By setting this parameter to true,
11
+ # we'll have detailed contents extraction into a CSV-formatted file
12
+ my_task.detailed = true
13
+
14
+ # and set name for output file.
15
+ # the task will set the correct file extension for you.
16
+ my_task.output_filename = 'csv_filename'
17
+
18
+ # Process files
19
+ response = my_task.execute
20
+
21
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
22
+ # It will download a text file with Linux line endings
23
+ my_task.download
@@ -0,0 +1,15 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Extract.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # Process files
11
+ response = my_task.execute
12
+
13
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
14
+ # It will download a text file with Linux line endings
15
+ my_task.download
@@ -0,0 +1,25 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Imagepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/photo.png'
9
+ file2 = my_task.add_file '/path/to/file/image.tiff'
10
+
11
+ # Merge After: Default is true. If it is false then it will download a zip file with a pdf for each image
12
+ my_task.merge_after = false
13
+
14
+ # and set name for output file.
15
+ # the task will set the correct file extension for you.
16
+ my_task.output_filename = 'pdf_filename'
17
+
18
+ # and name for splitted document (inside the zip file)
19
+ my_task.packaged_filename = 'zip_filename'
20
+
21
+ # Process files
22
+ response = my_task.execute
23
+
24
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
25
+ my_task.download
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Imagepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/photo.png'
9
+
10
+ # Process files
11
+ response = my_task.execute
12
+
13
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
14
+ my_task.download
@@ -8,7 +8,10 @@ my_task = Ilovepdf::Tool::Pdfa.new("PUBLIC_KEY", "SECRET_KEY");
8
8
  file = my_task.add_file '/path/to/file/document.pdf'
9
9
 
10
10
  # Set conformance
11
- file.conformance = 'pdfa-1b'
11
+ my_task.conformance = 'pdfa-2a'
12
+
13
+ # don't allow downgrading in case your conformance level fails
14
+ file.allow_downgrade = false
12
15
 
13
16
  # and set name for output file.
14
17
  # the task will set the correct file extension for you.
@@ -7,9 +7,6 @@ my_task = Ilovepdf::Tool::Pdfa.new("PUBLIC_KEY", "SECRET_KEY");
7
7
  # File object keeps information about its server_filename and the properties you can set
8
8
  file = my_task.add_file '/path/to/file/document.pdf'
9
9
 
10
- # Set conformance
11
- file.conformance = 'pdfa-1b'
12
-
13
10
  # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
14
11
  response = my_task.execute
15
12
 
@@ -0,0 +1,18 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::ValidatePdfa.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ file.conformance = 'pdfa-2a'
11
+
12
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
13
+ response = my_task.execute
14
+
15
+ response.body['validations'].each do |results|
16
+ file = my_task.files.find{|file| file.server_filename == results['server_filename']}
17
+ puts "File with name '#{file.filename}' has the following status: #{results['status']}"
18
+ end
@@ -0,0 +1,16 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::ValidatePdfa.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
11
+ response = my_task.execute
12
+
13
+ response.body['validations'].each do |results|
14
+ file = my_task.files.find{|file| file.server_filename == results['server_filename']}
15
+ puts "File with name '#{file.filename}' has the following status: #{results['status']}"
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ilovepdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Collazo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -146,10 +146,12 @@ files:
146
146
  - lib/ilovepdf.rb
147
147
  - lib/ilovepdf/errors.rb
148
148
  - lib/ilovepdf/file.rb
149
+ - lib/ilovepdf/helper.rb
149
150
  - lib/ilovepdf/ilovepdf.rb
150
151
  - lib/ilovepdf/response.rb
151
152
  - lib/ilovepdf/task.rb
152
153
  - lib/ilovepdf/tool/compress.rb
154
+ - lib/ilovepdf/tool/extract.rb
153
155
  - lib/ilovepdf/tool/imagepdf.rb
154
156
  - lib/ilovepdf/tool/merge.rb
155
157
  - lib/ilovepdf/tool/officepdf.rb
@@ -161,10 +163,15 @@ files:
161
163
  - lib/ilovepdf/tool/rotate.rb
162
164
  - lib/ilovepdf/tool/split.rb
163
165
  - lib/ilovepdf/tool/unlock.rb
166
+ - lib/ilovepdf/tool/validate_pdfa.rb
164
167
  - lib/ilovepdf/tool/watermark.rb
165
168
  - lib/ilovepdf/version.rb
166
169
  - samples/compress_advanced.rb
167
170
  - samples/compress_basic.rb
171
+ - samples/extract_advanced.rb
172
+ - samples/extract_basic.rb
173
+ - samples/imagepdf_advanced.rb
174
+ - samples/imagepdf_basic.rb
168
175
  - samples/merge_advanced.rb
169
176
  - samples/merge_basic.rb
170
177
  - samples/pdfa_advanced.rb
@@ -179,6 +186,8 @@ files:
179
186
  - samples/try_catch_errors.rb
180
187
  - samples/unlock_advanced.rb
181
188
  - samples/unlock_basic.rb
189
+ - samples/validatepdfa_advanced.rb
190
+ - samples/validatepdfa_basic.rb
182
191
  - samples/watermark_advanced.rb
183
192
  - samples/watermark_basic.rb
184
193
  - uploads/sample_pdf.pdf