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,14 +1,7 @@
1
1
  require 'uri'
2
- require 'singleton'
3
2
 
4
3
  module DocRaptor
5
4
  class Configuration
6
-
7
- include Singleton
8
-
9
- # Default api client
10
- attr_accessor :api_client
11
-
12
5
  # Defines url scheme
13
6
  attr_accessor :scheme
14
7
 
@@ -44,6 +37,9 @@ module DocRaptor
44
37
  # @return [String]
45
38
  attr_accessor :password
46
39
 
40
+ # Defines the access token (Bearer) used with OAuth2.
41
+ attr_accessor :access_token
42
+
47
43
  # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
48
44
  # details will be logged with `logger.debug` (see the `logger` attribute).
49
45
  # Default to false.
@@ -64,6 +60,10 @@ module DocRaptor
64
60
  # @return [String]
65
61
  attr_accessor :temp_folder_path
66
62
 
63
+ # The time limit for HTTP request in seconds.
64
+ # Default to 0 (never times out).
65
+ attr_accessor :timeout
66
+
67
67
  ### TLS/SSL
68
68
  # Set this to false to skip verifying SSL certificate when calling API from https server.
69
69
  # Default to true.
@@ -91,23 +91,13 @@ module DocRaptor
91
91
 
92
92
  attr_accessor :force_ending_format
93
93
 
94
- class << self
95
- def method_missing(method_name, *args, &block)
96
- config = Configuration.instance
97
- if config.respond_to?(method_name)
98
- config.send(method_name, *args, &block)
99
- else
100
- super
101
- end
102
- end
103
- end
104
-
105
94
  def initialize
106
- @scheme = 'http'
107
- @host = 'localhost:3000'
95
+ @scheme = 'https'
96
+ @host = 'docraptor.com'
108
97
  @base_path = '/'
109
98
  @api_key = {}
110
99
  @api_key_prefix = {}
100
+ @timeout = 0
111
101
  @verify_ssl = true
112
102
  @cert_file = nil
113
103
  @key_file = nil
@@ -115,10 +105,17 @@ module DocRaptor
115
105
  @inject_format = false
116
106
  @force_ending_format = false
117
107
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
108
+
109
+ yield(self) if block_given?
110
+ end
111
+
112
+ # The default Configuration object.
113
+ def self.default
114
+ @@default ||= Configuration.new
118
115
  end
119
116
 
120
- def api_client
121
- @api_client ||= ApiClient.new
117
+ def configure
118
+ yield(self) if block_given?
122
119
  end
123
120
 
124
121
  def scheme=(scheme)
@@ -1,18 +1,20 @@
1
+ require 'date'
2
+
1
3
  module DocRaptor
2
- #
3
- class AsyncDoc < BaseObject
4
+ class AsyncDoc
5
+ # The identifier used to get the status of the document using the status api.
4
6
  attr_accessor :status_id
5
- # attribute mapping from ruby-style variable name to JSON key
7
+
8
+ # Attribute mapping from ruby-style variable name to JSON key.
6
9
  def self.attribute_map
7
10
  {
8
11
 
9
- # The identifier used to get the status of the document using the status api.
10
12
  :'status_id' => :'status_id'
11
13
 
12
14
  }
13
15
  end
14
16
 
15
- # attribute type
17
+ # Attribute type mapping.
16
18
  def self.swagger_types
17
19
  {
18
20
  :'status_id' => :'String'
@@ -21,7 +23,7 @@ module DocRaptor
21
23
  end
22
24
 
23
25
  def initialize(attributes = {})
24
- return if !attributes.is_a?(Hash) || attributes.empty?
26
+ return unless attributes.is_a?(Hash)
25
27
 
26
28
  # convert string to symbol for hash key
27
29
  attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
@@ -33,5 +35,113 @@ module DocRaptor
33
35
 
34
36
  end
35
37
 
38
+ # Check equality by comparing each attribute.
39
+ def ==(o)
40
+ return true if self.equal?(o)
41
+ self.class == o.class &&
42
+ status_id == o.status_id
43
+ end
44
+
45
+ # @see the `==` method
46
+ def eql?(o)
47
+ self == o
48
+ end
49
+
50
+ # Calculate hash code according to all attributes.
51
+ def hash
52
+ [status_id].hash
53
+ end
54
+
55
+ # build the object from hash
56
+ def build_from_hash(attributes)
57
+ return nil unless attributes.is_a?(Hash)
58
+ self.class.swagger_types.each_pair do |key, type|
59
+ if type =~ /^Array<(.*)>/i
60
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
61
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
62
+ else
63
+ #TODO show warning in debug mode
64
+ end
65
+ elsif !attributes[self.class.attribute_map[key]].nil?
66
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
67
+ else
68
+ # data not found in attributes(hash), not an issue as the data can be optional
69
+ end
70
+ end
71
+
72
+ self
73
+ end
74
+
75
+ def _deserialize(type, value)
76
+ case type.to_sym
77
+ when :DateTime
78
+ DateTime.parse(value)
79
+ when :Date
80
+ Date.parse(value)
81
+ when :String
82
+ value.to_s
83
+ when :Integer
84
+ value.to_i
85
+ when :Float
86
+ value.to_f
87
+ when :BOOLEAN
88
+ if value =~ /^(true|t|yes|y|1)$/i
89
+ true
90
+ else
91
+ false
92
+ end
93
+ when /\AArray<(?<inner_type>.+)>\z/
94
+ inner_type = Regexp.last_match[:inner_type]
95
+ value.map { |v| _deserialize(inner_type, v) }
96
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
97
+ k_type = Regexp.last_match[:k_type]
98
+ v_type = Regexp.last_match[:v_type]
99
+ {}.tap do |hash|
100
+ value.each do |k, v|
101
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
102
+ end
103
+ end
104
+ else # model
105
+ _model = DocRaptor.const_get(type).new
106
+ _model.build_from_hash(value)
107
+ end
108
+ end
109
+
110
+ def to_s
111
+ to_hash.to_s
112
+ end
113
+
114
+ # to_body is an alias to to_body (backward compatibility))
115
+ def to_body
116
+ to_hash
117
+ end
118
+
119
+ # return the object in the form of hash
120
+ def to_hash
121
+ hash = {}
122
+ self.class.attribute_map.each_pair do |attr, param|
123
+ value = self.send(attr)
124
+ next if value.nil?
125
+ hash[param] = _to_hash(value)
126
+ end
127
+ hash
128
+ end
129
+
130
+ # Method to output non-array value in the form of hash
131
+ # For object, use to_hash. Otherwise, just return the value
132
+ def _to_hash(value)
133
+ if value.is_a?(Array)
134
+ value.compact.map{ |v| _to_hash(v) }
135
+ elsif value.is_a?(Hash)
136
+ {}.tap do |hash|
137
+ value.each { |k, v| hash[k] = _to_hash(v) }
138
+ end
139
+ elsif value.respond_to? :to_hash
140
+ value.to_hash
141
+ else
142
+ value
143
+ end
144
+ end
145
+
36
146
  end
37
147
  end
@@ -1,33 +1,45 @@
1
+ require 'date'
2
+
1
3
  module DocRaptor
2
- #
3
- class AsyncDocStatus < BaseObject
4
- attr_accessor :status, :download_url, :download_id, :message, :number_of_pages, :validation_errors
5
- # attribute mapping from ruby-style variable name to JSON key
4
+ class AsyncDocStatus
5
+ # The present status of the document. Can be queued, working, completed, and failed.
6
+ attr_accessor :status
7
+
8
+ # The URL where the document can be retrieved. This URL may only be used a few times.
9
+ attr_accessor :download_url
10
+
11
+ # The identifier for downloading the document with the download api.
12
+ attr_accessor :download_id
13
+
14
+ # Additional information.
15
+ attr_accessor :message
16
+
17
+ # Number of PDF pages in document.
18
+ attr_accessor :number_of_pages
19
+
20
+ # Error information.
21
+ attr_accessor :validation_errors
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
6
24
  def self.attribute_map
7
25
  {
8
26
 
9
- # The present status of the document. Can be queued, working, completed, and failed.
10
27
  :'status' => :'status',
11
28
 
12
- # The URL where the document can be retrieved. This URL may only be used a few times.
13
29
  :'download_url' => :'download_url',
14
30
 
15
- # The identifier for downloading the document with the download api.
16
31
  :'download_id' => :'download_id',
17
32
 
18
- # Additional information.
19
33
  :'message' => :'message',
20
34
 
21
- # Number of PDF pages in document.
22
35
  :'number_of_pages' => :'number_of_pages',
23
36
 
24
- # Error information.
25
37
  :'validation_errors' => :'validation_errors'
26
38
 
27
39
  }
28
40
  end
29
41
 
30
- # attribute type
42
+ # Attribute type mapping.
31
43
  def self.swagger_types
32
44
  {
33
45
  :'status' => :'String',
@@ -41,7 +53,7 @@ module DocRaptor
41
53
  end
42
54
 
43
55
  def initialize(attributes = {})
44
- return if !attributes.is_a?(Hash) || attributes.empty?
56
+ return unless attributes.is_a?(Hash)
45
57
 
46
58
  # convert string to symbol for hash key
47
59
  attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
@@ -73,5 +85,118 @@ module DocRaptor
73
85
 
74
86
  end
75
87
 
88
+ # Check equality by comparing each attribute.
89
+ def ==(o)
90
+ return true if self.equal?(o)
91
+ self.class == o.class &&
92
+ status == o.status &&
93
+ download_url == o.download_url &&
94
+ download_id == o.download_id &&
95
+ message == o.message &&
96
+ number_of_pages == o.number_of_pages &&
97
+ validation_errors == o.validation_errors
98
+ end
99
+
100
+ # @see the `==` method
101
+ def eql?(o)
102
+ self == o
103
+ end
104
+
105
+ # Calculate hash code according to all attributes.
106
+ def hash
107
+ [status, download_url, download_id, message, number_of_pages, validation_errors].hash
108
+ end
109
+
110
+ # build the object from hash
111
+ def build_from_hash(attributes)
112
+ return nil unless attributes.is_a?(Hash)
113
+ self.class.swagger_types.each_pair do |key, type|
114
+ if type =~ /^Array<(.*)>/i
115
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
116
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
117
+ else
118
+ #TODO show warning in debug mode
119
+ end
120
+ elsif !attributes[self.class.attribute_map[key]].nil?
121
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
122
+ else
123
+ # data not found in attributes(hash), not an issue as the data can be optional
124
+ end
125
+ end
126
+
127
+ self
128
+ end
129
+
130
+ def _deserialize(type, value)
131
+ case type.to_sym
132
+ when :DateTime
133
+ DateTime.parse(value)
134
+ when :Date
135
+ Date.parse(value)
136
+ when :String
137
+ value.to_s
138
+ when :Integer
139
+ value.to_i
140
+ when :Float
141
+ value.to_f
142
+ when :BOOLEAN
143
+ if value =~ /^(true|t|yes|y|1)$/i
144
+ true
145
+ else
146
+ false
147
+ end
148
+ when /\AArray<(?<inner_type>.+)>\z/
149
+ inner_type = Regexp.last_match[:inner_type]
150
+ value.map { |v| _deserialize(inner_type, v) }
151
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
152
+ k_type = Regexp.last_match[:k_type]
153
+ v_type = Regexp.last_match[:v_type]
154
+ {}.tap do |hash|
155
+ value.each do |k, v|
156
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
157
+ end
158
+ end
159
+ else # model
160
+ _model = DocRaptor.const_get(type).new
161
+ _model.build_from_hash(value)
162
+ end
163
+ end
164
+
165
+ def to_s
166
+ to_hash.to_s
167
+ end
168
+
169
+ # to_body is an alias to to_body (backward compatibility))
170
+ def to_body
171
+ to_hash
172
+ end
173
+
174
+ # return the object in the form of hash
175
+ def to_hash
176
+ hash = {}
177
+ self.class.attribute_map.each_pair do |attr, param|
178
+ value = self.send(attr)
179
+ next if value.nil?
180
+ hash[param] = _to_hash(value)
181
+ end
182
+ hash
183
+ end
184
+
185
+ # Method to output non-array value in the form of hash
186
+ # For object, use to_hash. Otherwise, just return the value
187
+ def _to_hash(value)
188
+ if value.is_a?(Array)
189
+ value.compact.map{ |v| _to_hash(v) }
190
+ elsif value.is_a?(Hash)
191
+ {}.tap do |hash|
192
+ value.each { |k, v| hash[k] = _to_hash(v) }
193
+ end
194
+ elsif value.respond_to? :to_hash
195
+ value.to_hash
196
+ else
197
+ value
198
+ end
199
+ end
200
+
76
201
  end
77
202
  end
@@ -1,51 +1,74 @@
1
+ require 'date'
2
+
1
3
  module DocRaptor
2
- #
3
- class Doc < BaseObject
4
- attr_accessor :name, :document_type, :document_content, :document_url, :test, :strict, :tag, :help, :javascript, :referrer, :callback_url, :prince_options
5
- # attribute mapping from ruby-style variable name to JSON key
4
+ class Doc
5
+ # A name for identifying your document.
6
+ attr_accessor :name
7
+
8
+ # The type of document being created.
9
+ attr_accessor :document_type
10
+
11
+ # The HTML data to be transformed into a document.\nYou must supply content using document_content or document_url.
12
+ attr_accessor :document_content
13
+
14
+ # The URL to fetch the HTML data to be transformed into a document.\nYou must supply content using document_content or document_url.
15
+ attr_accessor :document_url
16
+
17
+ # Enable test mode for this document. Test documents are not charged for but include a watermark.
18
+ attr_accessor :test
19
+
20
+ # Force strict HTML validation.
21
+ attr_accessor :strict
22
+
23
+ # A field for storing a small amount of metadata with this document.
24
+ attr_accessor :tag
25
+
26
+ # Request support help with this request if it succeeds.
27
+ attr_accessor :help
28
+
29
+ # Enable DocRaptor JavaScript parsing. PrinceXML JavaScript parsing is also available elsewhere.
30
+ attr_accessor :javascript
31
+
32
+ # Set HTTP referrer when generating this document.
33
+ attr_accessor :referrer
34
+
35
+ # A URL that will receive a POST request after successfully completing an asynchronous document.\nThe POST data will include download_url and download_id similar to status api responses.\nWARNING: this only works on asynchronous documents.
36
+ attr_accessor :callback_url
37
+
38
+ attr_accessor :prince_options
39
+
40
+ # Attribute mapping from ruby-style variable name to JSON key.
6
41
  def self.attribute_map
7
42
  {
8
43
 
9
- # A name for identifying your document.
10
44
  :'name' => :'name',
11
45
 
12
- # The type of document being created.
13
46
  :'document_type' => :'document_type',
14
47
 
15
- # The HTML data to be transformed into a document.\nYou must supply content using document_content or document_url.
16
48
  :'document_content' => :'document_content',
17
49
 
18
- # The URL to fetch the HTML data to be transformed into a document.\nYou must supply content using document_content or document_url.
19
50
  :'document_url' => :'document_url',
20
51
 
21
- # Enable test mode for this document. Test documents are not charged for but include a watermark.
22
52
  :'test' => :'test',
23
53
 
24
- # Force strict HTML validation.
25
54
  :'strict' => :'strict',
26
55
 
27
- # A field for storing a small amount of metadata with this document.
28
56
  :'tag' => :'tag',
29
57
 
30
- # Request support help with this request if it succeeds.
31
58
  :'help' => :'help',
32
59
 
33
- # Enable DocRaptor JavaScript parsing. PrinceXML JavaScript parsing is also available elsewhere.
34
60
  :'javascript' => :'javascript',
35
61
 
36
- # Set HTTP referrer when generating this document.
37
62
  :'referrer' => :'referrer',
38
63
 
39
- # A URL that will receive a POST request after successfully completing an asynchronous document.\nThe POST data will include download_url and download_id similar to status api responses.\nWARNING: this only works on asynchronous documents.
40
64
  :'callback_url' => :'callback_url',
41
65
 
42
- #
43
66
  :'prince_options' => :'prince_options'
44
67
 
45
68
  }
46
69
  end
47
70
 
48
- # attribute type
71
+ # Attribute type mapping.
49
72
  def self.swagger_types
50
73
  {
51
74
  :'name' => :'String',
@@ -65,7 +88,7 @@ module DocRaptor
65
88
  end
66
89
 
67
90
  def initialize(attributes = {})
68
- return if !attributes.is_a?(Hash) || attributes.empty?
91
+ return unless attributes.is_a?(Hash)
69
92
 
70
93
  # convert string to symbol for hash key
71
94
  attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
@@ -89,10 +112,14 @@ module DocRaptor
89
112
 
90
113
  if attributes[:'test']
91
114
  self.test = attributes[:'test']
115
+ else
116
+ self.test = true
92
117
  end
93
118
 
94
119
  if attributes[:'strict']
95
120
  self.strict = attributes[:'strict']
121
+ else
122
+ self.strict = "none"
96
123
  end
97
124
 
98
125
  if attributes[:'tag']
@@ -101,10 +128,14 @@ module DocRaptor
101
128
 
102
129
  if attributes[:'help']
103
130
  self.help = attributes[:'help']
131
+ else
132
+ self.help = false
104
133
  end
105
134
 
106
135
  if attributes[:'javascript']
107
136
  self.javascript = attributes[:'javascript']
137
+ else
138
+ self.javascript = false
108
139
  end
109
140
 
110
141
  if attributes[:'referrer']
@@ -121,6 +152,7 @@ module DocRaptor
121
152
 
122
153
  end
123
154
 
155
+ # Custom attribute writer method checking allowed values (enum).
124
156
  def document_type=(document_type)
125
157
  allowed_values = ["pdf", "xls", "xlsx"]
126
158
  if document_type && !allowed_values.include?(document_type)
@@ -129,6 +161,7 @@ module DocRaptor
129
161
  @document_type = document_type
130
162
  end
131
163
 
164
+ # Custom attribute writer method checking allowed values (enum).
132
165
  def strict=(strict)
133
166
  allowed_values = ["none"]
134
167
  if strict && !allowed_values.include?(strict)
@@ -137,5 +170,124 @@ module DocRaptor
137
170
  @strict = strict
138
171
  end
139
172
 
173
+ # Check equality by comparing each attribute.
174
+ def ==(o)
175
+ return true if self.equal?(o)
176
+ self.class == o.class &&
177
+ name == o.name &&
178
+ document_type == o.document_type &&
179
+ document_content == o.document_content &&
180
+ document_url == o.document_url &&
181
+ test == o.test &&
182
+ strict == o.strict &&
183
+ tag == o.tag &&
184
+ help == o.help &&
185
+ javascript == o.javascript &&
186
+ referrer == o.referrer &&
187
+ callback_url == o.callback_url &&
188
+ prince_options == o.prince_options
189
+ end
190
+
191
+ # @see the `==` method
192
+ def eql?(o)
193
+ self == o
194
+ end
195
+
196
+ # Calculate hash code according to all attributes.
197
+ def hash
198
+ [name, document_type, document_content, document_url, test, strict, tag, help, javascript, referrer, callback_url, prince_options].hash
199
+ end
200
+
201
+ # build the object from hash
202
+ def build_from_hash(attributes)
203
+ return nil unless attributes.is_a?(Hash)
204
+ self.class.swagger_types.each_pair do |key, type|
205
+ if type =~ /^Array<(.*)>/i
206
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
207
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
208
+ else
209
+ #TODO show warning in debug mode
210
+ end
211
+ elsif !attributes[self.class.attribute_map[key]].nil?
212
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
213
+ else
214
+ # data not found in attributes(hash), not an issue as the data can be optional
215
+ end
216
+ end
217
+
218
+ self
219
+ end
220
+
221
+ def _deserialize(type, value)
222
+ case type.to_sym
223
+ when :DateTime
224
+ DateTime.parse(value)
225
+ when :Date
226
+ Date.parse(value)
227
+ when :String
228
+ value.to_s
229
+ when :Integer
230
+ value.to_i
231
+ when :Float
232
+ value.to_f
233
+ when :BOOLEAN
234
+ if value =~ /^(true|t|yes|y|1)$/i
235
+ true
236
+ else
237
+ false
238
+ end
239
+ when /\AArray<(?<inner_type>.+)>\z/
240
+ inner_type = Regexp.last_match[:inner_type]
241
+ value.map { |v| _deserialize(inner_type, v) }
242
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
243
+ k_type = Regexp.last_match[:k_type]
244
+ v_type = Regexp.last_match[:v_type]
245
+ {}.tap do |hash|
246
+ value.each do |k, v|
247
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
248
+ end
249
+ end
250
+ else # model
251
+ _model = DocRaptor.const_get(type).new
252
+ _model.build_from_hash(value)
253
+ end
254
+ end
255
+
256
+ def to_s
257
+ to_hash.to_s
258
+ end
259
+
260
+ # to_body is an alias to to_body (backward compatibility))
261
+ def to_body
262
+ to_hash
263
+ end
264
+
265
+ # return the object in the form of hash
266
+ def to_hash
267
+ hash = {}
268
+ self.class.attribute_map.each_pair do |attr, param|
269
+ value = self.send(attr)
270
+ next if value.nil?
271
+ hash[param] = _to_hash(value)
272
+ end
273
+ hash
274
+ end
275
+
276
+ # Method to output non-array value in the form of hash
277
+ # For object, use to_hash. Otherwise, just return the value
278
+ def _to_hash(value)
279
+ if value.is_a?(Array)
280
+ value.compact.map{ |v| _to_hash(v) }
281
+ elsif value.is_a?(Hash)
282
+ {}.tap do |hash|
283
+ value.each { |k, v| hash[k] = _to_hash(v) }
284
+ end
285
+ elsif value.respond_to? :to_hash
286
+ value.to_hash
287
+ else
288
+ value
289
+ end
290
+ end
291
+
140
292
  end
141
293
  end