docraptor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,96 +1,150 @@
1
+ require 'date'
2
+
1
3
  module DocRaptor
2
- #
3
- class PrinceOptions < BaseObject
4
- attr_accessor :baseurl, :no_xinclude, :no_network, :http_user, :http_password, :http_proxy, :http_timeout, :insecure, :media, :no_author_style, :no_default_style, :no_embed_fonts, :no_subset_fonts, :no_compress, :encrypt, :key_bits, :user_password, :owner_password, :disallow_print, :disallow_copy, :disallow_annotate, :disallow_modify, :input, :version, :javascript, :css_dpi, :profile
5
- # attribute mapping from ruby-style variable name to JSON key
4
+ class PrinceOptions
5
+ # Set the baseurl for assets.
6
+ attr_accessor :baseurl
7
+
8
+ # Disable XML inclusion.
9
+ attr_accessor :no_xinclude
10
+
11
+ # Disable network access.
12
+ attr_accessor :no_network
13
+
14
+ # Set the user for HTTP authentication.
15
+ attr_accessor :http_user
16
+
17
+ # Set the password for HTTP authentication.
18
+ attr_accessor :http_password
19
+
20
+ # Set the HTTP proxy server.
21
+ attr_accessor :http_proxy
22
+
23
+ # Set the HTTP request timeout.
24
+ attr_accessor :http_timeout
25
+
26
+ # Disable SSL verification.
27
+ attr_accessor :insecure
28
+
29
+ # Specify the CSS media type. Defaults to \"print\" but you may want to use \"screen\" for web styles.
30
+ attr_accessor :media
31
+
32
+ # Ignore author stylesheets.
33
+ attr_accessor :no_author_style
34
+
35
+ # Ignore default stylesheets.
36
+ attr_accessor :no_default_style
37
+
38
+ # Disable font embedding in PDFs.
39
+ attr_accessor :no_embed_fonts
40
+
41
+ # Disable font subsetting in PDFs.
42
+ attr_accessor :no_subset_fonts
43
+
44
+ # Disable PDF compression.
45
+ attr_accessor :no_compress
46
+
47
+ # Encrypt PDF output.
48
+ attr_accessor :encrypt
49
+
50
+ # Set encryption key size.
51
+ attr_accessor :key_bits
52
+
53
+ # Set the PDF user password.
54
+ attr_accessor :user_password
55
+
56
+ # Set the PDF owner password.
57
+ attr_accessor :owner_password
58
+
59
+ # Disallow printing of this PDF.
60
+ attr_accessor :disallow_print
61
+
62
+ # Disallow copying of this PDF.
63
+ attr_accessor :disallow_copy
64
+
65
+ # Disallow annotation of this PDF.
66
+ attr_accessor :disallow_annotate
67
+
68
+ # Disallow modification of this PDF.
69
+ attr_accessor :disallow_modify
70
+
71
+ # Specify the input format.
72
+ attr_accessor :input
73
+
74
+ # Specify a specific verison of PrinceXML to use.
75
+ attr_accessor :version
76
+
77
+ # Enable PrinceXML JavaScript. DocRaptor JavaScript parsing is also available elsewhere.
78
+ attr_accessor :javascript
79
+
80
+ # Set the DPI when rendering CSS. Defaults to 96 but can be set with Prince 9.0 and up.
81
+ attr_accessor :css_dpi
82
+
83
+ # In Prince 9.0 and up you can set the PDF profile.
84
+ attr_accessor :profile
85
+
86
+ # Attribute mapping from ruby-style variable name to JSON key.
6
87
  def self.attribute_map
7
88
  {
8
89
 
9
- # Set the baseurl for assets.
10
90
  :'baseurl' => :'baseurl',
11
91
 
12
- # Disable XML inclusion.
13
92
  :'no_xinclude' => :'no_xinclude',
14
93
 
15
- # Disable network access.
16
94
  :'no_network' => :'no_network',
17
95
 
18
- # Set the user for HTTP authentication.
19
96
  :'http_user' => :'http_user',
20
97
 
21
- # Set the password for HTTP authentication.
22
98
  :'http_password' => :'http_password',
23
99
 
24
- # Set the HTTP proxy server.
25
100
  :'http_proxy' => :'http_proxy',
26
101
 
27
- # Set the HTTP request timeout.
28
102
  :'http_timeout' => :'http_timeout',
29
103
 
30
- # Disable SSL verification.
31
104
  :'insecure' => :'insecure',
32
105
 
33
- # Specify the CSS media type. Defaults to \&quot;print\&quot; but you may want to use \&quot;screen\&quot; for web styles.
34
106
  :'media' => :'media',
35
107
 
36
- # Ignore author stylesheets.
37
108
  :'no_author_style' => :'no_author_style',
38
109
 
39
- # Ignore default stylesheets.
40
110
  :'no_default_style' => :'no_default_style',
41
111
 
42
- # Disable font embedding in PDFs.
43
112
  :'no_embed_fonts' => :'no_embed_fonts',
44
113
 
45
- # Disable font subsetting in PDFs.
46
114
  :'no_subset_fonts' => :'no_subset_fonts',
47
115
 
48
- # Disable PDF compression.
49
116
  :'no_compress' => :'no_compress',
50
117
 
51
- # Encrypt PDF output.
52
118
  :'encrypt' => :'encrypt',
53
119
 
54
- # Set encryption key size.
55
120
  :'key_bits' => :'key_bits',
56
121
 
57
- # Set the PDF user password.
58
122
  :'user_password' => :'user_password',
59
123
 
60
- # Set the PDF owner password.
61
124
  :'owner_password' => :'owner_password',
62
125
 
63
- # Disallow printing of this PDF.
64
126
  :'disallow_print' => :'disallow_print',
65
127
 
66
- # Disallow copying of this PDF.
67
128
  :'disallow_copy' => :'disallow_copy',
68
129
 
69
- # Disallow annotation of this PDF.
70
130
  :'disallow_annotate' => :'disallow_annotate',
71
131
 
72
- # Disallow modification of this PDF.
73
132
  :'disallow_modify' => :'disallow_modify',
74
133
 
75
- # Specify the input format.
76
134
  :'input' => :'input',
77
135
 
78
- # Specify a specific verison of PrinceXML to use.
79
136
  :'version' => :'version',
80
137
 
81
- # Enable PrinceXML JavaScript. DocRaptor JavaScript parsing is also available elsewhere.
82
138
  :'javascript' => :'javascript',
83
139
 
84
- # Set the DPI when rendering CSS. Defaults to 96 but can be set with Prince 9.0 and up.
85
140
  :'css_dpi' => :'css_dpi',
86
141
 
87
- # In Prince 9.0 and up you can set the PDF profile.
88
142
  :'profile' => :'profile'
89
143
 
90
144
  }
91
145
  end
92
146
 
93
- # attribute type
147
+ # Attribute type mapping.
94
148
  def self.swagger_types
95
149
  {
96
150
  :'baseurl' => :'String',
@@ -125,7 +179,7 @@ module DocRaptor
125
179
  end
126
180
 
127
181
  def initialize(attributes = {})
128
- return if !attributes.is_a?(Hash) || attributes.empty?
182
+ return unless attributes.is_a?(Hash)
129
183
 
130
184
  # convert string to symbol for hash key
131
185
  attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
@@ -165,6 +219,8 @@ module DocRaptor
165
219
 
166
220
  if attributes[:'media']
167
221
  self.media = attributes[:'media']
222
+ else
223
+ self.media = "print"
168
224
  end
169
225
 
170
226
  if attributes[:'no_author_style']
@@ -221,6 +277,8 @@ module DocRaptor
221
277
 
222
278
  if attributes[:'input']
223
279
  self.input = attributes[:'input']
280
+ else
281
+ self.input = "html"
224
282
  end
225
283
 
226
284
  if attributes[:'version']
@@ -241,6 +299,7 @@ module DocRaptor
241
299
 
242
300
  end
243
301
 
302
+ # Custom attribute writer method checking allowed values (enum).
244
303
  def input=(input)
245
304
  allowed_values = ["html", "xml", "auto"]
246
305
  if input && !allowed_values.include?(input)
@@ -249,5 +308,139 @@ module DocRaptor
249
308
  @input = input
250
309
  end
251
310
 
311
+ # Check equality by comparing each attribute.
312
+ def ==(o)
313
+ return true if self.equal?(o)
314
+ self.class == o.class &&
315
+ baseurl == o.baseurl &&
316
+ no_xinclude == o.no_xinclude &&
317
+ no_network == o.no_network &&
318
+ http_user == o.http_user &&
319
+ http_password == o.http_password &&
320
+ http_proxy == o.http_proxy &&
321
+ http_timeout == o.http_timeout &&
322
+ insecure == o.insecure &&
323
+ media == o.media &&
324
+ no_author_style == o.no_author_style &&
325
+ no_default_style == o.no_default_style &&
326
+ no_embed_fonts == o.no_embed_fonts &&
327
+ no_subset_fonts == o.no_subset_fonts &&
328
+ no_compress == o.no_compress &&
329
+ encrypt == o.encrypt &&
330
+ key_bits == o.key_bits &&
331
+ user_password == o.user_password &&
332
+ owner_password == o.owner_password &&
333
+ disallow_print == o.disallow_print &&
334
+ disallow_copy == o.disallow_copy &&
335
+ disallow_annotate == o.disallow_annotate &&
336
+ disallow_modify == o.disallow_modify &&
337
+ input == o.input &&
338
+ version == o.version &&
339
+ javascript == o.javascript &&
340
+ css_dpi == o.css_dpi &&
341
+ profile == o.profile
342
+ end
343
+
344
+ # @see the `==` method
345
+ def eql?(o)
346
+ self == o
347
+ end
348
+
349
+ # Calculate hash code according to all attributes.
350
+ def hash
351
+ [baseurl, no_xinclude, no_network, http_user, http_password, http_proxy, http_timeout, insecure, media, no_author_style, no_default_style, no_embed_fonts, no_subset_fonts, no_compress, encrypt, key_bits, user_password, owner_password, disallow_print, disallow_copy, disallow_annotate, disallow_modify, input, version, javascript, css_dpi, profile].hash
352
+ end
353
+
354
+ # build the object from hash
355
+ def build_from_hash(attributes)
356
+ return nil unless attributes.is_a?(Hash)
357
+ self.class.swagger_types.each_pair do |key, type|
358
+ if type =~ /^Array<(.*)>/i
359
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
360
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
361
+ else
362
+ #TODO show warning in debug mode
363
+ end
364
+ elsif !attributes[self.class.attribute_map[key]].nil?
365
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
366
+ else
367
+ # data not found in attributes(hash), not an issue as the data can be optional
368
+ end
369
+ end
370
+
371
+ self
372
+ end
373
+
374
+ def _deserialize(type, value)
375
+ case type.to_sym
376
+ when :DateTime
377
+ DateTime.parse(value)
378
+ when :Date
379
+ Date.parse(value)
380
+ when :String
381
+ value.to_s
382
+ when :Integer
383
+ value.to_i
384
+ when :Float
385
+ value.to_f
386
+ when :BOOLEAN
387
+ if value =~ /^(true|t|yes|y|1)$/i
388
+ true
389
+ else
390
+ false
391
+ end
392
+ when /\AArray<(?<inner_type>.+)>\z/
393
+ inner_type = Regexp.last_match[:inner_type]
394
+ value.map { |v| _deserialize(inner_type, v) }
395
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
396
+ k_type = Regexp.last_match[:k_type]
397
+ v_type = Regexp.last_match[:v_type]
398
+ {}.tap do |hash|
399
+ value.each do |k, v|
400
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
401
+ end
402
+ end
403
+ else # model
404
+ _model = DocRaptor.const_get(type).new
405
+ _model.build_from_hash(value)
406
+ end
407
+ end
408
+
409
+ def to_s
410
+ to_hash.to_s
411
+ end
412
+
413
+ # to_body is an alias to to_body (backward compatibility))
414
+ def to_body
415
+ to_hash
416
+ end
417
+
418
+ # return the object in the form of hash
419
+ def to_hash
420
+ hash = {}
421
+ self.class.attribute_map.each_pair do |attr, param|
422
+ value = self.send(attr)
423
+ next if value.nil?
424
+ hash[param] = _to_hash(value)
425
+ end
426
+ hash
427
+ end
428
+
429
+ # Method to output non-array value in the form of hash
430
+ # For object, use to_hash. Otherwise, just return the value
431
+ def _to_hash(value)
432
+ if value.is_a?(Array)
433
+ value.compact.map{ |v| _to_hash(v) }
434
+ elsif value.is_a?(Hash)
435
+ {}.tap do |hash|
436
+ value.each { |k, v| hash[k] = _to_hash(v) }
437
+ end
438
+ elsif value.respond_to? :to_hash
439
+ value.to_hash
440
+ else
441
+ value
442
+ end
443
+ end
444
+
252
445
  end
253
446
  end
@@ -1,3 +1,3 @@
1
1
  module DocRaptor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docraptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elijah Miller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-11 00:00:00.000000000 Z
12
+ date: 2016-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -228,7 +228,6 @@ files:
228
228
  - lib/docraptor/configuration.rb
229
229
  - lib/docraptor/models/async_doc.rb
230
230
  - lib/docraptor/models/async_doc_status.rb
231
- - lib/docraptor/models/base_object.rb
232
231
  - lib/docraptor/models/doc.rb
233
232
  - lib/docraptor/models/prince_options.rb
234
233
  - lib/docraptor/version.rb
@@ -252,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
251
  version: '0'
253
252
  requirements: []
254
253
  rubyforge_project:
255
- rubygems_version: 2.4.5.1
254
+ rubygems_version: 2.5.1
256
255
  signing_key:
257
256
  specification_version: 4
258
257
  summary: A wrapper for the DocRaptor HTML to PDF/XLS service.
@@ -1,86 +0,0 @@
1
- require 'date'
2
-
3
- module DocRaptor
4
- # base class containing fundamental method such as to_hash, build_from_hash and more
5
- class BaseObject
6
-
7
- # build the object from hash
8
- def build_from_hash(attributes)
9
- return nil unless attributes.is_a?(Hash)
10
- self.class.swagger_types.each_pair do |key, type|
11
- if type =~ /^Array<(.*)>/i
12
- if attributes[self.class.attribute_map[key]].is_a?(Array)
13
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
14
- else
15
- #TODO show warning in debug mode
16
- end
17
- elsif !attributes[self.class.attribute_map[key]].nil?
18
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
19
- else
20
- # data not found in attributes(hash), not an issue as the data can be optional
21
- end
22
- end
23
-
24
- self
25
- end
26
-
27
- def _deserialize(type, value)
28
- case type.to_sym
29
- when :DateTime
30
- DateTime.parse(value)
31
- when :Date
32
- Date.parse(value)
33
- when :String
34
- value.to_s
35
- when :Integer
36
- value.to_i
37
- when :Float
38
- value.to_f
39
- when :BOOLEAN
40
- if value =~ /^(true|t|yes|y|1)$/i
41
- true
42
- else
43
- false
44
- end
45
- else # model
46
- _model = DocRaptor.const_get(type).new
47
- _model.build_from_hash(value)
48
- end
49
- end
50
-
51
- def to_s
52
- to_hash.to_s
53
- end
54
-
55
- # to_body is an alias to to_body (backward compatibility))
56
- def to_body
57
- to_hash
58
- end
59
-
60
- # return the object in the form of hash
61
- def to_hash
62
- hash = {}
63
- self.class.attribute_map.each_pair do |attr, param|
64
- value = self.send(attr)
65
- next if value.nil?
66
- if value.is_a?(Array)
67
- hash[param] = value.compact.map{ |v| _to_hash(v) }
68
- else
69
- hash[param] = _to_hash(value)
70
- end
71
- end
72
- hash
73
- end
74
-
75
- # Method to output non-array value in the form of hash
76
- # For object, use to_hash. Otherwise, just return the value
77
- def _to_hash(value)
78
- if value.respond_to? :to_hash
79
- value.to_hash
80
- else
81
- value
82
- end
83
- end
84
-
85
- end
86
- end