groupdocs_parser_cloud 19.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/groupdocs_parser_cloud.rb +91 -0
- data/lib/groupdocs_parser_cloud/api/file_api.rb +729 -0
- data/lib/groupdocs_parser_cloud/api/folder_api.rb +694 -0
- data/lib/groupdocs_parser_cloud/api/info_api.rb +363 -0
- data/lib/groupdocs_parser_cloud/api/parse_api.rb +411 -0
- data/lib/groupdocs_parser_cloud/api/storage_api.rb +541 -0
- data/lib/groupdocs_parser_cloud/api/template_api.rb +410 -0
- data/lib/groupdocs_parser_cloud/api_client.rb +380 -0
- data/lib/groupdocs_parser_cloud/api_error.rb +64 -0
- data/lib/groupdocs_parser_cloud/configuration.rb +95 -0
- data/lib/groupdocs_parser_cloud/models/container_item.rb +246 -0
- data/lib/groupdocs_parser_cloud/models/container_item_info.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/container_options.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/container_result.rb +216 -0
- data/lib/groupdocs_parser_cloud/models/coordinates.rb +264 -0
- data/lib/groupdocs_parser_cloud/models/create_template_options.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/detector_parameters.rb +266 -0
- data/lib/groupdocs_parser_cloud/models/disc_usage.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/error.rb +244 -0
- data/lib/groupdocs_parser_cloud/models/error_details.rb +229 -0
- data/lib/groupdocs_parser_cloud/models/field.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/field_data.rb +249 -0
- data/lib/groupdocs_parser_cloud/models/field_position.rb +344 -0
- data/lib/groupdocs_parser_cloud/models/file_info.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/file_type.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/file_version.rb +289 -0
- data/lib/groupdocs_parser_cloud/models/file_versions.rb +216 -0
- data/lib/groupdocs_parser_cloud/models/files_list.rb +216 -0
- data/lib/groupdocs_parser_cloud/models/files_upload_result.rb +228 -0
- data/lib/groupdocs_parser_cloud/models/format.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/formats_result.rb +216 -0
- data/lib/groupdocs_parser_cloud/models/formatted_text_options.rb +214 -0
- data/lib/groupdocs_parser_cloud/models/image.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/image_page.rb +231 -0
- data/lib/groupdocs_parser_cloud/models/images_options.rb +254 -0
- data/lib/groupdocs_parser_cloud/models/images_result.rb +228 -0
- data/lib/groupdocs_parser_cloud/models/info_options.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/info_result.rb +244 -0
- data/lib/groupdocs_parser_cloud/models/object_exist.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/page.rb +229 -0
- data/lib/groupdocs_parser_cloud/models/page_area.rb +244 -0
- data/lib/groupdocs_parser_cloud/models/page_table_area.rb +246 -0
- data/lib/groupdocs_parser_cloud/models/page_table_area_cell.rb +274 -0
- data/lib/groupdocs_parser_cloud/models/page_text_area.rb +251 -0
- data/lib/groupdocs_parser_cloud/models/parse_options.rb +244 -0
- data/lib/groupdocs_parser_cloud/models/parse_result.rb +231 -0
- data/lib/groupdocs_parser_cloud/models/parser_options.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/point.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/rectangle.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/size.rb +234 -0
- data/lib/groupdocs_parser_cloud/models/storage_exist.rb +219 -0
- data/lib/groupdocs_parser_cloud/models/storage_file.rb +264 -0
- data/lib/groupdocs_parser_cloud/models/table.rb +244 -0
- data/lib/groupdocs_parser_cloud/models/table_layout.rb +228 -0
- data/lib/groupdocs_parser_cloud/models/template.rb +228 -0
- data/lib/groupdocs_parser_cloud/models/template_options.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/template_result.rb +224 -0
- data/lib/groupdocs_parser_cloud/models/text_options.rb +254 -0
- data/lib/groupdocs_parser_cloud/models/text_page.rb +229 -0
- data/lib/groupdocs_parser_cloud/models/text_result.rb +226 -0
- data/lib/groupdocs_parser_cloud/models/text_style.rb +269 -0
- data/lib/groupdocs_parser_cloud/version.rb +29 -0
- metadata +174 -0
@@ -0,0 +1,363 @@
|
|
1
|
+
# -----------------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose Pty Ltd" file="info.rb">
|
3
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# -----------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
require 'uri'
|
27
|
+
require 'date'
|
28
|
+
|
29
|
+
module GroupDocsParserCloud
|
30
|
+
#
|
31
|
+
# GroupDocs.Parser Cloud API
|
32
|
+
#
|
33
|
+
class InfoApi
|
34
|
+
attr_accessor :config
|
35
|
+
|
36
|
+
#make InfoApi.new private
|
37
|
+
private_class_method :new
|
38
|
+
|
39
|
+
# Initializes new instance of InfoApi
|
40
|
+
#
|
41
|
+
# @param [config] Configuration
|
42
|
+
# @return [InfoApi] New instance of InfoApi
|
43
|
+
def initialize(config)
|
44
|
+
@config = config
|
45
|
+
@api_client = ApiClient.new(config)
|
46
|
+
@access_token = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Initializes new instance of InfoApi
|
50
|
+
#
|
51
|
+
# @param [app_sid] Application identifier (App SID)
|
52
|
+
# @param [app_key] Application private key (App Key)
|
53
|
+
# @return [InfoApi] New instance of InfoApi
|
54
|
+
def self.from_keys(app_sid, app_key)
|
55
|
+
config = Configuration.new(app_sid, app_key)
|
56
|
+
return new(config)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Initializes new instance of InfoApi
|
60
|
+
#
|
61
|
+
# @param [config] Configuration
|
62
|
+
# @return [InfoApi] New instance of InfoApi
|
63
|
+
def self.from_config(config)
|
64
|
+
return new(config)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Retrieve a container items (relative paths) from document to work with formats that contain attachments, ZIP archives etc.
|
68
|
+
#
|
69
|
+
# @param request container_request
|
70
|
+
# @return [ContainerResult]
|
71
|
+
def container(request)
|
72
|
+
data, _status_code, _headers = container_with_http_info(request)
|
73
|
+
data
|
74
|
+
end
|
75
|
+
|
76
|
+
# Retrieve a container items (relative paths) from document to work with formats that contain attachments, ZIP archives etc.
|
77
|
+
#
|
78
|
+
# @param request container_request
|
79
|
+
# @return [Array<(ContainerResult, Fixnum, Hash)>]
|
80
|
+
# ContainerResult data, response status code and response headers
|
81
|
+
def container_with_http_info(request)
|
82
|
+
raise ArgumentError, 'Incorrect request type' unless request.is_a? ContainerRequest
|
83
|
+
|
84
|
+
@api_client.config.logger.debug 'Calling API: InfoApi.container ...' if @api_client.config.debugging
|
85
|
+
# verify the required parameter 'options' is set
|
86
|
+
raise ArgumentError, 'Missing the required parameter options when calling InfoApi.container' if @api_client.config.client_side_validation && request.options.nil?
|
87
|
+
# resource path
|
88
|
+
local_var_path = '/parser/container'
|
89
|
+
|
90
|
+
# query parameters
|
91
|
+
query_params = {}
|
92
|
+
|
93
|
+
# header parameters
|
94
|
+
header_params = {}
|
95
|
+
# HTTP header 'Accept' (if needed)
|
96
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
97
|
+
# HTTP header 'Content-Type'
|
98
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
99
|
+
|
100
|
+
# form parameters
|
101
|
+
form_params = {}
|
102
|
+
|
103
|
+
# http body (model)
|
104
|
+
post_body = @api_client.object_to_http_body(request.options)
|
105
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
106
|
+
header_params: header_params,
|
107
|
+
query_params: query_params,
|
108
|
+
form_params: form_params,
|
109
|
+
body: post_body,
|
110
|
+
access_token: get_access_token,
|
111
|
+
return_type: 'ContainerResult')
|
112
|
+
if @api_client.config.debugging
|
113
|
+
@api_client.config.logger.debug "API called:
|
114
|
+
InfoApi#container\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
115
|
+
end
|
116
|
+
[data, status_code, headers]
|
117
|
+
end
|
118
|
+
|
119
|
+
# Retrieve information about document.
|
120
|
+
#
|
121
|
+
# @param request get_info_request
|
122
|
+
# @return [InfoResult]
|
123
|
+
def get_info(request)
|
124
|
+
data, _status_code, _headers = get_info_with_http_info(request)
|
125
|
+
data
|
126
|
+
end
|
127
|
+
|
128
|
+
# Retrieve information about document.
|
129
|
+
#
|
130
|
+
# @param request get_info_request
|
131
|
+
# @return [Array<(InfoResult, Fixnum, Hash)>]
|
132
|
+
# InfoResult data, response status code and response headers
|
133
|
+
def get_info_with_http_info(request)
|
134
|
+
raise ArgumentError, 'Incorrect request type' unless request.is_a? GetInfoRequest
|
135
|
+
|
136
|
+
@api_client.config.logger.debug 'Calling API: InfoApi.get_info ...' if @api_client.config.debugging
|
137
|
+
# verify the required parameter 'options' is set
|
138
|
+
raise ArgumentError, 'Missing the required parameter options when calling InfoApi.get_info' if @api_client.config.client_side_validation && request.options.nil?
|
139
|
+
# resource path
|
140
|
+
local_var_path = '/parser/info'
|
141
|
+
|
142
|
+
# query parameters
|
143
|
+
query_params = {}
|
144
|
+
|
145
|
+
# header parameters
|
146
|
+
header_params = {}
|
147
|
+
# HTTP header 'Accept' (if needed)
|
148
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
149
|
+
# HTTP header 'Content-Type'
|
150
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
151
|
+
|
152
|
+
# form parameters
|
153
|
+
form_params = {}
|
154
|
+
|
155
|
+
# http body (model)
|
156
|
+
post_body = @api_client.object_to_http_body(request.options)
|
157
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
158
|
+
header_params: header_params,
|
159
|
+
query_params: query_params,
|
160
|
+
form_params: form_params,
|
161
|
+
body: post_body,
|
162
|
+
access_token: get_access_token,
|
163
|
+
return_type: 'InfoResult')
|
164
|
+
if @api_client.config.debugging
|
165
|
+
@api_client.config.logger.debug "API called:
|
166
|
+
InfoApi#get_info\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
167
|
+
end
|
168
|
+
[data, status_code, headers]
|
169
|
+
end
|
170
|
+
|
171
|
+
# List supported file formats.
|
172
|
+
#
|
173
|
+
# @return [FormatsResult]
|
174
|
+
def get_supported_file_formats()
|
175
|
+
data, _status_code, _headers = get_supported_file_formats_with_http_info()
|
176
|
+
data
|
177
|
+
end
|
178
|
+
|
179
|
+
# List supported file formats.
|
180
|
+
#
|
181
|
+
|
182
|
+
# @return [Array<(FormatsResult, Fixnum, Hash)>]
|
183
|
+
# FormatsResult data, response status code and response headers
|
184
|
+
def get_supported_file_formats_with_http_info()
|
185
|
+
|
186
|
+
|
187
|
+
@api_client.config.logger.debug 'Calling API: InfoApi.get_supported_file_formats ...' if @api_client.config.debugging
|
188
|
+
# resource path
|
189
|
+
local_var_path = '/parser/formats'
|
190
|
+
|
191
|
+
# query parameters
|
192
|
+
query_params = {}
|
193
|
+
|
194
|
+
# header parameters
|
195
|
+
header_params = {}
|
196
|
+
# HTTP header 'Accept' (if needed)
|
197
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
198
|
+
# HTTP header 'Content-Type'
|
199
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
200
|
+
|
201
|
+
# form parameters
|
202
|
+
form_params = {}
|
203
|
+
|
204
|
+
# http body (model)
|
205
|
+
post_body = nil
|
206
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
207
|
+
header_params: header_params,
|
208
|
+
query_params: query_params,
|
209
|
+
form_params: form_params,
|
210
|
+
body: post_body,
|
211
|
+
access_token: get_access_token,
|
212
|
+
return_type: 'FormatsResult')
|
213
|
+
if @api_client.config.debugging
|
214
|
+
@api_client.config.logger.debug "API called:
|
215
|
+
InfoApi#get_supported_file_formats\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
216
|
+
end
|
217
|
+
[data, status_code, headers]
|
218
|
+
end
|
219
|
+
|
220
|
+
#
|
221
|
+
# Helper method to convert first letter to downcase
|
222
|
+
#
|
223
|
+
private def downcase_first_letter(str)
|
224
|
+
value = str[0].downcase + str[1..-1]
|
225
|
+
value
|
226
|
+
end
|
227
|
+
|
228
|
+
#
|
229
|
+
# Retrieves access token
|
230
|
+
#
|
231
|
+
private def get_access_token
|
232
|
+
if @access_token.nil? then
|
233
|
+
request_access_token
|
234
|
+
end
|
235
|
+
|
236
|
+
@access_token
|
237
|
+
end
|
238
|
+
|
239
|
+
#
|
240
|
+
# Gets a access token from server
|
241
|
+
#
|
242
|
+
private def request_access_token
|
243
|
+
auth_config = Configuration.new(@config.app_sid, @config.app_key)
|
244
|
+
auth_config.api_base_url = @config.api_base_url
|
245
|
+
auth_config.debugging = @config.debugging
|
246
|
+
auth_config.logger = @config.logger
|
247
|
+
auth_config.temp_folder_path = @config.temp_folder_path
|
248
|
+
auth_config.client_side_validation = @config.client_side_validation
|
249
|
+
auth_config.api_version = ''
|
250
|
+
|
251
|
+
auth_api_client = ApiClient.new(auth_config)
|
252
|
+
|
253
|
+
request_url = "/connect/token"
|
254
|
+
post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
|
255
|
+
|
256
|
+
data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
|
257
|
+
|
258
|
+
@access_token = data[:access_token]
|
259
|
+
|
260
|
+
expires_in_seconds = data[:expires_in].to_i - 5 * 60
|
261
|
+
expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
|
262
|
+
@access_token_expires_at = DateTime.now + expires_in_days
|
263
|
+
end
|
264
|
+
|
265
|
+
# requires all files inside a directory from current dir
|
266
|
+
# @param _dir can be relative path like '/lib' or "../lib"
|
267
|
+
private def require_all(_dir)
|
268
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
|
269
|
+
require file
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
#
|
275
|
+
# --------------------------------------------------------------------------------------------------------------------
|
276
|
+
# <copyright company="Aspose Pty Ltd" file="container_request.rb">
|
277
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
278
|
+
# </copyright>
|
279
|
+
# <summary>
|
280
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
281
|
+
# of this software and associated documentation files (the "Software"), to deal
|
282
|
+
# in the Software without restriction, including without limitation the rights
|
283
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
284
|
+
# copies of the Software, and to permit persons to whom the Software is
|
285
|
+
# furnished to do so, subject to the following conditions:
|
286
|
+
#
|
287
|
+
# The above copyright notice and this permission notice shall be included in all
|
288
|
+
# copies or substantial portions of the Software.
|
289
|
+
#
|
290
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
291
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
292
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
293
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
294
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
295
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
296
|
+
# SOFTWARE.
|
297
|
+
# </summary>
|
298
|
+
# --------------------------------------------------------------------------------------------------------------------
|
299
|
+
#
|
300
|
+
|
301
|
+
module GroupDocsParserCloud
|
302
|
+
|
303
|
+
#
|
304
|
+
# Request model for container operation.
|
305
|
+
#
|
306
|
+
class ContainerRequest
|
307
|
+
|
308
|
+
# Container options.
|
309
|
+
attr_accessor :options
|
310
|
+
|
311
|
+
#
|
312
|
+
# Initializes a new instance.
|
313
|
+
# @param options Container options.
|
314
|
+
def initialize(options)
|
315
|
+
self.options = options
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
#
|
320
|
+
# --------------------------------------------------------------------------------------------------------------------
|
321
|
+
# <copyright company="Aspose Pty Ltd" file="get_info_request.rb">
|
322
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
323
|
+
# </copyright>
|
324
|
+
# <summary>
|
325
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
326
|
+
# of this software and associated documentation files (the "Software"), to deal
|
327
|
+
# in the Software without restriction, including without limitation the rights
|
328
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
329
|
+
# copies of the Software, and to permit persons to whom the Software is
|
330
|
+
# furnished to do so, subject to the following conditions:
|
331
|
+
#
|
332
|
+
# The above copyright notice and this permission notice shall be included in all
|
333
|
+
# copies or substantial portions of the Software.
|
334
|
+
#
|
335
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
336
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
337
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
338
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
339
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
340
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
341
|
+
# SOFTWARE.
|
342
|
+
# </summary>
|
343
|
+
# --------------------------------------------------------------------------------------------------------------------
|
344
|
+
#
|
345
|
+
|
346
|
+
module GroupDocsParserCloud
|
347
|
+
|
348
|
+
#
|
349
|
+
# Request model for get_info operation.
|
350
|
+
#
|
351
|
+
class GetInfoRequest
|
352
|
+
|
353
|
+
# Info options.
|
354
|
+
attr_accessor :options
|
355
|
+
|
356
|
+
#
|
357
|
+
# Initializes a new instance.
|
358
|
+
# @param options Info options.
|
359
|
+
def initialize(options)
|
360
|
+
self.options = options
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
@@ -0,0 +1,411 @@
|
|
1
|
+
# -----------------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose Pty Ltd" file="parse.rb">
|
3
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# -----------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
require 'uri'
|
27
|
+
require 'date'
|
28
|
+
|
29
|
+
module GroupDocsParserCloud
|
30
|
+
#
|
31
|
+
# GroupDocs.Parser Cloud API
|
32
|
+
#
|
33
|
+
class ParseApi
|
34
|
+
attr_accessor :config
|
35
|
+
|
36
|
+
#make ParseApi.new private
|
37
|
+
private_class_method :new
|
38
|
+
|
39
|
+
# Initializes new instance of ParseApi
|
40
|
+
#
|
41
|
+
# @param [config] Configuration
|
42
|
+
# @return [ParseApi] New instance of ParseApi
|
43
|
+
def initialize(config)
|
44
|
+
@config = config
|
45
|
+
@api_client = ApiClient.new(config)
|
46
|
+
@access_token = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Initializes new instance of ParseApi
|
50
|
+
#
|
51
|
+
# @param [app_sid] Application identifier (App SID)
|
52
|
+
# @param [app_key] Application private key (App Key)
|
53
|
+
# @return [ParseApi] New instance of ParseApi
|
54
|
+
def self.from_keys(app_sid, app_key)
|
55
|
+
config = Configuration.new(app_sid, app_key)
|
56
|
+
return new(config)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Initializes new instance of ParseApi
|
60
|
+
#
|
61
|
+
# @param [config] Configuration
|
62
|
+
# @return [ParseApi] New instance of ParseApi
|
63
|
+
def self.from_config(config)
|
64
|
+
return new(config)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Extract images from document.
|
68
|
+
#
|
69
|
+
# @param request images_request
|
70
|
+
# @return [ImagesResult]
|
71
|
+
def images(request)
|
72
|
+
data, _status_code, _headers = images_with_http_info(request)
|
73
|
+
data
|
74
|
+
end
|
75
|
+
|
76
|
+
# Extract images from document.
|
77
|
+
#
|
78
|
+
# @param request images_request
|
79
|
+
# @return [Array<(ImagesResult, Fixnum, Hash)>]
|
80
|
+
# ImagesResult data, response status code and response headers
|
81
|
+
def images_with_http_info(request)
|
82
|
+
raise ArgumentError, 'Incorrect request type' unless request.is_a? ImagesRequest
|
83
|
+
|
84
|
+
@api_client.config.logger.debug 'Calling API: ParseApi.images ...' if @api_client.config.debugging
|
85
|
+
# verify the required parameter 'options' is set
|
86
|
+
raise ArgumentError, 'Missing the required parameter options when calling ParseApi.images' if @api_client.config.client_side_validation && request.options.nil?
|
87
|
+
# resource path
|
88
|
+
local_var_path = '/parser/images'
|
89
|
+
|
90
|
+
# query parameters
|
91
|
+
query_params = {}
|
92
|
+
|
93
|
+
# header parameters
|
94
|
+
header_params = {}
|
95
|
+
# HTTP header 'Accept' (if needed)
|
96
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
97
|
+
# HTTP header 'Content-Type'
|
98
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
99
|
+
|
100
|
+
# form parameters
|
101
|
+
form_params = {}
|
102
|
+
|
103
|
+
# http body (model)
|
104
|
+
post_body = @api_client.object_to_http_body(request.options)
|
105
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
106
|
+
header_params: header_params,
|
107
|
+
query_params: query_params,
|
108
|
+
form_params: form_params,
|
109
|
+
body: post_body,
|
110
|
+
access_token: get_access_token,
|
111
|
+
return_type: 'ImagesResult')
|
112
|
+
if @api_client.config.debugging
|
113
|
+
@api_client.config.logger.debug "API called:
|
114
|
+
ParseApi#images\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
115
|
+
end
|
116
|
+
[data, status_code, headers]
|
117
|
+
end
|
118
|
+
|
119
|
+
# Extract document data by a predefined template.
|
120
|
+
#
|
121
|
+
# @param request parse_request
|
122
|
+
# @return [ParseResult]
|
123
|
+
def parse(request)
|
124
|
+
data, _status_code, _headers = parse_with_http_info(request)
|
125
|
+
data
|
126
|
+
end
|
127
|
+
|
128
|
+
# Extract document data by a predefined template.
|
129
|
+
#
|
130
|
+
# @param request parse_request
|
131
|
+
# @return [Array<(ParseResult, Fixnum, Hash)>]
|
132
|
+
# ParseResult data, response status code and response headers
|
133
|
+
def parse_with_http_info(request)
|
134
|
+
raise ArgumentError, 'Incorrect request type' unless request.is_a? ParseRequest
|
135
|
+
|
136
|
+
@api_client.config.logger.debug 'Calling API: ParseApi.parse ...' if @api_client.config.debugging
|
137
|
+
# verify the required parameter 'options' is set
|
138
|
+
raise ArgumentError, 'Missing the required parameter options when calling ParseApi.parse' if @api_client.config.client_side_validation && request.options.nil?
|
139
|
+
# resource path
|
140
|
+
local_var_path = '/parser/parse'
|
141
|
+
|
142
|
+
# query parameters
|
143
|
+
query_params = {}
|
144
|
+
|
145
|
+
# header parameters
|
146
|
+
header_params = {}
|
147
|
+
# HTTP header 'Accept' (if needed)
|
148
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
149
|
+
# HTTP header 'Content-Type'
|
150
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
151
|
+
|
152
|
+
# form parameters
|
153
|
+
form_params = {}
|
154
|
+
|
155
|
+
# http body (model)
|
156
|
+
post_body = @api_client.object_to_http_body(request.options)
|
157
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
158
|
+
header_params: header_params,
|
159
|
+
query_params: query_params,
|
160
|
+
form_params: form_params,
|
161
|
+
body: post_body,
|
162
|
+
access_token: get_access_token,
|
163
|
+
return_type: 'ParseResult')
|
164
|
+
if @api_client.config.debugging
|
165
|
+
@api_client.config.logger.debug "API called:
|
166
|
+
ParseApi#parse\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
167
|
+
end
|
168
|
+
[data, status_code, headers]
|
169
|
+
end
|
170
|
+
|
171
|
+
# Extract text from document.
|
172
|
+
#
|
173
|
+
# @param request text_request
|
174
|
+
# @return [TextResult]
|
175
|
+
def text(request)
|
176
|
+
data, _status_code, _headers = text_with_http_info(request)
|
177
|
+
data
|
178
|
+
end
|
179
|
+
|
180
|
+
# Extract text from document.
|
181
|
+
#
|
182
|
+
# @param request text_request
|
183
|
+
# @return [Array<(TextResult, Fixnum, Hash)>]
|
184
|
+
# TextResult data, response status code and response headers
|
185
|
+
def text_with_http_info(request)
|
186
|
+
raise ArgumentError, 'Incorrect request type' unless request.is_a? TextRequest
|
187
|
+
|
188
|
+
@api_client.config.logger.debug 'Calling API: ParseApi.text ...' if @api_client.config.debugging
|
189
|
+
# verify the required parameter 'options' is set
|
190
|
+
raise ArgumentError, 'Missing the required parameter options when calling ParseApi.text' if @api_client.config.client_side_validation && request.options.nil?
|
191
|
+
# resource path
|
192
|
+
local_var_path = '/parser/text'
|
193
|
+
|
194
|
+
# query parameters
|
195
|
+
query_params = {}
|
196
|
+
|
197
|
+
# header parameters
|
198
|
+
header_params = {}
|
199
|
+
# HTTP header 'Accept' (if needed)
|
200
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
201
|
+
# HTTP header 'Content-Type'
|
202
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
203
|
+
|
204
|
+
# form parameters
|
205
|
+
form_params = {}
|
206
|
+
|
207
|
+
# http body (model)
|
208
|
+
post_body = @api_client.object_to_http_body(request.options)
|
209
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path,
|
210
|
+
header_params: header_params,
|
211
|
+
query_params: query_params,
|
212
|
+
form_params: form_params,
|
213
|
+
body: post_body,
|
214
|
+
access_token: get_access_token,
|
215
|
+
return_type: 'TextResult')
|
216
|
+
if @api_client.config.debugging
|
217
|
+
@api_client.config.logger.debug "API called:
|
218
|
+
ParseApi#text\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
219
|
+
end
|
220
|
+
[data, status_code, headers]
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# Helper method to convert first letter to downcase
|
225
|
+
#
|
226
|
+
private def downcase_first_letter(str)
|
227
|
+
value = str[0].downcase + str[1..-1]
|
228
|
+
value
|
229
|
+
end
|
230
|
+
|
231
|
+
#
|
232
|
+
# Retrieves access token
|
233
|
+
#
|
234
|
+
private def get_access_token
|
235
|
+
if @access_token.nil? then
|
236
|
+
request_access_token
|
237
|
+
end
|
238
|
+
|
239
|
+
@access_token
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# Gets a access token from server
|
244
|
+
#
|
245
|
+
private def request_access_token
|
246
|
+
auth_config = Configuration.new(@config.app_sid, @config.app_key)
|
247
|
+
auth_config.api_base_url = @config.api_base_url
|
248
|
+
auth_config.debugging = @config.debugging
|
249
|
+
auth_config.logger = @config.logger
|
250
|
+
auth_config.temp_folder_path = @config.temp_folder_path
|
251
|
+
auth_config.client_side_validation = @config.client_side_validation
|
252
|
+
auth_config.api_version = ''
|
253
|
+
|
254
|
+
auth_api_client = ApiClient.new(auth_config)
|
255
|
+
|
256
|
+
request_url = "/connect/token"
|
257
|
+
post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
|
258
|
+
|
259
|
+
data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
|
260
|
+
|
261
|
+
@access_token = data[:access_token]
|
262
|
+
|
263
|
+
expires_in_seconds = data[:expires_in].to_i - 5 * 60
|
264
|
+
expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
|
265
|
+
@access_token_expires_at = DateTime.now + expires_in_days
|
266
|
+
end
|
267
|
+
|
268
|
+
# requires all files inside a directory from current dir
|
269
|
+
# @param _dir can be relative path like '/lib' or "../lib"
|
270
|
+
private def require_all(_dir)
|
271
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
|
272
|
+
require file
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
#
|
278
|
+
# --------------------------------------------------------------------------------------------------------------------
|
279
|
+
# <copyright company="Aspose Pty Ltd" file="images_request.rb">
|
280
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
281
|
+
# </copyright>
|
282
|
+
# <summary>
|
283
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
284
|
+
# of this software and associated documentation files (the "Software"), to deal
|
285
|
+
# in the Software without restriction, including without limitation the rights
|
286
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
287
|
+
# copies of the Software, and to permit persons to whom the Software is
|
288
|
+
# furnished to do so, subject to the following conditions:
|
289
|
+
#
|
290
|
+
# The above copyright notice and this permission notice shall be included in all
|
291
|
+
# copies or substantial portions of the Software.
|
292
|
+
#
|
293
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
294
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
295
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
296
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
297
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
298
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
299
|
+
# SOFTWARE.
|
300
|
+
# </summary>
|
301
|
+
# --------------------------------------------------------------------------------------------------------------------
|
302
|
+
#
|
303
|
+
|
304
|
+
module GroupDocsParserCloud
|
305
|
+
|
306
|
+
#
|
307
|
+
# Request model for images operation.
|
308
|
+
#
|
309
|
+
class ImagesRequest
|
310
|
+
|
311
|
+
# Extract image options.
|
312
|
+
attr_accessor :options
|
313
|
+
|
314
|
+
#
|
315
|
+
# Initializes a new instance.
|
316
|
+
# @param options Extract image options.
|
317
|
+
def initialize(options)
|
318
|
+
self.options = options
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
#
|
323
|
+
# --------------------------------------------------------------------------------------------------------------------
|
324
|
+
# <copyright company="Aspose Pty Ltd" file="parse_request.rb">
|
325
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
326
|
+
# </copyright>
|
327
|
+
# <summary>
|
328
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
329
|
+
# of this software and associated documentation files (the "Software"), to deal
|
330
|
+
# in the Software without restriction, including without limitation the rights
|
331
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
332
|
+
# copies of the Software, and to permit persons to whom the Software is
|
333
|
+
# furnished to do so, subject to the following conditions:
|
334
|
+
#
|
335
|
+
# The above copyright notice and this permission notice shall be included in all
|
336
|
+
# copies or substantial portions of the Software.
|
337
|
+
#
|
338
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
339
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
340
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
341
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
342
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
343
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
344
|
+
# SOFTWARE.
|
345
|
+
# </summary>
|
346
|
+
# --------------------------------------------------------------------------------------------------------------------
|
347
|
+
#
|
348
|
+
|
349
|
+
module GroupDocsParserCloud
|
350
|
+
|
351
|
+
#
|
352
|
+
# Request model for parse operation.
|
353
|
+
#
|
354
|
+
class ParseRequest
|
355
|
+
|
356
|
+
# Parse options.
|
357
|
+
attr_accessor :options
|
358
|
+
|
359
|
+
#
|
360
|
+
# Initializes a new instance.
|
361
|
+
# @param options Parse options.
|
362
|
+
def initialize(options)
|
363
|
+
self.options = options
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
#
|
368
|
+
# --------------------------------------------------------------------------------------------------------------------
|
369
|
+
# <copyright company="Aspose Pty Ltd" file="text_request.rb">
|
370
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
371
|
+
# </copyright>
|
372
|
+
# <summary>
|
373
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
374
|
+
# of this software and associated documentation files (the "Software"), to deal
|
375
|
+
# in the Software without restriction, including without limitation the rights
|
376
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
377
|
+
# copies of the Software, and to permit persons to whom the Software is
|
378
|
+
# furnished to do so, subject to the following conditions:
|
379
|
+
#
|
380
|
+
# The above copyright notice and this permission notice shall be included in all
|
381
|
+
# copies or substantial portions of the Software.
|
382
|
+
#
|
383
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
384
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
385
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
386
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
387
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
388
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
389
|
+
# SOFTWARE.
|
390
|
+
# </summary>
|
391
|
+
# --------------------------------------------------------------------------------------------------------------------
|
392
|
+
#
|
393
|
+
|
394
|
+
module GroupDocsParserCloud
|
395
|
+
|
396
|
+
#
|
397
|
+
# Request model for text operation.
|
398
|
+
#
|
399
|
+
class TextRequest
|
400
|
+
|
401
|
+
# Extract text options.
|
402
|
+
attr_accessor :options
|
403
|
+
|
404
|
+
#
|
405
|
+
# Initializes a new instance.
|
406
|
+
# @param options Extract text options.
|
407
|
+
def initialize(options)
|
408
|
+
self.options = options
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|