ilovepdf 1.3.1 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +1 -1
- data/LICENSE +0 -0
- data/README.md +21 -1
- data/ilovepdf.gemspec +4 -3
- data/lib/ilovepdf/element.rb +79 -0
- data/lib/ilovepdf/errors.rb +8 -1
- data/lib/ilovepdf/file.rb +1 -1
- data/lib/ilovepdf/ilovepdf.rb +9 -5
- data/lib/ilovepdf/refinements.rb +30 -0
- data/lib/ilovepdf/request_payload/form_url_encoded.rb +54 -0
- data/lib/ilovepdf/servers.rb +7 -0
- data/lib/ilovepdf/signature/date_element.rb +16 -0
- data/lib/ilovepdf/signature/file_element.rb +60 -0
- data/lib/ilovepdf/signature/initials_element.rb +11 -0
- data/lib/ilovepdf/signature/input_element.rb +27 -0
- data/lib/ilovepdf/signature/management.rb +103 -0
- data/lib/ilovepdf/signature/name_element.rb +11 -0
- data/lib/ilovepdf/signature/receiver.rb +87 -0
- data/lib/ilovepdf/signature/signature_element.rb +11 -0
- data/lib/ilovepdf/signature/text_element.rb +17 -0
- data/lib/ilovepdf/signature.rb +5 -0
- data/lib/ilovepdf/signature_file.rb +10 -0
- data/lib/ilovepdf/task.rb +60 -15
- data/lib/ilovepdf/tool/compress.rb +2 -2
- data/lib/ilovepdf/tool/extract.rb +2 -2
- data/lib/ilovepdf/tool/imagepdf.rb +2 -2
- data/lib/ilovepdf/tool/merge.rb +2 -2
- data/lib/ilovepdf/tool/officepdf.rb +2 -2
- data/lib/ilovepdf/tool/pagenumber.rb +2 -2
- data/lib/ilovepdf/tool/pdfa.rb +2 -2
- data/lib/ilovepdf/tool/pdfjpg.rb +31 -9
- data/lib/ilovepdf/tool/protect.rb +2 -2
- data/lib/ilovepdf/tool/repair.rb +2 -2
- data/lib/ilovepdf/tool/rotate.rb +2 -2
- data/lib/ilovepdf/tool/signature.rb +134 -0
- data/lib/ilovepdf/tool/split.rb +2 -2
- data/lib/ilovepdf/tool/unlock.rb +2 -2
- data/lib/ilovepdf/tool/validate_pdfa.rb +2 -2
- data/lib/ilovepdf/tool/watermark.rb +33 -15
- data/lib/ilovepdf/version.rb +1 -1
- data/lib/ilovepdf.rb +19 -0
- data/samples/chained_task.rb +20 -0
- data/samples/signature_advanced.rb +74 -0
- data/samples/signature_basic.rb +21 -0
- data/samples/signature_management.rb +42 -0
- data/uploads/sample_pdf.pdf +0 -0
- metadata +40 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed633b60a4ee0aaa209849e234cadd731bdf40ea64f89738d5ad12599cde9e91
|
4
|
+
data.tar.gz: 0b19f9d1d76b024cb9e382a9cf96fc72e2d94cd92512613ff8b92e850839627f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f71245b644289f6e59dcf55cf6c8ac25e218191ee745e0f640c0f8e866d5f70a9ff245c4acd83861fd2a8eb202a198e99a48cac42afceda529c1c96e440f1221
|
7
|
+
data.tar.gz: 2887db879e62bd3d7f04ee8db462d3df9ea978f0ba187e4bb77f9d0a161fc5df0c048b45b987f75c9633a955bd4527a0b3a6c044976be88347f725604c57c16a
|
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -25,11 +25,12 @@ Develop and automate PDF processing tasks like:
|
|
25
25
|
* PDF to PDF/A
|
26
26
|
* Validate PDF/A
|
27
27
|
* Extract
|
28
|
+
* Sign PDF
|
28
29
|
|
29
30
|
Each one with several settings to get your desired results.
|
30
31
|
|
31
32
|
## Requirements
|
32
|
-
Ruby 2.
|
33
|
+
Ruby 2.6 or greater
|
33
34
|
|
34
35
|
## Installation
|
35
36
|
|
@@ -71,6 +72,25 @@ That's it!
|
|
71
72
|
|
72
73
|
For a more in-depth usage, refer to the [sample codes](https://github.com/ilovepdf/ilovepdf-ruby/tree/master/samples) in this repository.
|
73
74
|
|
75
|
+
## Signature Tool
|
76
|
+
The usage of this tool is different than the other tools, the following example shows how to create a signature using the iLovePDF API:
|
77
|
+
```ruby
|
78
|
+
my_task = Ilovepdf::Tool::Signature.new(pub_key, priv_key)
|
79
|
+
# File object keeps information about its server_filename and the properties you can set
|
80
|
+
file = my_task.add_file '/path/to/file/sample.pdf'
|
81
|
+
|
82
|
+
signer = Ilovepdf::Signature::Receiver.new(:signer,'name','email@email.com')
|
83
|
+
|
84
|
+
signature_element = Ilovepdf::Signature::SignatureElement.new(file)
|
85
|
+
signature_element.set_position(x: 20, y: -20)
|
86
|
+
signature_element.pages = "1"
|
87
|
+
signature_element.size = 40
|
88
|
+
|
89
|
+
signer << signature_element
|
90
|
+
body = my_task.send_to_sign.body
|
91
|
+
```
|
92
|
+
For a more in-depth usage, refer to all of the signature examples on the [sample codes](https://github.com/ilovepdf/ilovepdf-ruby/tree/master/samples) in this repository.
|
93
|
+
|
74
94
|
## Documentation
|
75
95
|
### HTTP API Calls
|
76
96
|
All PDF tools have the following methods that contact with the iLovePDF API:
|
data/ilovepdf.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'ilovepdf/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ilovepdf"
|
8
8
|
spec.version = Ilovepdf::VERSION
|
9
|
-
spec.authors = ["Leonardo Collazo"]
|
10
|
-
spec.email = ["leonardo.chronicles@gmail.com"]
|
9
|
+
spec.authors = ["Leonardo Collazo", "Guillem Vidal"]
|
10
|
+
spec.email = ["leonardo.chronicles@gmail.com", "g.vidal.cantavella@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A library in Ruby for iLovePDF Api}
|
13
13
|
spec.description = %q{Develop and automate PDF processing tasks like Compress PDF, Merge PDF, Split PDF, convert Office to PDF, PDF to JPG, Images to PDF, add Page Numbers, Rotate PDF, Unlock PDF, stamp a Watermark and Repair PDF. Each one with several settings to get your desired results.}
|
@@ -20,10 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.bindir = "exe"
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
|
-
spec.required_ruby_version = '>= 2.
|
23
|
+
spec.required_ruby_version = '>= 2.6'
|
24
24
|
|
25
25
|
spec.add_runtime_dependency 'rest-client', '~> 2'
|
26
26
|
spec.add_runtime_dependency 'jwt', '~> 2'
|
27
|
+
spec.add_runtime_dependency 'json', '~> 2'
|
27
28
|
|
28
29
|
|
29
30
|
spec.add_development_dependency "bundler", ">= 1.16"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
class Element
|
3
|
+
FONT_FAMILY_VALUES = ['Arial', 'Arial Unicode MS', 'Verdana', 'Courier',
|
4
|
+
'Times New Roman', 'Comic Sans MS', 'WenQuanYi Zen Hei',
|
5
|
+
'Lohit Marathi'
|
6
|
+
]
|
7
|
+
|
8
|
+
VERTICAL_POSITION_VALUES = ['bottom', 'middle' ,'top']
|
9
|
+
HORIZONTAL_POSITION_VALUES = ['left', 'center', 'right']
|
10
|
+
|
11
|
+
LAYER_VALUES = ['above', 'below']
|
12
|
+
|
13
|
+
ATTR_DEFAULT_VALUES = {
|
14
|
+
type: 'text',
|
15
|
+
mode: 'text',
|
16
|
+
text: nil,
|
17
|
+
image: nil,
|
18
|
+
pages: 'all',
|
19
|
+
vertical_position: 'middle',
|
20
|
+
horizontal_position: 'center',
|
21
|
+
vertical_adjustment: 0,
|
22
|
+
horizontal_adjustment: 0,
|
23
|
+
rotation: 0,
|
24
|
+
transparency: 100,
|
25
|
+
mosaic: false,
|
26
|
+
font_family: nil,
|
27
|
+
font_style: 'Regular',
|
28
|
+
font_color: '#000000',
|
29
|
+
font_size: 14,
|
30
|
+
image_resize: 1,
|
31
|
+
zoom: 1,
|
32
|
+
gravity: 'center',
|
33
|
+
border: nil,
|
34
|
+
layer: nil,
|
35
|
+
bold: false,
|
36
|
+
server_filename: nil
|
37
|
+
}
|
38
|
+
|
39
|
+
attr_accessor *ATTR_DEFAULT_VALUES.keys
|
40
|
+
|
41
|
+
def initialize(params={})
|
42
|
+
init_values = ATTR_DEFAULT_VALUES.merge(params)
|
43
|
+
init_values.delete_if{|k, v| v.nil? }
|
44
|
+
init_values.each_pair do |k, v|
|
45
|
+
public_send(:"#{k}=", v)
|
46
|
+
end # /each_pair
|
47
|
+
end # /initialize
|
48
|
+
|
49
|
+
def font_family=(new_val)
|
50
|
+
raise Errors::ArgumentEnumError.new(FONT_FAMILY_VALUES) unless FONT_FAMILY_VALUES.include? new_val
|
51
|
+
@font_family = new_val
|
52
|
+
end
|
53
|
+
|
54
|
+
def layer=(new_val)
|
55
|
+
raise Errors::ArgumentEnumError.new(LAYER_VALUES) unless LAYER_VALUES.include? new_val
|
56
|
+
@layer = new_val
|
57
|
+
end
|
58
|
+
|
59
|
+
def vertical_position=(new_val)
|
60
|
+
raise Errors::ArgumentEnumError.new(VERTICAL_POSITION_VALUES) unless VERTICAL_POSITION_VALUES.include? new_val
|
61
|
+
@vertical_position = new_val
|
62
|
+
end
|
63
|
+
|
64
|
+
def horizontal_position=(new_val)
|
65
|
+
raise Errors::ArgumentEnumError.new(HORIZONTAL_POSITION_VALUES) unless HORIZONTAL_POSITION_VALUES.include? new_val
|
66
|
+
@horizontal_position = new_val
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_api_hash
|
70
|
+
export_hash = {}
|
71
|
+
ATTR_DEFAULT_VALUES.keys.each do |k|
|
72
|
+
val = send(k)
|
73
|
+
export_hash[k] = val if !val.nil?
|
74
|
+
end
|
75
|
+
export_hash
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
data/lib/ilovepdf/errors.rb
CHANGED
@@ -40,9 +40,16 @@ module Ilovepdf
|
|
40
40
|
end
|
41
41
|
class UploadError < ::Ilovepdf::ApiError
|
42
42
|
end
|
43
|
+
class DownloadError < ::Ilovepdf::ApiError
|
44
|
+
end
|
45
|
+
class StartError < ::Ilovepdf::ApiError
|
46
|
+
end
|
43
47
|
|
44
48
|
# Library errors
|
45
|
-
class
|
49
|
+
class ArgumentError < ::ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
class ArgumentEnumError < ArgumentError
|
46
53
|
def initialize(valid_values)
|
47
54
|
super("Provided argument is invalid. Valid values: #{valid_values.join(', ')}")
|
48
55
|
end
|
data/lib/ilovepdf/file.rb
CHANGED
data/lib/ilovepdf/ilovepdf.rb
CHANGED
@@ -2,7 +2,7 @@ module Ilovepdf
|
|
2
2
|
class Ilovepdf
|
3
3
|
attr_accessor :api_version, :token, :encrypt_key, :debug, :timeout, :long_timeout
|
4
4
|
|
5
|
-
START_SERVER =
|
5
|
+
START_SERVER = Servers::START_SERVER
|
6
6
|
API_VERSION = 'ruby.v1'.freeze
|
7
7
|
TOKEN_ALGORITHM = 'HS256'.freeze
|
8
8
|
ALL_ENDPOINTS = [:start, :upload, :process, :download, :task].freeze
|
@@ -17,13 +17,13 @@ module Ilovepdf
|
|
17
17
|
self.long_timeout = nil
|
18
18
|
end
|
19
19
|
|
20
|
-
def new_task(tool_name)
|
20
|
+
def new_task(tool_name, make_start = true)
|
21
21
|
camelized_name = Helper.camelize_str(tool_name.to_s)
|
22
22
|
task_klass = ::Ilovepdf::Tool.const_get(camelized_name) rescue false
|
23
23
|
unless task_klass
|
24
24
|
raise ::Ilovepdf::Error.new("Unknown tool '#{tool_name}'. Available tools: #{self.class.all_tool_names.to_s}")
|
25
25
|
end
|
26
|
-
task_klass.new(@public_key, @secret_key)
|
26
|
+
task_klass.new(@public_key, @secret_key, make_start)
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.all_tool_names
|
@@ -64,7 +64,6 @@ module Ilovepdf
|
|
64
64
|
|
65
65
|
def send_request(http_method, endpoint, extra_opts={})
|
66
66
|
to_server = worker_server ? worker_server : START_SERVER
|
67
|
-
|
68
67
|
timeout_to_use = LONG_JOB_ENDPOINTS.include?(endpoint.to_sym) ? self.long_timeout : self.timeout
|
69
68
|
extra_opts[:body] ||= {}
|
70
69
|
extra_opts[:headers] ||= {}
|
@@ -77,6 +76,7 @@ module Ilovepdf
|
|
77
76
|
extra_opts[:body][:debug] = true if self.debug
|
78
77
|
|
79
78
|
request_uri = to_server + "/v1/#{endpoint}"
|
79
|
+
|
80
80
|
begin
|
81
81
|
rest_response = RestClient::Request.execute( method: http_method.to_sym, url: request_uri, timeout: timeout_to_use,
|
82
82
|
headers: extra_opts[:headers], payload: extra_opts[:body]
|
@@ -96,7 +96,11 @@ module Ilovepdf
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def klass_error_for(endpoint)
|
99
|
-
|
99
|
+
endpoint_base = /^([^\/\?]+)\/?/.match(endpoint)
|
100
|
+
if endpoint_base
|
101
|
+
endpoint_base = endpoint_base[1]
|
102
|
+
error_klass = ::Ilovepdf::Errors.const_get("#{endpoint_base.to_s.capitalize}Error") rescue false
|
103
|
+
end
|
100
104
|
error_klass = ::Ilovepdf::ApiError if !error_klass # use generic ApiError
|
101
105
|
error_klass
|
102
106
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module Refinements
|
3
|
+
module Crush
|
4
|
+
refine Object do
|
5
|
+
def crush
|
6
|
+
self
|
7
|
+
end
|
8
|
+
end
|
9
|
+
refine Array do
|
10
|
+
def crush
|
11
|
+
r = map(&:crush).compact
|
12
|
+
|
13
|
+
r.empty? ? nil : r
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
refine Hash do
|
18
|
+
def crush
|
19
|
+
r = each_with_object({ }) do |(k, v), h|
|
20
|
+
if (_v = v.crush)
|
21
|
+
h[k] = _v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
r.empty? ? nil : r
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module RequestPayload
|
3
|
+
class FormUrlEncoded
|
4
|
+
def initialize(body)
|
5
|
+
raise ArgumentError.new("Body must be a hash") unless body.is_a?(Hash)
|
6
|
+
@body = body
|
7
|
+
end
|
8
|
+
|
9
|
+
def mime_type
|
10
|
+
'application/x-www-form-urlencoded'
|
11
|
+
end
|
12
|
+
|
13
|
+
def extract_to_s
|
14
|
+
components = []
|
15
|
+
|
16
|
+
@body.each do |key, value|
|
17
|
+
resolved_val = stringify_into_form_format(key, value)
|
18
|
+
components << resolved_val if !resolved_val.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
components.join("&")
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def stringify_into_form_format(key, value)
|
27
|
+
components = []
|
28
|
+
|
29
|
+
if value.is_a?(Hash)
|
30
|
+
return nil if value.empty?
|
31
|
+
value.each do|hk, hv|
|
32
|
+
prop_name = URI.encode_www_form_component(hk)
|
33
|
+
resolved_val = stringify_into_form_format("#{key}[#{prop_name}]", hv)
|
34
|
+
components << resolved_val
|
35
|
+
end
|
36
|
+
elsif value.is_a?(Array)
|
37
|
+
return nil if value.empty?
|
38
|
+
value.each_with_index do |array_item, idx|
|
39
|
+
resolved_val = stringify_into_form_format("#{key}[#{idx}]", array_item)
|
40
|
+
next if resolved_val.nil?
|
41
|
+
components << resolved_val
|
42
|
+
end
|
43
|
+
else
|
44
|
+
return nil if value.nil?
|
45
|
+
resolved_val = "#{key}=" + URI.encode_www_form_component(value)
|
46
|
+
components << resolved_val
|
47
|
+
end
|
48
|
+
|
49
|
+
components.join("&")
|
50
|
+
end
|
51
|
+
|
52
|
+
end # /UrlEncoded class
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module Signature
|
3
|
+
class DateElement
|
4
|
+
include FileElement
|
5
|
+
def initialize(file)
|
6
|
+
super(file)
|
7
|
+
@type = :date
|
8
|
+
end
|
9
|
+
|
10
|
+
def date_format=(value)
|
11
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("value must be a String type of object") unless value.is_a?(String)
|
12
|
+
@content = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module Signature
|
3
|
+
module FileElement
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:include,InstanceMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
attr_reader :file,:position,:pages,:size,:info,:type,:content
|
10
|
+
def initialize(file)
|
11
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only Ilovepdf::File type of object is allowed") unless file.class.name == "Ilovepdf::File"
|
12
|
+
@file = file
|
13
|
+
@position = "0 0"
|
14
|
+
@pages = "1"
|
15
|
+
@size = 40
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_position(x: 0,y: 0)
|
19
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("x must be an integer or float") unless x.is_a?(Integer) || x.is_a?(Float)
|
20
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("y must be an integer or float") unless y.is_a?(Integer) || y.is_a?(Float)
|
21
|
+
@position = "#{x.abs} #{-y.abs}"
|
22
|
+
position
|
23
|
+
end
|
24
|
+
|
25
|
+
def pages=(value)
|
26
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("value must be string type") unless value.is_a?(String)
|
27
|
+
@pages = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def size=(value)
|
31
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("value must be Integer type") unless value.is_a?(Integer)
|
32
|
+
@size = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_h
|
36
|
+
{
|
37
|
+
position: position,
|
38
|
+
pages: pages,
|
39
|
+
size: size,
|
40
|
+
info: info,
|
41
|
+
type: type,
|
42
|
+
content: content
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def info
|
47
|
+
@info && @info.to_json
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def set_info_parameter(parameter_name,value)
|
53
|
+
@info ||= {}
|
54
|
+
@info[parameter_name] = value
|
55
|
+
@info
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module Signature
|
3
|
+
class InputElement
|
4
|
+
include FileElement
|
5
|
+
def initialize(file, label,description = nil)
|
6
|
+
super(file)
|
7
|
+
self.label=label
|
8
|
+
self.description=description
|
9
|
+
@type = :input
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_info(label: "", description:)
|
13
|
+
@info = {}.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def label=(value)
|
17
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("value must be a String type of object") unless value.is_a?(String)
|
18
|
+
self.set_info_parameter(:label,value)
|
19
|
+
end
|
20
|
+
|
21
|
+
def description=(value)
|
22
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("value must be a String type of object") unless value.is_a?(String)
|
23
|
+
self.set_info_parameter(:description,value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module Signature
|
3
|
+
class Management < ::Ilovepdf::Task
|
4
|
+
|
5
|
+
def initialize(public_key, secret_key, make_start=false)
|
6
|
+
self.tool = :sign
|
7
|
+
super(public_key, secret_key, make_start)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_status(signature_token)
|
11
|
+
send_request("get", "signature/requesterview/#{signature_token}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def list_signatures(current_page: 0,per_page: 20)
|
15
|
+
send_request("get", "signature/list", body: {page: current_page,per_page: per_page})
|
16
|
+
end
|
17
|
+
|
18
|
+
def download_audit(signature_token, directory = __dir__,create_directory: true,filename:)
|
19
|
+
download_file("signature/#{signature_token}/download-audit",directory,create_directory: create_directory, filename: filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
def download_original(signature_token, directory = __dir__,create_directory: true,filename:)
|
23
|
+
download_file("signature/#{signature_token}/download-original",directory,create_directory: create_directory, filename: filename)
|
24
|
+
end
|
25
|
+
|
26
|
+
def download_signed(signature_token, directory = __dir__,create_directory: true,filename:)
|
27
|
+
download_file("signature/#{signature_token}/download-signed",directory,create_directory: create_directory, filename: filename)
|
28
|
+
end
|
29
|
+
|
30
|
+
def send_reminders(signature_token)
|
31
|
+
send_request("post","signature/sendReminder/#{signature_token}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def void_signature(signature_token)
|
35
|
+
send_request("put","signature/void/#{signature_token}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def increase_expiration_days(signature_token,days_to_increase)
|
39
|
+
body = {days: days_to_increase}
|
40
|
+
extracted_body = RequestPayload::FormUrlEncoded.new(body).extract_to_s
|
41
|
+
send_request("put","signature/increase-expiration-days/#{signature_token}", body: extracted_body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_receiver_info(signer_token)
|
45
|
+
send_request("get", "signature/receiver/info/#{signer_token}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def fix_receiver_email(signer_token, new_email)
|
49
|
+
body = {email: new_email}
|
50
|
+
extracted_body = RequestPayload::FormUrlEncoded.new(body).extract_to_s
|
51
|
+
send_request("put","signature/receiver/fix-email/#{signer_token}", body: extracted_body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def fix_receiver_phone(signer_token, new_phone)
|
55
|
+
body = {phone: new_phone}
|
56
|
+
extracted_body = RequestPayload::FormUrlEncoded.new(body).extract_to_s
|
57
|
+
send_request("put","signature/receiver/fix-phone/#{signer_token}", body: extracted_body)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def download_file(url,directory,create_directory: true,filename:)
|
63
|
+
if self.worker_server.nil?
|
64
|
+
response = perform_start_request
|
65
|
+
self.worker_server = "#{Servers::PROTOCOL}://" + response.body['server']
|
66
|
+
end
|
67
|
+
|
68
|
+
response = send_request("get",url)
|
69
|
+
content_disposition = response.headers[:content_disposition]
|
70
|
+
filename_to_set = ::File.basename(filename,::File.extname(filename)) unless filename.nil?
|
71
|
+
external_filename = parse_filename_from_content_disposition(content_disposition)
|
72
|
+
|
73
|
+
if filename_to_set.nil?
|
74
|
+
filename_to_set = external_filename
|
75
|
+
else
|
76
|
+
filename_to_set << ::File.extname(external_filename)
|
77
|
+
end
|
78
|
+
|
79
|
+
if directory
|
80
|
+
directory = Pathname.new(directory).to_s if directory.is_a?(Pathname)
|
81
|
+
directory.chop! if directory.end_with? '/'
|
82
|
+
else
|
83
|
+
directory = '.'
|
84
|
+
end
|
85
|
+
|
86
|
+
destination = "#{directory}/#{filename_to_set}"
|
87
|
+
|
88
|
+
FileUtils.mkdir_p(directory) if create_directory
|
89
|
+
::File.open(destination, 'wb'){|file| file.write(response.raw_body) }
|
90
|
+
destination
|
91
|
+
end
|
92
|
+
|
93
|
+
def parse_filename_from_content_disposition(content_disposition)
|
94
|
+
if match_data = /filename\*\=utf-8\'\'([\W\w]+)/.match(content_disposition)
|
95
|
+
filename_to_set = URI.unescape(match_data[1].gsub('"', ''))
|
96
|
+
else
|
97
|
+
match_data = / .*filename=\"([\W\w]+)\"/.match(content_disposition)
|
98
|
+
filename_to_set = match_data[1].gsub('"', '')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Ilovepdf
|
2
|
+
module Signature
|
3
|
+
class Receiver
|
4
|
+
ALLOWED_TYPES = [:signer,:validator,:viewer]
|
5
|
+
|
6
|
+
attr_reader :type,:name,:email,:phone, :access_code,:force_signature_type
|
7
|
+
def initialize(type,name,email, phone=nil)
|
8
|
+
@type = type
|
9
|
+
@name = name
|
10
|
+
@email = email
|
11
|
+
@phone = phone
|
12
|
+
end
|
13
|
+
|
14
|
+
def name=(value)
|
15
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only String type of object is allowed") if !value.is_a?(String) || value.empty?
|
16
|
+
@name = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def email=(value)
|
20
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only String type of object is allowed") if !value.is_a?(String) || value.empty?
|
21
|
+
@email = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def type=(value)
|
25
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("type is not valid, valid types are: #{value.join(", ")}") unless ALLOWED_TYPES.include?(value)
|
26
|
+
@type = value
|
27
|
+
end
|
28
|
+
|
29
|
+
def phone=(value)
|
30
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only String type of object is allowed") unless value.is_a?(String)
|
31
|
+
@phone = phone
|
32
|
+
end
|
33
|
+
|
34
|
+
def access_code=(value)
|
35
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only String type of object is allowed") unless value.is_a?(String)
|
36
|
+
@access_code = value
|
37
|
+
end
|
38
|
+
|
39
|
+
def force_signature_type=(value)
|
40
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only String type of object is allowed") unless value.is_a?(String)
|
41
|
+
@force_signature_type = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def elements
|
45
|
+
@elements ||= []
|
46
|
+
end
|
47
|
+
|
48
|
+
def <<(element)
|
49
|
+
raise ::Ilovepdf::Errors::ArgumentError.new("Only Ilovepdf::Signature::FileElement type of object is allowed") unless element.is_a?(::Ilovepdf::Signature::FileElement)
|
50
|
+
@elements ||= []
|
51
|
+
@elements << element
|
52
|
+
elements
|
53
|
+
end
|
54
|
+
alias_method :add_receiver,:<<
|
55
|
+
|
56
|
+
def to_h
|
57
|
+
{
|
58
|
+
name: name,
|
59
|
+
email: email,
|
60
|
+
phone: phone,
|
61
|
+
type: type,
|
62
|
+
access_code: access_code,
|
63
|
+
force_signature_type: force_signature_type,
|
64
|
+
files: files_to_hash
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def files_to_hash
|
71
|
+
files_hash = @elements.inject({}) do |result,element|
|
72
|
+
result[file.server_filename] ||= []
|
73
|
+
result[file.server_filename] << element
|
74
|
+
result
|
75
|
+
end
|
76
|
+
files_hash.inject([]) do |result,(server_filename,elements)|
|
77
|
+
{
|
78
|
+
server_filename: server_filename,
|
79
|
+
elements: elements.map do |element|
|
80
|
+
element.to_h
|
81
|
+
end
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|