hypdf 0.2.2 → 1.0.1

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 CHANGED
@@ -1,15 +1,7 @@
1
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=
2
+ SHA1:
3
+ metadata.gz: d01ef0f4bc12b7ec1ef73668326a0033fa0efac3
4
+ data.tar.gz: 5d3b10c5b68caabc880af55d485b4ae513fa28e2
5
+ SHA512:
6
+ metadata.gz: ab43ac8828a6b733d6db5fb4764a86df401238d3d7648972b6b806cb972f94df42303af151649dbe8ce2ddb0e2d506d3963b95c963a7150348c51ba156890a58
7
+ data.tar.gz: 97aa983e15ee97788a2a200471ac1025d39dfe3505ce66b9964a11aae7add9031b99f705cb0cd74f43f61c2fe6fb9bf4dc810e2ce9387a7e229a883694cae6c3
data/hypdf.gemspec CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
- gem.add_dependency "httparty", ">=0.10.0"
20
+ gem.add_dependency "httmultiparty", ">=0.3.10"
21
21
  end
data/lib/hypdf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class HyPDF
2
- VERSION = "0.2.2"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/hypdf.rb CHANGED
@@ -1,10 +1,71 @@
1
- require 'net/http'
2
1
  require "json"
3
2
  require "hypdf/exceptions"
4
- require 'httparty'
3
+ require 'httmultiparty'
5
4
 
6
5
  class HyPDF
7
6
 
7
+ HOST = 'https://www.hypdf.com'
8
+
9
+ class << self
10
+
11
+ def htmltopdf(content, options = {})
12
+ raise HyPDF::ContentRequired if content.nil? || content.empty?
13
+ options[:content] = content
14
+ response = request('htmltopdf', options)
15
+
16
+ result = {
17
+ pages: response.headers['hypdf-pages'].to_i,
18
+ page_size: response.headers['hypdf-page-size'],
19
+ pdf_version: response.headers['hypdf-pdf-version'].to_f
20
+ }
21
+
22
+ if options[:callback].nil? && options[:bucket].nil?
23
+ result.merge(pdf: response.body)
24
+ else
25
+ result.merge(JSON.parse(response.body, symbolize_names: true))
26
+ end
27
+ end
28
+
29
+ def pdfinfo(file, options = {})
30
+ options.merge!(file: File.new(file))
31
+ JSON.parse(request('pdfinfo', options).body)
32
+ end
33
+
34
+ def pdftotext(file, options = {})
35
+ options.merge!(file: File.new(file))
36
+ JSON.parse(request('pdftotext', options).body, symbolize_names: true)
37
+ end
38
+
39
+ def pdfextract(file, options = {})
40
+ options.merge!(file: File.new(file))
41
+ {pdf: request('pdfextract', options).body}
42
+ end
43
+
44
+ def pdfunite(file_1, file_2, options = {})
45
+ options.merge!(file_1: File.new(file_1))
46
+ options.merge!(file_2: File.new(file_2))
47
+ {pdf: request('pdfunite', options).body}
48
+ end
49
+
50
+ private
51
+
52
+ def request(method, body)
53
+ body[:user] ||= ENV["HYPDF_USER"]
54
+ body[:password] ||= ENV["HYPDF_PASSWORD"]
55
+
56
+ response = HTTMultiParty.post("#{HyPDF::HOST}/#{method}", body: body)
57
+ case response.code
58
+ when 200 then response
59
+ when 400 then raise HyPDF::ContentRequired
60
+ when 401 then raise HyPDF::AuthorizationRequired
61
+ when 402 then raise HyPDF::PaymentRequired
62
+ when 404 then raise HyPDF::NoSuchBucket
63
+ when 500 then raise HyPDF::InternalServerError
64
+ end
65
+ end
66
+
67
+ end
68
+
8
69
  # Initializes new HyPDF object
9
70
  #
10
71
  # @param content [String] HTML document or URL
@@ -14,6 +75,7 @@ class HyPDF
14
75
  #
15
76
  # Full list of PDF options see on {http://docs.heroku.com HyPDF page}
16
77
  def initialize(content, options = {})
78
+ puts "Warning! This syntax is deprecated and will be removed in the future version, please visit https://devcenter.heroku.com/articles/hypdf for details."
17
79
  raise HyPDF::ContentRequired if content.nil? || content.empty?
18
80
  @content = content
19
81
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - redfield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: httmultiparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.0
19
+ version: 0.3.10
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.0
26
+ version: 0.3.10
27
27
  description: Ruby wrapper around the HyPDF API
28
28
  email:
29
29
  - up.redfield@gmail.com
@@ -53,12 +53,12 @@ require_paths:
53
53
  - lib
54
54
  required_ruby_version: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - ! '>='
56
+ - - '>='
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ! '>='
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []