html_to_pdf_conversion 0.1.2 → 0.1.3

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: ce7ca2406bf947a20244c2fc372ab12d0e7ecc4c
4
- data.tar.gz: aa4402a955a0578d76025cd4cf7c01c221c3c3ff
3
+ metadata.gz: 596ad2143fb6680f5423a499fba355ed0cf0e635
4
+ data.tar.gz: 694c0f2710f4c51b321d4dbb28e544628a5dfbf2
5
5
  SHA512:
6
- metadata.gz: d641a9ad69c4173dcb7987d62d79e908af726754fe2c5d388d0b06ec534dfa8016d288d27f45b3bd74897cd3896a8f77d312c41b793d70a54570892b7839cf33
7
- data.tar.gz: 7a07a07385b87714cc9ec37d5f53373c5ad30663026d82403a724d8279465354d85cdc56882d7d1d23619898c8b70cbddf8c4e165cfedbf6fef59c4983dea582
6
+ metadata.gz: 103bc53b2404c5854e37decc5abe126aae103812c372779e87d056d7f281f1684f240af93ab64ca0545984e987fb943b00e6565c4af0d4a681de38c155fb91d9
7
+ data.tar.gz: ae19dfb75c45008ba8aef994f48c3accf55bb01aed190bc7b3b26775f2c1337c9c3e5096e29adb35249082a110a26809145a653ee681151fa6b425c602317263
data/example/example.rb CHANGED
@@ -1,7 +1,23 @@
1
1
  require 'html_to_pdf_conversion'
2
2
  require 'dotenv'
3
3
 
4
+ # Load Environment Variables
4
5
  Dotenv.load
5
6
 
7
+ # Declare the Client instance passing in the authentication parameters
6
8
  @client = PDFlayer::Client.new(ENV['ACCESS_KEY'], ENV['SECRET_KEY'])
7
- response = @client.convert('http://apilayer.net', { export: File.join('tmp', SecureRandom.uuid() +'.pdf') })
9
+
10
+ # Set the URL to get as PDF, we take a random URL from Wikipedia
11
+ document_url = 'https://en.wikipedia.org/wiki/Special:Random'
12
+
13
+ # We declare the options
14
+ options = PDFlayer::ConvertOptions.new()
15
+ options.export = File.join('tmp', SecureRandom.uuid() +'.pdf')
16
+
17
+ # We make the call to convert
18
+ response = @client.convert(document_url, options)
19
+
20
+ # If its a success, we print a message to the user
21
+ if ! response.nil?
22
+ puts 'SUCCESS : PDF fetched...'
23
+ end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_runtime_dependency "httparty"
23
+ spec.add_runtime_dependency "hashable"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.11"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
@@ -18,6 +18,7 @@
18
18
  <orderEntry type="library" scope="PROVIDED" name="bundler (v1.11.2, ruby-2.0.0-p645) [gem]" level="application" />
19
19
  <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, ruby-2.0.0-p645) [gem]" level="application" />
20
20
  <orderEntry type="library" scope="PROVIDED" name="dotenv (v2.1.0, ruby-2.0.0-p645) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="hashable (v0.1.2, ruby-2.0.0-p645) [gem]" level="application" />
21
22
  <orderEntry type="library" scope="PROVIDED" name="httparty (v0.13.7, ruby-2.0.0-p645) [gem]" level="application" />
22
23
  <orderEntry type="library" scope="PROVIDED" name="json (v1.8.3, ruby-2.0.0-p645) [gem]" level="application" />
23
24
  <orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.5.5, ruby-2.0.0-p645) [gem]" level="application" />
@@ -1,6 +1,8 @@
1
1
  require 'digest'
2
2
  require "httparty"
3
+ require "hashable"
3
4
  require "html_to_pdf_conversion/version"
5
+ require "html_to_pdf_conversion/missing_argument_exception"
4
6
 
5
7
  module PDFlayer
6
8
 
@@ -11,48 +13,153 @@ module PDFlayer
11
13
  base_uri 'api.pdflayer.com/api'
12
14
 
13
15
  def initialize(access_key, secret_key)
16
+
17
+ if access_key.nil?
18
+ raise PDFlayer::MissingArgumentException.new 'access_key'
19
+ end
20
+
21
+ if secret_key.nil?
22
+ raise PDFlayer::MissingArgumentException.new 'secret_key'
23
+ end
24
+
14
25
  @access_key = access_key
15
26
  @secret_key = secret_key
27
+
16
28
  end
17
29
 
30
+
18
31
  def convert(document_url, options = {})
19
32
 
33
+ # Create a shallow copy so we don't manipulate the original reference
34
+ query = options.dup
35
+
36
+ # Generate the SecretKey for the request
20
37
  md5 = Digest::MD5.new
21
38
  md5.update document_url + @secret_key
39
+ secret_key = md5.hexdigest
40
+
41
+ # Populate the Query
42
+ query.access_key = @access_key
43
+ query.secret_key = secret_key
44
+ query.document_url = document_url
45
+
46
+ # We then create the Request
47
+ req = ConvertRequest.new(query)
22
48
 
23
- @options = {
24
- query: {
25
- access_key: @access_key,
26
- document_url: document_url,
27
- secret_key: md5.hexdigest
28
- },
29
- export: options[:export]
30
- }
49
+ # We create a Hash of the request so we can send it via HTTP
50
+ req_dto = req.to_dh
31
51
 
32
52
  begin
33
53
 
34
- res = self.class.get('/convert', @options)
54
+ # We make the actual request
55
+ res = self.class.get('/convert', req_dto)
56
+
57
+ # We ensure that we tap the response so we can use the results
35
58
  res.inspect
36
59
 
37
- if @options[:export]
38
- filename = @options[:export]
60
+ # If we have an export option passed in, we save it to local file system
61
+ if !options.export.nil?
39
62
  begin
40
- File.open(filename, 'a+') do |file|
63
+ File.open(options.export, 'a+') do |file|
41
64
  file.write(res.body)
42
65
  end
43
66
  end
44
67
  end
45
68
 
69
+ # Finally we return the parsed binary response
46
70
  return res.parsed_response
47
71
 
48
72
  rescue => e
49
73
  puts e.inspect
74
+ return
50
75
 
51
76
  ensure
52
-
53
- @options = nil
77
+ # Clean Up
54
78
 
55
79
  end
56
80
  end
57
81
  end
82
+
83
+
84
+ class ConvertRequest
85
+
86
+ include Hashable
87
+
88
+ attr_accessor :query
89
+
90
+ def initialize(query = {})
91
+ self.query = query;
92
+ end
93
+
94
+ end
95
+
96
+
97
+ class ConvertOptions
98
+
99
+ include Hashable
100
+
101
+ attr_accessor :access_key
102
+ attr_accessor :secret_key
103
+
104
+ attr_accessor :document_url
105
+ attr_accessor :document_html
106
+
107
+ attr_accessor :document_name
108
+ attr_accessor :export
109
+ attr_accessor :document_unit
110
+ attr_accessor :user_agent
111
+ attr_accessor :text_encoding
112
+ attr_accessor :ttl
113
+ attr_accessor :force
114
+ attr_accessor :inline
115
+ attr_accessor :auth_user
116
+ attr_accessor :auth_password
117
+ attr_accessor :encryption
118
+ attr_accessor :no_images
119
+ attr_accessor :no_hyperlinks
120
+ attr_accessor :accept_lang
121
+ attr_accessor :no_backgrounds
122
+ attr_accessor :no_javascript
123
+ attr_accessor :use_print_media
124
+ attr_accessor :grayscale
125
+ attr_accessor :low_quality
126
+ attr_accessor :forms
127
+ attr_accessor :no_print
128
+ attr_accessor :no_modify
129
+ attr_accessor :no_copy
130
+ attr_accessor :page_size
131
+ attr_accessor :page_width
132
+ attr_accessor :page_height
133
+ attr_accessor :orientation
134
+ attr_accessor :header_text
135
+ attr_accessor :header_align
136
+ attr_accessor :header_url
137
+ attr_accessor :header_html
138
+ attr_accessor :header_spacing
139
+ attr_accessor :footer_text
140
+ attr_accessor :footer_align
141
+ attr_accessor :footer_url
142
+ attr_accessor :footer_html
143
+ attr_accessor :footer_spacing
144
+ attr_accessor :css_url
145
+ attr_accessor :delay
146
+ attr_accessor :dpi
147
+ attr_accessor :zoom
148
+ attr_accessor :page_numbering_offset
149
+ attr_accessor :watermark_url
150
+ attr_accessor :watermark_opacity
151
+ attr_accessor :watermark_offset_x
152
+ attr_accessor :watermark_offset_y
153
+ attr_accessor :watermark_in_background
154
+ attr_accessor :title
155
+ attr_accessor :subject
156
+ attr_accessor :creator
157
+ attr_accessor :author
158
+
159
+ def initialize()
160
+ @query = nil
161
+ end
162
+
163
+ end
164
+
58
165
  end
@@ -0,0 +1,13 @@
1
+ module PDFlayer
2
+
3
+ class MissingArgumentException < Exception
4
+
5
+ attr_accessor :argument
6
+
7
+ def initialize(argument)
8
+ self.argument = argument
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -1,3 +1,3 @@
1
1
  module PDFlayer
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_to_pdf_conversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Andreas Moelgaard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-14 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +128,7 @@ files:
114
128
  - html_to_pdf_conversion.gemspec
115
129
  - html_to_pdf_conversion.iml
116
130
  - lib/html_to_pdf_conversion.rb
131
+ - lib/html_to_pdf_conversion/missing_argument_exception.rb
117
132
  - lib/html_to_pdf_conversion/version.rb
118
133
  homepage: https://github.com/pmoelgaard/html_to_pdf_conversion
119
134
  licenses: