pdfserve_client 2.0.0 → 2.1.0
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 +4 -4
- data/README.md +12 -12
- data/lib/pdfserve/client.rb +38 -0
- data/lib/pdfserve/merge.rb +47 -0
- data/lib/{pdfserve_client → pdfserve}/split.rb +17 -16
- data/lib/{pdfserve_client → pdfserve}/stamp.rb +15 -14
- data/lib/pdfserve/version.rb +5 -0
- metadata +12 -15
- data/lib/pdfserve_client/client.rb +0 -40
- data/lib/pdfserve_client/merge.rb +0 -45
- data/lib/pdfserve_client/version.rb +0 -5
- data/lib/pdfserve_client.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bda63ed2b57602e119910e3c0e48bcb34daf395b9abd1d83d7d4e37e6f9752d
|
|
4
|
+
data.tar.gz: efd6730b309387ea93c4ebaee10c401150d34b18af4fe2d4547174d41b2122b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 945c3fe84944a2dbbda2f9198ab5c96370e3a484269a7581284d276bc97ebd0db875480455b2a44215dc01645abe087cd33d799b2cd3b61d6721cc9a80cfb948
|
|
7
|
+
data.tar.gz: 56b53b1daa7f45defea6d840d85bf5e9af32ada99450a4a2ad13f03388927020770ecbfd958ca33b0779b7c2261ee9baf5b964e864de9bb6ec4e148f9696c2db
|
data/README.md
CHANGED
|
@@ -21,7 +21,7 @@ bundle install
|
|
|
21
21
|
### PDFServe Client
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
|
-
require '
|
|
24
|
+
require 'pdfserve/client'
|
|
25
25
|
|
|
26
26
|
file_urls = [
|
|
27
27
|
'https://s3-public.de/file1.pdf',
|
|
@@ -29,7 +29,7 @@ file_urls = [
|
|
|
29
29
|
]
|
|
30
30
|
output_path = './output.pdf'
|
|
31
31
|
|
|
32
|
-
client =
|
|
32
|
+
client = Pdfserve::Client.new(api_endpoint: 'https://your.custom.endpoint')
|
|
33
33
|
client.merge(file_urls:, output_path:)
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ or with a token
|
|
|
37
37
|
|
|
38
38
|
```ruby
|
|
39
39
|
|
|
40
|
-
require '
|
|
40
|
+
require 'pdfserve/client'
|
|
41
41
|
|
|
42
42
|
file_urls = [
|
|
43
43
|
'https://s3-public.de/file1.pdf',
|
|
@@ -45,7 +45,7 @@ file_urls = [
|
|
|
45
45
|
]
|
|
46
46
|
output_path = './output.pdf'
|
|
47
47
|
|
|
48
|
-
client =
|
|
48
|
+
client = Pdfserve::Client.new(api_endpoint: 'https://your.custom.endpoint', api_token: 'the-token')
|
|
49
49
|
client.merge(file_urls:, output_path:)
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -56,12 +56,12 @@ client.merge(file_urls:, output_path:)
|
|
|
56
56
|
### PDF Stamp
|
|
57
57
|
|
|
58
58
|
```ruby
|
|
59
|
-
require '
|
|
59
|
+
require 'pdfserve/client'
|
|
60
60
|
|
|
61
61
|
file_url = 'https://s3-public.de/file1.pdf'
|
|
62
62
|
stamp_text = 'A1'
|
|
63
63
|
|
|
64
|
-
client =
|
|
64
|
+
client = Pdfserve::Client.new(api_endpoint: 'https://your.custom.endpoint')
|
|
65
65
|
client.stamp(file_url:, stamp_text:)
|
|
66
66
|
```
|
|
67
67
|
|
|
@@ -69,12 +69,12 @@ or with a token
|
|
|
69
69
|
|
|
70
70
|
```ruby
|
|
71
71
|
|
|
72
|
-
require '
|
|
72
|
+
require 'pdfserve/client'
|
|
73
73
|
|
|
74
74
|
file_url = 'https://s3-public.de/file1.pdf'
|
|
75
75
|
stamp_text = 'A1'
|
|
76
76
|
|
|
77
|
-
client =
|
|
77
|
+
client = Pdfserve::Client.new(api_endpoint: 'https://your.custom.endpoint', api_token: 'the-token')
|
|
78
78
|
client.stamp(file_url:, stamp_text:)
|
|
79
79
|
```
|
|
80
80
|
|
|
@@ -84,12 +84,12 @@ client.stamp(file_url:, stamp_text:)
|
|
|
84
84
|
### PDF Split
|
|
85
85
|
|
|
86
86
|
```ruby
|
|
87
|
-
require '
|
|
87
|
+
require 'pdfserve/client'
|
|
88
88
|
|
|
89
89
|
file_url = 'https://s3-public.de/file1.pdf'
|
|
90
90
|
pages = '1-3,4,6-8'
|
|
91
91
|
|
|
92
|
-
client =
|
|
92
|
+
client = Pdfserve::Client.new(api_endpoint: 'https://your.custom.endpoint')
|
|
93
93
|
client.split(file_url:, pages:)
|
|
94
94
|
```
|
|
95
95
|
|
|
@@ -97,12 +97,12 @@ or with a token
|
|
|
97
97
|
|
|
98
98
|
```ruby
|
|
99
99
|
|
|
100
|
-
require '
|
|
100
|
+
require 'pdfserve/client'
|
|
101
101
|
|
|
102
102
|
file_url = 'https://s3-public.de/file1.pdf'
|
|
103
103
|
pages = '1-3,4,6-8'
|
|
104
104
|
|
|
105
|
-
client =
|
|
105
|
+
client = Pdfserve::Client.new(api_endpoint: 'https://your.custom.endpoint', api_token: 'the-token')
|
|
106
106
|
client.split(file_url:, pages:)
|
|
107
107
|
```
|
|
108
108
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative 'merge'
|
|
2
|
+
require_relative 'stamp'
|
|
3
|
+
require_relative 'split'
|
|
4
|
+
|
|
5
|
+
module Pdfserve
|
|
6
|
+
class Client
|
|
7
|
+
def initialize(api_endpoint:, api_token:)
|
|
8
|
+
@api_endpoint = api_endpoint
|
|
9
|
+
@api_token = api_token
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def merge(file_urls:, output_path:, rotations: nil)
|
|
13
|
+
merge_service.merge(file_urls, output_path, rotations:)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def stamp(file_url:, stamp_text:)
|
|
17
|
+
stamp_service.call(file_url, stamp_text)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def split(file_url:, pages:)
|
|
21
|
+
split_service.split(file_url:, pages:)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def merge_service
|
|
27
|
+
Pdfserve::Merge.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def stamp_service
|
|
31
|
+
Pdfserve::Stamp.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def split_service
|
|
35
|
+
Pdfserve::Split.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'version'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'json'
|
|
7
|
+
require 'ostruct'
|
|
8
|
+
|
|
9
|
+
module Pdfserve
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
class Merge
|
|
13
|
+
PATH = '/api/v1/pdf/merge'
|
|
14
|
+
|
|
15
|
+
def initialize(api_endpoint:, api_token: nil)
|
|
16
|
+
@api_endpoint = api_endpoint + PATH
|
|
17
|
+
@api_token = api_token
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def merge(file_urls, output_path, rotations: nil)
|
|
21
|
+
uri = URI(api_endpoint)
|
|
22
|
+
uri.query = URI.encode_www_form(rotations.map { |angle| ['rotations', angle] }) if rotations && !rotations.empty?
|
|
23
|
+
request = Net::HTTP::Post.new(uri)
|
|
24
|
+
request['token'] = api_token unless api_token.nil?
|
|
25
|
+
form_data = file_urls.map { |url| ['files', url] }
|
|
26
|
+
|
|
27
|
+
request.set_form form_data, 'multipart/form-data'
|
|
28
|
+
|
|
29
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
30
|
+
http.request(request)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if response.is_a?(Net::HTTPSuccess)
|
|
34
|
+
File.binwrite(output_path, response.body)
|
|
35
|
+
puts 'Success!'
|
|
36
|
+
OpenStruct.new(success: true, errors: '')
|
|
37
|
+
else
|
|
38
|
+
puts 'Failed!'
|
|
39
|
+
OpenStruct.new(success: false, errors: response.message)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
attr_reader :api_endpoint, :api_token
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require_relative 'version'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'json'
|
|
7
|
+
require 'ostruct'
|
|
7
8
|
|
|
8
|
-
module
|
|
9
|
+
module Pdfserve
|
|
9
10
|
class Error < StandardError; end
|
|
10
11
|
|
|
11
12
|
class Split
|
|
12
|
-
PATH =
|
|
13
|
+
PATH = '/api/v1/pdf/split'
|
|
13
14
|
|
|
14
15
|
def initialize(api_endpoint:, api_token: nil)
|
|
15
16
|
@api_endpoint = api_endpoint + PATH
|
|
@@ -18,29 +19,29 @@ module PdfserveClient
|
|
|
18
19
|
|
|
19
20
|
def split(file_url:, pages:)
|
|
20
21
|
uri = URI(api_endpoint)
|
|
21
|
-
uri.query = URI.encode_www_form({ pages:
|
|
22
|
+
uri.query = URI.encode_www_form({ pages: })
|
|
22
23
|
|
|
23
24
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
24
|
-
http.use_ssl = uri.scheme ==
|
|
25
|
+
http.use_ssl = uri.scheme == 'https'
|
|
25
26
|
request = Net::HTTP::Post.new(uri.request_uri)
|
|
26
27
|
|
|
27
|
-
request[
|
|
28
|
-
form_data = [[
|
|
28
|
+
request['token'] = api_token unless api_token.nil?
|
|
29
|
+
form_data = [['splitfile', file_url]]
|
|
29
30
|
|
|
30
|
-
request.set_form form_data,
|
|
31
|
+
request.set_form form_data, 'multipart/form-data'
|
|
31
32
|
|
|
32
33
|
response = http.request(request)
|
|
33
34
|
|
|
34
35
|
if response.is_a?(Net::HTTPSuccess)
|
|
35
|
-
puts
|
|
36
|
-
content_disposition = response.header[
|
|
37
|
-
filename = content_disposition[/filename="?([^"]+)"?/, 1] ||
|
|
36
|
+
puts 'Successful split!'
|
|
37
|
+
content_disposition = response.header['Content-Disposition']
|
|
38
|
+
filename = content_disposition[/filename="?([^"]+)"?/, 1] || 'archive.tar.gz'
|
|
38
39
|
|
|
39
40
|
OpenStruct.new(
|
|
40
|
-
success: true, response: response.read_body, filename
|
|
41
|
+
success: true, response: response.read_body, filename:, errors: ''
|
|
41
42
|
)
|
|
42
43
|
else
|
|
43
|
-
puts
|
|
44
|
+
puts 'Failed!'
|
|
44
45
|
OpenStruct.new(
|
|
45
46
|
success: false, response: response.body, errors: response.message
|
|
46
47
|
)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require_relative 'version'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'json'
|
|
7
|
+
require 'ostruct'
|
|
7
8
|
|
|
8
|
-
module
|
|
9
|
+
module Pdfserve
|
|
9
10
|
class Error < StandardError; end
|
|
10
11
|
|
|
11
12
|
class Stamp
|
|
12
|
-
PATH =
|
|
13
|
+
PATH = '/api/v1/pdf/stamp'
|
|
13
14
|
|
|
14
15
|
def initialize(api_endpoint:, api_token: nil)
|
|
15
16
|
@api_endpoint = api_endpoint + PATH
|
|
@@ -19,26 +20,26 @@ module PdfserveClient
|
|
|
19
20
|
def call(file_url, stamp_text)
|
|
20
21
|
uri = URI(api_endpoint)
|
|
21
22
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
22
|
-
http.use_ssl = uri.scheme ==
|
|
23
|
+
http.use_ssl = uri.scheme == 'https'
|
|
23
24
|
request = Net::HTTP::Post.new(uri.request_uri)
|
|
24
25
|
|
|
25
|
-
request[
|
|
26
|
+
request['token'] = api_token unless api_token.nil?
|
|
26
27
|
form_data = [
|
|
27
|
-
[
|
|
28
|
-
[
|
|
28
|
+
['files', file_url],
|
|
29
|
+
['stamp_text', { 'text' => stamp_text, 'color' => '0,0,0', 'position_name' => 'tr', 'over' => 'true' }.to_json]
|
|
29
30
|
]
|
|
30
31
|
|
|
31
|
-
request.set_form form_data,
|
|
32
|
+
request.set_form form_data, 'multipart/form-data'
|
|
32
33
|
|
|
33
34
|
response = http.request(request)
|
|
34
35
|
|
|
35
36
|
if response.is_a?(Net::HTTPSuccess)
|
|
36
|
-
puts
|
|
37
|
+
puts 'Successful stamp!'
|
|
37
38
|
OpenStruct.new(
|
|
38
|
-
success: true, response: response.body, errors:
|
|
39
|
+
success: true, response: response.body, errors: ''
|
|
39
40
|
)
|
|
40
41
|
else
|
|
41
|
-
puts
|
|
42
|
+
puts 'Failed!'
|
|
42
43
|
OpenStruct.new(
|
|
43
44
|
success: false, response: response.body, errors: response.message
|
|
44
45
|
)
|
metadata
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pdfserve_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Isabel Garcia
|
|
8
8
|
- Antoine Legrand
|
|
9
9
|
- Lakhan Pasari
|
|
10
|
-
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date:
|
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
15
|
name: net-http
|
|
@@ -29,7 +28,7 @@ dependencies:
|
|
|
29
28
|
description: This gem provides a simple interface to merge, stamp, split PDFs using
|
|
30
29
|
https://github.com/ant31/pdfserve API.
|
|
31
30
|
email:
|
|
32
|
-
-
|
|
31
|
+
- isabelgg22@gmail.com
|
|
33
32
|
- antoine.legrand@conny.legal
|
|
34
33
|
- lakhan.pasari@conny.legal
|
|
35
34
|
executables: []
|
|
@@ -37,17 +36,16 @@ extensions: []
|
|
|
37
36
|
extra_rdoc_files: []
|
|
38
37
|
files:
|
|
39
38
|
- README.md
|
|
40
|
-
- lib/
|
|
41
|
-
- lib/
|
|
42
|
-
- lib/
|
|
43
|
-
- lib/
|
|
44
|
-
- lib/
|
|
45
|
-
- lib/pdfserve_client/version.rb
|
|
39
|
+
- lib/pdfserve/client.rb
|
|
40
|
+
- lib/pdfserve/merge.rb
|
|
41
|
+
- lib/pdfserve/split.rb
|
|
42
|
+
- lib/pdfserve/stamp.rb
|
|
43
|
+
- lib/pdfserve/version.rb
|
|
46
44
|
homepage: https://github.com/mietright/pdf_merger
|
|
47
45
|
licenses:
|
|
48
46
|
- MIT
|
|
49
|
-
metadata:
|
|
50
|
-
|
|
47
|
+
metadata:
|
|
48
|
+
rubygems_mfa_required: 'true'
|
|
51
49
|
rdoc_options: []
|
|
52
50
|
require_paths:
|
|
53
51
|
- lib
|
|
@@ -55,15 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
55
53
|
requirements:
|
|
56
54
|
- - ">="
|
|
57
55
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '
|
|
56
|
+
version: '3.3'
|
|
59
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
58
|
requirements:
|
|
61
59
|
- - ">="
|
|
62
60
|
- !ruby/object:Gem::Version
|
|
63
61
|
version: '0'
|
|
64
62
|
requirements: []
|
|
65
|
-
rubygems_version:
|
|
66
|
-
signing_key:
|
|
63
|
+
rubygems_version: 4.0.10
|
|
67
64
|
specification_version: 4
|
|
68
65
|
summary: A gem for merging, stamping, and splitting PDFs using an external API
|
|
69
66
|
test_files: []
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require_relative "merge"
|
|
2
|
-
require_relative "stamp"
|
|
3
|
-
require_relative "split"
|
|
4
|
-
|
|
5
|
-
module PdfserveClient
|
|
6
|
-
class Client
|
|
7
|
-
attr_reader :merge_service, :stamp_service, :split_service
|
|
8
|
-
|
|
9
|
-
def initialize(api_endpoint:, api_token:)
|
|
10
|
-
@api_endpoint = api_endpoint
|
|
11
|
-
@api_token = api_token
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def merge(file_urls:, output_path:)
|
|
15
|
-
merge_service.merge(file_urls, output_path)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def stamp(file_url:, stamp_text:)
|
|
19
|
-
stamp_service.call(file_url, stamp_text)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def split(file_url:, pages:)
|
|
23
|
-
split_service.split(file_url:, pages:)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def merge_service
|
|
29
|
-
PdfserveClient::Merge.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def stamp_service
|
|
33
|
-
PdfserveClient::Stamp.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def split_service
|
|
37
|
-
PdfserveClient::Split.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "version"
|
|
4
|
-
require "net/http"
|
|
5
|
-
require "uri"
|
|
6
|
-
require "json"
|
|
7
|
-
|
|
8
|
-
module PdfserveClient
|
|
9
|
-
class Error < StandardError; end
|
|
10
|
-
|
|
11
|
-
class Merge
|
|
12
|
-
PATH = "/api/v1/pdf/merge"
|
|
13
|
-
|
|
14
|
-
def initialize(api_endpoint:, api_token: nil)
|
|
15
|
-
@api_endpoint = api_endpoint + PATH
|
|
16
|
-
@api_token = api_token
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def merge(file_urls, output_path)
|
|
20
|
-
uri = URI(api_endpoint)
|
|
21
|
-
request = Net::HTTP::Post.new(uri)
|
|
22
|
-
request["token"] = api_token unless api_token.nil?
|
|
23
|
-
form_data = file_urls.map { |url| ["files", url] }
|
|
24
|
-
|
|
25
|
-
request.set_form form_data, "multipart/form-data"
|
|
26
|
-
|
|
27
|
-
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
28
|
-
http.request(request)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
if response.is_a?(Net::HTTPSuccess)
|
|
32
|
-
File.open(output_path, "wb") { |file| file.write(response.body) }
|
|
33
|
-
puts "Success!"
|
|
34
|
-
OpenStruct.new(success: true, errors: "")
|
|
35
|
-
else
|
|
36
|
-
puts "Failed!"
|
|
37
|
-
OpenStruct.new(success: false, errors: response.message)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
attr_reader :api_endpoint, :api_token
|
|
44
|
-
end
|
|
45
|
-
end
|
data/lib/pdfserve_client.rb
DELETED