groupdocs_annotation_cloud 18.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/lib/groupdocs_annotation_cloud/api/annotation_api.rb +344 -0
  3. data/lib/groupdocs_annotation_cloud/api/image_info_api.rb +218 -0
  4. data/lib/groupdocs_annotation_cloud/api/image_pages_api.rb +395 -0
  5. data/lib/groupdocs_annotation_cloud/api/pdf_file_api.rb +281 -0
  6. data/lib/groupdocs_annotation_cloud/api_client.rb +390 -0
  7. data/lib/groupdocs_annotation_cloud/api_error.rb +56 -0
  8. data/lib/groupdocs_annotation_cloud/configuration.rb +95 -0
  9. data/lib/groupdocs_annotation_cloud/models/annotation_api_link.rb +236 -0
  10. data/lib/groupdocs_annotation_cloud/models/annotation_info.rb +504 -0
  11. data/lib/groupdocs_annotation_cloud/models/annotation_reply_info.rb +271 -0
  12. data/lib/groupdocs_annotation_cloud/models/document_info.rb +264 -0
  13. data/lib/groupdocs_annotation_cloud/models/image_page.rb +214 -0
  14. data/lib/groupdocs_annotation_cloud/models/image_pages.rb +219 -0
  15. data/lib/groupdocs_annotation_cloud/models/link.rb +236 -0
  16. data/lib/groupdocs_annotation_cloud/models/link_element.rb +206 -0
  17. data/lib/groupdocs_annotation_cloud/models/page_info.rb +258 -0
  18. data/lib/groupdocs_annotation_cloud/models/point.rb +216 -0
  19. data/lib/groupdocs_annotation_cloud/models/rectangle.rb +236 -0
  20. data/lib/groupdocs_annotation_cloud/models/requests/delete_clean_document_request.rb +53 -0
  21. data/lib/groupdocs_annotation_cloud/models/requests/delete_pages_request.rb +49 -0
  22. data/lib/groupdocs_annotation_cloud/models/requests/get_import_request.rb +53 -0
  23. data/lib/groupdocs_annotation_cloud/models/requests/get_info_request.rb +53 -0
  24. data/lib/groupdocs_annotation_cloud/models/requests/get_page_request.rb +53 -0
  25. data/lib/groupdocs_annotation_cloud/models/requests/get_pages_request.rb +49 -0
  26. data/lib/groupdocs_annotation_cloud/models/requests/get_pdf_request.rb +53 -0
  27. data/lib/groupdocs_annotation_cloud/models/requests/get_pdf_stream_request.rb +53 -0
  28. data/lib/groupdocs_annotation_cloud/models/requests/post_pages_request.rb +53 -0
  29. data/lib/groupdocs_annotation_cloud/models/requests/put_export_request.rb +57 -0
  30. data/lib/groupdocs_annotation_cloud/models/row_info.rb +276 -0
  31. data/lib/groupdocs_annotation_cloud/models/value_type.rb +196 -0
  32. data/lib/groupdocs_annotation_cloud/version.rb +29 -0
  33. data/lib/groupdocs_annotation_cloud.rb +80 -0
  34. metadata +164 -0
@@ -0,0 +1,395 @@
1
+ # -----------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="imagePages.rb">
3
+ # Copyright (c) 2003-2018 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 GroupDocsAnnotationCloud
30
+ #
31
+ # GroupDocs.Annotation Cloud API
32
+ #
33
+ class ImagePagesApi
34
+ attr_accessor :config
35
+
36
+ #make ImagePagesApi.new private
37
+ private_class_method :new
38
+
39
+ # Initializes new instance of ImagePagesApi
40
+ #
41
+ # @param [config] Configuration
42
+ # @return [ImagePagesApi] New instance of ImagePagesApi
43
+ def initialize(config)
44
+ @config = config
45
+ @api_client = ApiClient.new(config)
46
+ require_all '../models/requests'
47
+
48
+ @access_token = nil
49
+ end
50
+
51
+ # Initializes new instance of ImagePagesApi
52
+ #
53
+ # @param [app_sid] Application identifier (App SID)
54
+ # @param [app_key] Application private key (App Key)
55
+ # @return [ImagePagesApi] New instance of ImagePagesApi
56
+ def self.from_keys(app_sid, app_key)
57
+ config = Configuration.new(app_sid, app_key)
58
+ return new(config)
59
+ end
60
+
61
+ # Initializes new instance of ImagePagesApi
62
+ #
63
+ # @param [config] Configuration
64
+ # @return [ImagePagesApi] New instance of ImagePagesApi
65
+ def self.from_config(config)
66
+ return new(config)
67
+ end
68
+
69
+ # Removes document's pages as image.
70
+ #
71
+ # @param request delete_pages_request
72
+ # @return [File]
73
+ def delete_pages(request)
74
+ data, _status_code, _headers = delete_pages_with_http_info(request)
75
+ data
76
+ end
77
+
78
+ # Removes document's pages as image.
79
+ #
80
+ # @param request delete_pages_request
81
+ # @return [Array<(File, Fixnum, Hash)>]
82
+ # File data, response status code and response headers
83
+ def delete_pages_with_http_info(request)
84
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? DeletePagesRequest
85
+
86
+ @api_client.config.logger.debug 'Calling API: ImagePagesApi.delete_pages ...' if @api_client.config.debugging
87
+ # verify the required parameter 'name' is set
88
+ raise ArgumentError, 'Missing the required parameter name when calling ImagePagesApi.delete_pages' if @api_client.config.client_side_validation && request.name.nil?
89
+ # resource path
90
+ local_var_path = '/annotation/{name}/image/pages'
91
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
92
+
93
+ # query parameters
94
+ query_params = {}
95
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
96
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
97
+ else
98
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
99
+ end
100
+
101
+ # header parameters
102
+ header_params = {}
103
+ # HTTP header 'Accept' (if needed)
104
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
105
+ # HTTP header 'Content-Type'
106
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
107
+
108
+ # form parameters
109
+ form_params = {}
110
+
111
+ # http body (model)
112
+ post_body = nil
113
+ data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
114
+ header_params: header_params,
115
+ query_params: query_params,
116
+ form_params: form_params,
117
+ body: post_body,
118
+ access_token: get_access_token,
119
+ return_type: 'File')
120
+ if @api_client.config.debugging
121
+ @api_client.config.logger.debug "API called:
122
+ ImagePagesApi#delete_pages\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
123
+ end
124
+ [data, status_code, headers]
125
+ end
126
+
127
+ # Downloads document's page as image.
128
+ #
129
+ # @param request get_page_request
130
+ # @return [ImagePage]
131
+ def get_page(request)
132
+ data, _status_code, _headers = get_page_with_http_info(request)
133
+ data
134
+ end
135
+
136
+ # Downloads document's page as image.
137
+ #
138
+ # @param request get_page_request
139
+ # @return [Array<(ImagePage, Fixnum, Hash)>]
140
+ # ImagePage data, response status code and response headers
141
+ def get_page_with_http_info(request)
142
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? GetPageRequest
143
+
144
+ @api_client.config.logger.debug 'Calling API: ImagePagesApi.get_page ...' if @api_client.config.debugging
145
+ # verify the required parameter 'name' is set
146
+ raise ArgumentError, 'Missing the required parameter name when calling ImagePagesApi.get_page' if @api_client.config.client_side_validation && request.name.nil?
147
+ # verify the required parameter 'page_number' is set
148
+ raise ArgumentError, 'Missing the required parameter page_number when calling ImagePagesApi.get_page' if @api_client.config.client_side_validation && request.page_number.nil?
149
+ # resource path
150
+ local_var_path = '/annotation/{name}/image/pages/{pageNumber}'
151
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
152
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('PageNumber') + '}', request.page_number.to_s)
153
+
154
+ # query parameters
155
+ query_params = {}
156
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
157
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
158
+ else
159
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
160
+ end
161
+
162
+ # header parameters
163
+ header_params = {}
164
+ # HTTP header 'Accept' (if needed)
165
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
166
+ # HTTP header 'Content-Type'
167
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
168
+
169
+ # form parameters
170
+ form_params = {}
171
+
172
+ # http body (model)
173
+ post_body = nil
174
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
175
+ header_params: header_params,
176
+ query_params: query_params,
177
+ form_params: form_params,
178
+ body: post_body,
179
+ access_token: get_access_token,
180
+ return_type: 'ImagePage')
181
+ if @api_client.config.debugging
182
+ @api_client.config.logger.debug "API called:
183
+ ImagePagesApi#get_page\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
184
+ end
185
+ [data, status_code, headers]
186
+ end
187
+
188
+ # Retrieves document's pages as images.
189
+ #
190
+ # @param request get_pages_request
191
+ # @return [ImagePages]
192
+ def get_pages(request)
193
+ data, _status_code, _headers = get_pages_with_http_info(request)
194
+ data
195
+ end
196
+
197
+ # Retrieves document's pages as images.
198
+ #
199
+ # @param request get_pages_request
200
+ # @return [Array<(ImagePages, Fixnum, Hash)>]
201
+ # ImagePages data, response status code and response headers
202
+ def get_pages_with_http_info(request)
203
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? GetPagesRequest
204
+
205
+ @api_client.config.logger.debug 'Calling API: ImagePagesApi.get_pages ...' if @api_client.config.debugging
206
+ # verify the required parameter 'name' is set
207
+ raise ArgumentError, 'Missing the required parameter name when calling ImagePagesApi.get_pages' if @api_client.config.client_side_validation && request.name.nil?
208
+ # resource path
209
+ local_var_path = '/annotation/{name}/image/pages'
210
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
211
+
212
+ # query parameters
213
+ query_params = {}
214
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
215
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
216
+ else
217
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
218
+ end
219
+
220
+ # header parameters
221
+ header_params = {}
222
+ # HTTP header 'Accept' (if needed)
223
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
224
+ # HTTP header 'Content-Type'
225
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
226
+
227
+ # form parameters
228
+ form_params = {}
229
+
230
+ # http body (model)
231
+ post_body = nil
232
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
233
+ header_params: header_params,
234
+ query_params: query_params,
235
+ form_params: form_params,
236
+ body: post_body,
237
+ access_token: get_access_token,
238
+ return_type: 'ImagePages')
239
+ if @api_client.config.debugging
240
+ @api_client.config.logger.debug "API called:
241
+ ImagePagesApi#get_pages\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
242
+ end
243
+ [data, status_code, headers]
244
+ end
245
+
246
+ # Creates document's pages as image.
247
+ #
248
+ # @param request post_pages_request
249
+ # @return [ImagePages]
250
+ def post_pages(request)
251
+ data, _status_code, _headers = post_pages_with_http_info(request)
252
+ data
253
+ end
254
+
255
+ # Creates document's pages as image.
256
+ #
257
+ # @param request post_pages_request
258
+ # @return [Array<(ImagePages, Fixnum, Hash)>]
259
+ # ImagePages data, response status code and response headers
260
+ def post_pages_with_http_info(request)
261
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? PostPagesRequest
262
+
263
+ @api_client.config.logger.debug 'Calling API: ImagePagesApi.post_pages ...' if @api_client.config.debugging
264
+ # verify the required parameter 'name' is set
265
+ raise ArgumentError, 'Missing the required parameter name when calling ImagePagesApi.post_pages' if @api_client.config.client_side_validation && request.name.nil?
266
+ # resource path
267
+ local_var_path = '/annotation/{name}/image/pages'
268
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
269
+
270
+ # query parameters
271
+ query_params = {}
272
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
273
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
274
+ else
275
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
276
+ end
277
+ if local_var_path.include? ('{' + downcase_first_letter('Password') + '}')
278
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Password') + '}', request.password.to_s)
279
+ else
280
+ query_params[downcase_first_letter('Password')] = request.password unless request.password.nil?
281
+ end
282
+
283
+ # header parameters
284
+ header_params = {}
285
+ # HTTP header 'Accept' (if needed)
286
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
287
+ # HTTP header 'Content-Type'
288
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
289
+
290
+ # form parameters
291
+ form_params = {}
292
+
293
+ # http body (model)
294
+ post_body = nil
295
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path,
296
+ header_params: header_params,
297
+ query_params: query_params,
298
+ form_params: form_params,
299
+ body: post_body,
300
+ access_token: get_access_token,
301
+ return_type: 'ImagePages')
302
+ if @api_client.config.debugging
303
+ @api_client.config.logger.debug "API called:
304
+ ImagePagesApi#post_pages\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
305
+ end
306
+ [data, status_code, headers]
307
+ end
308
+
309
+ #
310
+ # Helper method to convert first letter to downcase
311
+ #
312
+ private def downcase_first_letter(str)
313
+ value = str[0].downcase + str[1..-1]
314
+ value
315
+ end
316
+
317
+ #
318
+ # Retrieves access token
319
+ #
320
+ private def get_access_token
321
+ if @access_token.nil? then
322
+ request_access_token
323
+ else
324
+ access_token_expired = @access_token_expires_at < DateTime.now
325
+ if access_token_expired then
326
+ reset_access_token
327
+ end
328
+ end
329
+
330
+ @access_token
331
+ end
332
+
333
+ #
334
+ # Gets a access token from server
335
+ #
336
+ private def request_access_token
337
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
338
+ auth_config.api_base_url = @config.api_base_url
339
+ auth_config.debugging = @config.debugging
340
+ auth_config.logger = @config.logger
341
+ auth_config.temp_folder_path = @config.temp_folder_path
342
+ auth_config.client_side_validation = @config.client_side_validation
343
+ auth_config.api_version = ''
344
+
345
+ auth_api_client = ApiClient.new(auth_config)
346
+
347
+ request_url = "/oauth2/token"
348
+ post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
349
+
350
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
351
+
352
+ @access_token = data[:access_token]
353
+ @refresh_token = data[:refresh_token]
354
+
355
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
356
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
357
+ @access_token_expires_at = DateTime.now + expires_in_days
358
+ end
359
+
360
+ #
361
+ # Resets access token
362
+ #
363
+ private def reset_access_token
364
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
365
+ auth_config.api_base_url = @config.api_base_url
366
+ auth_config.debugging = @config.debugging
367
+ auth_config.logger = @config.logger
368
+ auth_config.temp_folder_path = @config.temp_folder_path
369
+ auth_config.client_side_validation = @config.client_side_validation
370
+ auth_config.api_version = ''
371
+
372
+ auth_api_client = ApiClient.new(auth_config)
373
+
374
+ request_url = "/oauth2/token"
375
+ post_data = "grant_type=refresh_token&refresh_token=#{@refresh_token}"
376
+
377
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
378
+
379
+ @access_token = data[:access_token]
380
+ @refresh_token = data[:refresh_token]
381
+
382
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
383
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
384
+ @access_token_expires_at = DateTime.now + expires_in_days
385
+ end
386
+
387
+ # requires all files inside a directory from current dir
388
+ # @param _dir can be relative path like '/lib' or "../lib"
389
+ private def require_all(_dir)
390
+ Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
391
+ require file
392
+ end
393
+ end
394
+ end
395
+ end
@@ -0,0 +1,281 @@
1
+ # -----------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="pdfFile.rb">
3
+ # Copyright (c) 2003-2018 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 GroupDocsAnnotationCloud
30
+ #
31
+ # GroupDocs.Annotation Cloud API
32
+ #
33
+ class PdfFileApi
34
+ attr_accessor :config
35
+
36
+ #make PdfFileApi.new private
37
+ private_class_method :new
38
+
39
+ # Initializes new instance of PdfFileApi
40
+ #
41
+ # @param [config] Configuration
42
+ # @return [PdfFileApi] New instance of PdfFileApi
43
+ def initialize(config)
44
+ @config = config
45
+ @api_client = ApiClient.new(config)
46
+ require_all '../models/requests'
47
+
48
+ @access_token = nil
49
+ end
50
+
51
+ # Initializes new instance of PdfFileApi
52
+ #
53
+ # @param [app_sid] Application identifier (App SID)
54
+ # @param [app_key] Application private key (App Key)
55
+ # @return [PdfFileApi] New instance of PdfFileApi
56
+ def self.from_keys(app_sid, app_key)
57
+ config = Configuration.new(app_sid, app_key)
58
+ return new(config)
59
+ end
60
+
61
+ # Initializes new instance of PdfFileApi
62
+ #
63
+ # @param [config] Configuration
64
+ # @return [PdfFileApi] New instance of PdfFileApi
65
+ def self.from_config(config)
66
+ return new(config)
67
+ end
68
+
69
+ # Retrieves document as PDF.
70
+ #
71
+ # @param request get_pdf_request
72
+ # @return [File]
73
+ def get_pdf(request)
74
+ data, _status_code, _headers = get_pdf_with_http_info(request)
75
+ data
76
+ end
77
+
78
+ # Retrieves document as PDF.
79
+ #
80
+ # @param request get_pdf_request
81
+ # @return [Array<(File, Fixnum, Hash)>]
82
+ # File data, response status code and response headers
83
+ def get_pdf_with_http_info(request)
84
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? GetPdfRequest
85
+
86
+ @api_client.config.logger.debug 'Calling API: PdfFileApi.get_pdf ...' if @api_client.config.debugging
87
+ # verify the required parameter 'name' is set
88
+ raise ArgumentError, 'Missing the required parameter name when calling PdfFileApi.get_pdf' if @api_client.config.client_side_validation && request.name.nil?
89
+ # resource path
90
+ local_var_path = '/annotation/{name}/pdf'
91
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
92
+
93
+ # query parameters
94
+ query_params = {}
95
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
96
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
97
+ else
98
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
99
+ end
100
+ if local_var_path.include? ('{' + downcase_first_letter('Password') + '}')
101
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Password') + '}', request.password.to_s)
102
+ else
103
+ query_params[downcase_first_letter('Password')] = request.password unless request.password.nil?
104
+ end
105
+
106
+ # header parameters
107
+ header_params = {}
108
+ # HTTP header 'Accept' (if needed)
109
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
110
+ # HTTP header 'Content-Type'
111
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
112
+
113
+ # form parameters
114
+ form_params = {}
115
+
116
+ # http body (model)
117
+ post_body = nil
118
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
119
+ header_params: header_params,
120
+ query_params: query_params,
121
+ form_params: form_params,
122
+ body: post_body,
123
+ access_token: get_access_token,
124
+ return_type: 'File')
125
+ if @api_client.config.debugging
126
+ @api_client.config.logger.debug "API called:
127
+ PdfFileApi#get_pdf\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
128
+ end
129
+ [data, status_code, headers]
130
+ end
131
+
132
+ # Downloads document as PDF.
133
+ #
134
+ # @param request get_pdf_stream_request
135
+ # @return [File]
136
+ def get_pdf_stream(request)
137
+ data, _status_code, _headers = get_pdf_stream_with_http_info(request)
138
+ data
139
+ end
140
+
141
+ # Downloads document as PDF.
142
+ #
143
+ # @param request get_pdf_stream_request
144
+ # @return [Array<(File, Fixnum, Hash)>]
145
+ # File data, response status code and response headers
146
+ def get_pdf_stream_with_http_info(request)
147
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? GetPdfStreamRequest
148
+
149
+ @api_client.config.logger.debug 'Calling API: PdfFileApi.get_pdf_stream ...' if @api_client.config.debugging
150
+ # verify the required parameter 'name' is set
151
+ raise ArgumentError, 'Missing the required parameter name when calling PdfFileApi.get_pdf_stream' if @api_client.config.client_side_validation && request.name.nil?
152
+ # resource path
153
+ local_var_path = '/annotation/{name}/pdf/stream'
154
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
155
+
156
+ # query parameters
157
+ query_params = {}
158
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
159
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
160
+ else
161
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
162
+ end
163
+ if local_var_path.include? ('{' + downcase_first_letter('Password') + '}')
164
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Password') + '}', request.password.to_s)
165
+ else
166
+ query_params[downcase_first_letter('Password')] = request.password unless request.password.nil?
167
+ end
168
+
169
+ # header parameters
170
+ header_params = {}
171
+ # HTTP header 'Accept' (if needed)
172
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
173
+ # HTTP header 'Content-Type'
174
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
175
+
176
+ # form parameters
177
+ form_params = {}
178
+
179
+ # http body (model)
180
+ post_body = nil
181
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
182
+ header_params: header_params,
183
+ query_params: query_params,
184
+ form_params: form_params,
185
+ body: post_body,
186
+ access_token: get_access_token,
187
+ return_type: 'File')
188
+ if @api_client.config.debugging
189
+ @api_client.config.logger.debug "API called:
190
+ PdfFileApi#get_pdf_stream\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
191
+ end
192
+ [data, status_code, headers]
193
+ end
194
+
195
+ #
196
+ # Helper method to convert first letter to downcase
197
+ #
198
+ private def downcase_first_letter(str)
199
+ value = str[0].downcase + str[1..-1]
200
+ value
201
+ end
202
+
203
+ #
204
+ # Retrieves access token
205
+ #
206
+ private def get_access_token
207
+ if @access_token.nil? then
208
+ request_access_token
209
+ else
210
+ access_token_expired = @access_token_expires_at < DateTime.now
211
+ if access_token_expired then
212
+ reset_access_token
213
+ end
214
+ end
215
+
216
+ @access_token
217
+ end
218
+
219
+ #
220
+ # Gets a access token from server
221
+ #
222
+ private def request_access_token
223
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
224
+ auth_config.api_base_url = @config.api_base_url
225
+ auth_config.debugging = @config.debugging
226
+ auth_config.logger = @config.logger
227
+ auth_config.temp_folder_path = @config.temp_folder_path
228
+ auth_config.client_side_validation = @config.client_side_validation
229
+ auth_config.api_version = ''
230
+
231
+ auth_api_client = ApiClient.new(auth_config)
232
+
233
+ request_url = "/oauth2/token"
234
+ post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
235
+
236
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
237
+
238
+ @access_token = data[:access_token]
239
+ @refresh_token = data[:refresh_token]
240
+
241
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
242
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
243
+ @access_token_expires_at = DateTime.now + expires_in_days
244
+ end
245
+
246
+ #
247
+ # Resets access token
248
+ #
249
+ private def reset_access_token
250
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
251
+ auth_config.api_base_url = @config.api_base_url
252
+ auth_config.debugging = @config.debugging
253
+ auth_config.logger = @config.logger
254
+ auth_config.temp_folder_path = @config.temp_folder_path
255
+ auth_config.client_side_validation = @config.client_side_validation
256
+ auth_config.api_version = ''
257
+
258
+ auth_api_client = ApiClient.new(auth_config)
259
+
260
+ request_url = "/oauth2/token"
261
+ post_data = "grant_type=refresh_token&refresh_token=#{@refresh_token}"
262
+
263
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
264
+
265
+ @access_token = data[:access_token]
266
+ @refresh_token = data[:refresh_token]
267
+
268
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
269
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
270
+ @access_token_expires_at = DateTime.now + expires_in_days
271
+ end
272
+
273
+ # requires all files inside a directory from current dir
274
+ # @param _dir can be relative path like '/lib' or "../lib"
275
+ private def require_all(_dir)
276
+ Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
277
+ require file
278
+ end
279
+ end
280
+ end
281
+ end