hypdf 0.2.2

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTNiYTQ2YzI4OGM0MDU2ZmFlZjQ1ODJjNDVmMmVmOTQ1NTQ5ODJiZQ==
5
+ data.tar.gz: !binary |-
6
+ ZGM2YjkwMGEwMGFjZjZjYjhmZjBmZTAyYjRlYzYzYzk0MzZhOTljNQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmVlZTczYjVjMGEzZDIwZjhmZmVlMDI3NjllZDgzZGRjZWJmOGY3NGEzMTlj
10
+ YzFiZjk5ZWY1NjFiY2YzZTAyNTU1ZjM3NTlmYzZhYzhhMzg0NzJjNDJkN2Y5
11
+ MWY5ZTkzNTdkMmUwY2FkNjUyNzg3NjY0N2ZjNmNlZjUyNWIzOTM=
12
+ data.tar.gz: !binary |-
13
+ MjczZjgyZjRhZTU3YzZjMmMyNjAwOWM4ZDRiY2Y0NzU4YjU2MjVlNTc4YzE3
14
+ OGUzMzk5ZDAzNmQ3MzI1YTFjOWMyMDViYjA2MTcyYzQ2OTlkZGE0NzkwYTQ0
15
+ MmNjMzQ0ZmY3MjE1YmNjMzNiMmI3Y2VlMWYzNjgxNjgyZmU0MjA=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hypdf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 redfield (up.redfield@gmail.com)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # HyPDF
2
+
3
+ Ruby wrapper around the [HyPDF](https://addons.heroku.com/hypdf) API
4
+
5
+ ## Documentation
6
+
7
+ Full documentation can be found [here](https://devcenter.heroku.com/articles/hypdf).
8
+
9
+ ## Contributing
10
+
11
+ 1. Fork it
12
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
13
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
14
+ 4. Push to the branch (`git push origin my-new-feature`)
15
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/hypdf.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hypdf/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "hypdf"
8
+ gem.version = HyPDF::VERSION
9
+ gem.authors = ["redfield"]
10
+ gem.email = ["up.redfield@gmail.com"]
11
+ gem.description = %q{Ruby wrapper around the HyPDF API}
12
+ gem.summary = %q{Ruby wrapper around the HyPDF API}
13
+ gem.homepage = "https://addons.heroku.com/hypdf"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.add_dependency "httparty", ">=0.10.0"
21
+ end
data/lib/hypdf.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'net/http'
2
+ require "json"
3
+ require "hypdf/exceptions"
4
+ require 'httparty'
5
+
6
+ class HyPDF
7
+
8
+ # Initializes new HyPDF object
9
+ #
10
+ # @param content [String] HTML document or URL
11
+ # @param options [Hash] Authorization and PDF options
12
+ # @option options [String] :user If provided, sets user name (by default uses ENV['HYPDF_USER'] variable)
13
+ # @option options [String] :password If provided, sets user password (by default uses ENV['HYPDF_PASSWORD'] variable)
14
+ #
15
+ # Full list of PDF options see on {http://docs.heroku.com HyPDF page}
16
+ def initialize(content, options = {})
17
+ raise HyPDF::ContentRequired if content.nil? || content.empty?
18
+ @content = content
19
+
20
+ @options = options
21
+ @user = @options.delete(:user) || ENV["HYPDF_USER"]
22
+ @password = @options.delete(:password) || ENV["HYPDF_PASSWORD"]
23
+
24
+ @request_body = { user: @user, password: @password, content: @content, options: @options }
25
+ end
26
+
27
+ # Generates PDF
28
+ #
29
+ # @return [String] Binary string containing the generated document or id of asynchronous job
30
+ def get
31
+ make_request.body
32
+ end
33
+
34
+ # Generates PDF and uploads it to AWS S3
35
+ #
36
+ # @param bucket [String] Your S3 bucket name
37
+ # @param key [String] Name for generated file
38
+ # @param public [Boolean] Sets public read access
39
+ # @return [String] Url to generated document or id of asynchronous job
40
+ def upload_to_s3(bucket, key, public = false)
41
+ @request_body.merge!(bucket: bucket, key: key, public: public)
42
+ resp = JSON.parse make_request.body
43
+ resp["url"] || resp["id"]
44
+ end
45
+
46
+ # Returns PDF meta information
47
+ # @return [Hash] PDF meta information (nubmer of pages, page size and PDF version)
48
+ def meta
49
+ {
50
+ pages: @last_headers['hypdf-pages'].to_i,
51
+ page_size: @last_headers['hypdf-page-size'],
52
+ pdf_version: @last_headers['hypdf-pdf-version'].to_f
53
+ }
54
+ end
55
+
56
+ private
57
+
58
+ def make_request(options={})
59
+ resp = HTTParty.post('https://www.hypdf.com/pdf', options.merge(body: @request_body))
60
+ @last_headers = resp.headers
61
+ case resp.code
62
+ when 200 then resp
63
+ when 400 then raise HyPDF::ContentRequired
64
+ when 401 then raise HyPDF::AuthorizationRequired
65
+ when 402 then raise HyPDF::PaymentRequired
66
+ when 404 then raise HyPDF::NoSuchBucket
67
+ when 500 then raise HyPDF::InternalServerError
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,13 @@
1
+ class HyPDF
2
+
3
+ class ContentRequired < ArgumentError; end
4
+
5
+ class AuthorizationRequired < StandardError; end
6
+
7
+ class PaymentRequired < StandardError; end
8
+
9
+ class NoSuchBucket < StandardError; end
10
+
11
+ class InternalServerError < StandardError; end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ class HyPDF
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe HyPDF do
4
+ it 'should have a version number' do
5
+ HyPDF::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should be_true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'hypdf'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - redfield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ description: Ruby wrapper around the HyPDF API
28
+ email:
29
+ - up.redfield@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .rspec
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - hypdf.gemspec
41
+ - lib/hypdf.rb
42
+ - lib/hypdf/exceptions.rb
43
+ - lib/hypdf/version.rb
44
+ - spec/hypdf_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: https://addons.heroku.com/hypdf
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Ruby wrapper around the HyPDF API
70
+ test_files:
71
+ - spec/hypdf_spec.rb
72
+ - spec/spec_helper.rb