pdfbucket 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e602dcfb177b36170044b07abdde9700135e992d
4
+ data.tar.gz: cee1b48ea176d461f9ba4a3aca2adf2619043edd
5
+ SHA512:
6
+ metadata.gz: 91d88bd5478a2c2fbf43c03ec7ba5552bb9f5f90cb2006cb5994371059a18f0627932b6f748ead9b1cf8283864896eeceb312b155a2c9e8181622dc6dc5bc143
7
+ data.tar.gz: 5a5efef0c8d5edc75a561b021083443528eb02a589c6d7c4bd3ba3c70ddfa5612a188f7eab7bdd83159814eaab90adb672ba1d535ed1595e99d341788aa276e1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pdfbucket.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # PDFBucket
2
+
3
+ This gem allows you to use easily sign URLs to be used with the PDFBucket service.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pdfbucket'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ To sign a URL in your code instantiate a signer object and use its generate_url method.
22
+ The new signer will use `PDF_BUCKET_API_KEY`, `PDF_BUCKET_API_SECRET`, `PDF_BUCKET_API_HOST` (default is `pdfbucket.kommit.co`) ENV vars:
23
+
24
+ ```ruby
25
+ signer = PDFBucket::Signer.new
26
+
27
+ # You can also set any the api params, overwriting then ENV vars like this
28
+ other_signer = PDFBucket::Signer.new(api_key: '123', api_secret: '321', api_host: 'potion-api-staging.herokuapp.com')
29
+
30
+ # And you get the signed_url using the sign method
31
+ signed_url = signer.generate_url('http://example.com', :landscape, :a4)
32
+ ```
33
+
34
+ * Possible values for orientation: :landscape, :portrait
35
+ * Possible values for page size: :letter, :a4
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pdfbucket"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module PDFBucket
2
+ VERSION = "0.1.2"
3
+ end
data/lib/pdfbucket.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'pdfbucket/version'
2
+
3
+ require 'openssl'
4
+ require 'digest/sha2'
5
+ require 'base64'
6
+ require 'uri'
7
+
8
+ # Main module
9
+ module PDFBucket
10
+ DEFAULT_HOST = 'pdfbucket.kommit.co'
11
+ ORIENTATIONS = {
12
+ portrait: 'portrait',
13
+ landscape: 'landscape'
14
+ }
15
+ PAGE_SIZES = {
16
+ a4: 'A4',
17
+ letter: 'Letter'
18
+ }
19
+
20
+ # Main class
21
+ class Signer
22
+ attr_reader :api_key, :api_secret, :api_host
23
+
24
+ def initialize(
25
+ api_key: ENV['PDF_BUCKET_API_KEY'],
26
+ api_secret: ENV['PDF_BUCKET_API_SECRET'],
27
+ api_host: ENV['PDF_BUCKET_API_HOST'])
28
+
29
+ fail 'bucket api_key is required' if api_key.nil? || api_key.strip.empty?
30
+ fail 'bucket api_secret is required' if api_secret.nil? || api_secret.strip.empty?
31
+
32
+ @api_host = api_host || DEFAULT_HOST
33
+ @api_key = api_key
34
+ @api_secret = api_secret
35
+ end
36
+
37
+ def generate_url(url, orientation, page_size)
38
+ signed_uri = encrypt(api_secret, url)
39
+
40
+ query = URI.encode_www_form(
41
+ orientation: ORIENTATIONS[orientation],
42
+ page_size: PAGE_SIZES[page_size],
43
+ api_key: api_key,
44
+ signed_uri: signed_uri)
45
+
46
+ URI::HTTPS.build(
47
+ host: api_host,
48
+ path: '/api/convert',
49
+ query: query).to_s
50
+ end
51
+
52
+ private
53
+
54
+ def encrypt(key, content)
55
+ binary_key = Base64.decode64(key)
56
+ alg = 'AES-256-CTR'
57
+ iv = OpenSSL::Cipher::Cipher.new(alg).random_iv
58
+ aes_ctr = OpenSSL::Cipher::Cipher.new(alg)
59
+ aes_ctr.encrypt
60
+ aes_ctr.key = binary_key
61
+ aes_ctr.iv = iv
62
+
63
+ cipher = aes_ctr.update(content)
64
+ cipher << aes_ctr.final
65
+
66
+ Base64.strict_encode64(iv + cipher)
67
+ end
68
+ end
69
+ end
data/pdfbucket.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pdfbucket/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pdfbucket'
8
+ spec.version = PDFBucket::VERSION
9
+ spec.authors = ['sanrodari']
10
+ spec.email = ['santiago.rodriguez@kommit.co']
11
+
12
+ spec.summary = 'PDFBucket integration'
13
+ spec.description = 'PDFBucket integration library to use PDFBucket service'
14
+ spec.homepage = 'https://github.com/PDFBucket/pdfbucket-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.11'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdfbucket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - sanrodari
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: PDFBucket integration library to use PDFBucket service
42
+ email:
43
+ - santiago.rodriguez@kommit.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - lib/pdfbucket.rb
55
+ - lib/pdfbucket/version.rb
56
+ - pdfbucket.gemspec
57
+ homepage: https://github.com/PDFBucket/pdfbucket-ruby
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ allowed_push_host: https://rubygems.org
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: PDFBucket integration
82
+ test_files: []