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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d69835003ac37c1a070c0dca78860219ce255a5b
4
- data.tar.gz: fd2d427153bba4db28df8a501f4aecdf281a9d34
3
+ metadata.gz: f06f7c98093bb540a3813a3f9d4fa5c1e29f6d7c
4
+ data.tar.gz: 1b40b8e0ec2860cd2a52c7efcdff1ed3a811a03b
5
5
  SHA512:
6
- metadata.gz: 9aa6d13ee50b2c6801df7b2f8a75158f2f8ebd99cabc6eb5cf41d12e7d7b1e06e10eff61ac70b61f315a09a4860ea73da47f0acbc7618962742f7a3261106298
7
- data.tar.gz: 62890495c4eccb68d0e8971dbb9cdb9f7d4421c777f76b85944ab6a9aceeae03e5b9b63c2b359e7a861dfc2807def2048fe5a02e2e1f91d8d862033aadc7af88
6
+ metadata.gz: 91be2d208c8392aeefcf75c7f9315b8789bab52ef2dd410629df94a2204f1760f853289e1720946787973d47da70abe6791789071981e5d48e7acf2882401e03
7
+ data.tar.gz: 703b38409fcce03b76bee8307dfa7de764eb60c42ed38b1bdc4f33afd52fb8122737090912468f5f861c13d90d1f0d34d64bd03112b9bac30156631858c78579
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .byebug_history
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.3
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
- Also you can pass the plain URL to PDFBucket
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
- ```ruby
37
- plain_url = pdf_bucket.generate_plain_url('http://example.com', :landscape, :a4, '2px', '0.7')
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
- * Possible values for orientation: :landscape, :portrait
41
- * Possible values for page size: :letter, :a4
42
- * Possible values for margin: https://developer.mozilla.org/en-US/docs/Web/CSS/margin#Formal_syntax
43
- * Possible values for zoom: https://developer.mozilla.org/en-US/docs/Web/CSS/@viewport/zoom#Formal_syntax
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
@@ -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: ENV['PDF_BUCKET_API_KEY'],
35
+ api_key: ENV['PDF_BUCKET_API_KEY'],
26
36
  api_secret: ENV['PDF_BUCKET_API_SECRET'],
27
- api_host: ENV['PDF_BUCKET_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 = api_host || DEFAULT_HOST
33
- @api_key = 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
- query = URI.encode_www_form(
41
- orientation: ORIENTATIONS[orientation],
42
- page_size: PAGE_SIZES[page_size],
43
- margin: margin,
44
- zoom: zoom,
45
- api_key: api_key,
46
- encrypted_uri: encrypted_uri)
47
-
48
- URI::HTTPS.build(
49
- host: api_host,
50
- path: '/api/convert',
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
- query = URI.encode_www_form(
57
- orientation: ORIENTATIONS[orientation],
58
- page_size: PAGE_SIZES[page_size],
59
- margin: margin,
60
- zoom: zoom,
61
- api_key: api_key,
62
- uri: url,
63
- signature: signature)
64
-
65
- URI::HTTPS.build(
66
- host: api_host,
67
- path: '/api/convert',
68
- query: query).to_s
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
@@ -1,3 +1,3 @@
1
1
  module PDFBucket
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -29,4 +29,6 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 1.11'
31
31
  spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "byebug"
32
34
  end
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.3.2
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: 2016-07-08 00:00:00.000000000 Z
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.6.4
109
+ rubygems_version: 2.5.1
79
110
  signing_key:
80
111
  specification_version: 4
81
112
  summary: PDFBucket integration