pdfbucket 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/README.md +17 -10
- data/lib/pdfbucket.rb +64 -35
- data/lib/pdfbucket/version.rb +1 -1
- data/pdfbucket.gemspec +2 -0
- metadata +34 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f06f7c98093bb540a3813a3f9d4fa5c1e29f6d7c
|
4
|
+
data.tar.gz: 1b40b8e0ec2860cd2a52c7efcdff1ed3a811a03b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91be2d208c8392aeefcf75c7f9315b8789bab52ef2dd410629df94a2204f1760f853289e1720946787973d47da70abe6791789071981e5d48e7acf2882401e03
|
7
|
+
data.tar.gz: 703b38409fcce03b76bee8307dfa7de764eb60c42ed38b1bdc4f33afd52fb8122737090912468f5f861c13d90d1f0d34d64bd03112b9bac30156631858c78579
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -27,20 +27,27 @@ pdf_bucket = PDFBucket::PDFBucket.new
|
|
27
27
|
# You can also set any the api params, overwriting then ENV vars like this
|
28
28
|
other_pdf_bucket = PDFBucket::PDFBucket.new(api_key: '123', api_secret: '321', api_host: 'api.example.com')
|
29
29
|
|
30
|
-
# And you get the encrypted_url using the generate_url method
|
31
|
-
encrypted_url = pdf_bucket.generate_url('http://example.com', :landscape, :a4, '2px', '0.7')
|
32
|
-
```
|
30
|
+
# And you get the encrypted_url using the generate_url method taking into account the following order:
|
33
31
|
|
34
|
-
|
32
|
+
# Without pagination: (uri, orientation, page_size, margin, zoom)
|
33
|
+
encrypted_url = pdf_bucket.generate_url('http://example.com', :landscape, :a4, '2px', '0.7')
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
# With pagination: (uri, orientation, page_size, margin, zoom, expires_in, pagination, position, alignment, cache)
|
36
|
+
encrypted_url = pdf_bucket.generate_url('http://example.com', :landscape, :a4, '2px', '0.7', 0, true, :header, :center)
|
37
|
+
# Also you can pass the plain URL to PDFBucket
|
38
|
+
plain_url = pdf_bucket.generate_plain_url('http://example.com', :landscape, :a4, '2px', '0.7', 0, true, :header, :center)
|
38
39
|
```
|
39
40
|
|
40
|
-
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
41
|
+
**Possible values for the different params:**
|
42
|
+
* **orientation:** `:landscape` or `:portrait`
|
43
|
+
* **page size:** `:letter` or `:a4`
|
44
|
+
* **margin:** https://developer.mozilla.org/en-US/docs/Web/CSS/margin#Formal_syntax
|
45
|
+
* **zoom:** https://developer.mozilla.org/en-US/docs/Web/CSS/@viewport/zoom#Formal_syntax
|
46
|
+
* **pagination:** `true` or `false`
|
47
|
+
* **position:** `:header` or `:footer`
|
48
|
+
* **alignment:** `:left`, `:center` or `:right`
|
49
|
+
* **expires_in:** integer value in `seconds`
|
50
|
+
* **cache:** `0` to disable cache
|
44
51
|
|
45
52
|
|
46
53
|
## Development
|
data/lib/pdfbucket.rb
CHANGED
@@ -7,7 +7,8 @@ require 'uri'
|
|
7
7
|
|
8
8
|
# Main module
|
9
9
|
module PDFBucket
|
10
|
-
DEFAULT_HOST = 'api.pdfbucket.io'
|
10
|
+
#DEFAULT_HOST = 'api.pdfbucket.io'
|
11
|
+
DEFAULT_HOST = '8ed3489f.ngrok.io'
|
11
12
|
ORIENTATIONS = {
|
12
13
|
portrait: 'portrait',
|
13
14
|
landscape: 'landscape'
|
@@ -16,66 +17,76 @@ module PDFBucket
|
|
16
17
|
a4: 'A4',
|
17
18
|
letter: 'Letter'
|
18
19
|
}
|
20
|
+
POSITIONS = {
|
21
|
+
header: 'header',
|
22
|
+
footer: 'footer'
|
23
|
+
}
|
24
|
+
ALIGNMENTS = {
|
25
|
+
left: 'left',
|
26
|
+
center: 'center',
|
27
|
+
right: 'right'
|
28
|
+
}
|
19
29
|
|
20
30
|
# Main class
|
21
31
|
class PDFBucket
|
22
32
|
attr_reader :api_key, :api_secret, :api_host
|
23
33
|
|
24
34
|
def initialize(
|
25
|
-
api_key:
|
35
|
+
api_key: ENV['PDF_BUCKET_API_KEY'],
|
26
36
|
api_secret: ENV['PDF_BUCKET_API_SECRET'],
|
27
|
-
api_host:
|
37
|
+
api_host: ENV['PDF_BUCKET_API_HOST'])
|
28
38
|
|
29
39
|
fail 'bucket api_key is required' if api_key.nil? || api_key.strip.empty?
|
30
40
|
fail 'bucket api_secret is required' if api_secret.nil? || api_secret.strip.empty?
|
31
41
|
|
32
|
-
@api_host
|
33
|
-
@api_key
|
42
|
+
@api_host = api_host || DEFAULT_HOST
|
43
|
+
@api_key = api_key
|
34
44
|
@api_secret = api_secret
|
35
45
|
end
|
36
46
|
|
37
|
-
def generate_url(url, orientation, page_size, margin, zoom)
|
47
|
+
def generate_url(url, orientation, page_size, margin, zoom, expires_in = 0, pagination = false, position = nil, alignment = nil, cache = nil)
|
38
48
|
encrypted_uri = encrypt(api_secret, url)
|
39
49
|
|
40
|
-
|
41
|
-
orientation:
|
42
|
-
page_size:
|
43
|
-
margin:
|
44
|
-
zoom:
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
query: query).to_s
|
50
|
+
params = {
|
51
|
+
orientation: ORIENTATIONS[orientation],
|
52
|
+
page_size: PAGE_SIZES[page_size],
|
53
|
+
margin: margin,
|
54
|
+
zoom: zoom,
|
55
|
+
expires_in: expires_in,
|
56
|
+
api_key: api_key,
|
57
|
+
encrypted_uri: encrypted_uri
|
58
|
+
}
|
59
|
+
set_optional_params(params, pagination, position, alignment, cache)
|
60
|
+
build_uri(params)
|
52
61
|
end
|
53
62
|
|
54
|
-
def generate_plain_url(url, orientation, page_size, margin, zoom)
|
55
|
-
signature = sign(api_secret, api_key, url, orientation, page_size, margin, zoom)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
def generate_plain_url(url, orientation, page_size, margin, zoom, expires_in = 0, pagination = false, position = nil, alignment = nil, cache = nil)
|
64
|
+
signature = sign(api_secret, api_key, url, orientation, page_size, margin, zoom, pagination, position, alignment)
|
65
|
+
|
66
|
+
params = {
|
67
|
+
orientation: ORIENTATIONS[orientation],
|
68
|
+
page_size: PAGE_SIZES[page_size],
|
69
|
+
margin: margin,
|
70
|
+
zoom: zoom,
|
71
|
+
expires_in: expires_in,
|
72
|
+
api_key: api_key,
|
73
|
+
uri: url,
|
74
|
+
signature: signature
|
75
|
+
}
|
76
|
+
set_optional_params(params, pagination, position, alignment, cache)
|
77
|
+
build_uri(params)
|
69
78
|
end
|
70
79
|
|
71
80
|
private
|
72
|
-
|
73
|
-
def sign(api_secret, api_key, url, orientation, page_size, margin, zoom)
|
81
|
+
def sign(api_secret, api_key, url, orientation, page_size, margin, zoom, pagination, position, alignment)
|
74
82
|
params = [
|
75
83
|
api_key,
|
76
84
|
url,
|
77
85
|
ORIENTATIONS[orientation],
|
78
86
|
PAGE_SIZES[page_size],
|
87
|
+
pagination.to_s,
|
88
|
+
POSITIONS[position],
|
89
|
+
ALIGNMENTS[alignment],
|
79
90
|
margin,
|
80
91
|
zoom
|
81
92
|
].join(',')
|
@@ -97,5 +108,23 @@ module PDFBucket
|
|
97
108
|
|
98
109
|
Base64.strict_encode64(iv + cipher)
|
99
110
|
end
|
111
|
+
|
112
|
+
def build_uri(params)
|
113
|
+
URI::HTTPS.build(
|
114
|
+
host: api_host,
|
115
|
+
path: '/api/convert',
|
116
|
+
query: URI.encode_www_form(params)).to_s
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_optional_params(params, pagination, position, alignment, cache)
|
120
|
+
params.merge!(cache: cache) if cache
|
121
|
+
if pagination
|
122
|
+
params.merge!({
|
123
|
+
pagination: pagination,
|
124
|
+
position: POSITIONS[position],
|
125
|
+
alignment: ALIGNMENTS[alignment]
|
126
|
+
})
|
127
|
+
end
|
128
|
+
end
|
100
129
|
end
|
101
130
|
end
|
data/lib/pdfbucket/version.rb
CHANGED
data/pdfbucket.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfbucket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sanrodari
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description: PDFBucket integration library to use PDFBucket service
|
42
70
|
email:
|
43
71
|
- santiago.rodriguez@kommit.co
|
@@ -46,6 +74,9 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-version"
|
79
|
+
- ".travis.yml"
|
49
80
|
- Gemfile
|
50
81
|
- README.md
|
51
82
|
- Rakefile
|
@@ -75,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
106
|
version: '0'
|
76
107
|
requirements: []
|
77
108
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.5.1
|
79
110
|
signing_key:
|
80
111
|
specification_version: 4
|
81
112
|
summary: PDFBucket integration
|