groupdocs_annotation_cloud 18.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 87ce3312a2efaac314b2356ebddf35f4baed97d4
4
+ data.tar.gz: 8f42f946da1bc0bac4d24495b533359143963042
5
+ SHA512:
6
+ metadata.gz: 28f18f6a91420d5db93b06110095de2594b2c87f1bd165950881c79eeeda1dd6de29863da496aa557763e6f741f56c65255fae18829e9566798785260d06d142
7
+ data.tar.gz: 3b63dc7ecb6341351a3e7da532c2a355fd7ba625af7b9050b6d836807841573ef74abd98f99c25a6051eace76e6141cccc91ddcd2de74a3acdbcaada1c56927f
@@ -0,0 +1,344 @@
1
+ # -----------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="annotation.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 AnnotationApi
34
+ attr_accessor :config
35
+
36
+ #make AnnotationApi.new private
37
+ private_class_method :new
38
+
39
+ # Initializes new instance of AnnotationApi
40
+ #
41
+ # @param [config] Configuration
42
+ # @return [AnnotationApi] New instance of AnnotationApi
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 AnnotationApi
52
+ #
53
+ # @param [app_sid] Application identifier (App SID)
54
+ # @param [app_key] Application private key (App Key)
55
+ # @return [AnnotationApi] New instance of AnnotationApi
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 AnnotationApi
62
+ #
63
+ # @param [config] Configuration
64
+ # @return [AnnotationApi] New instance of AnnotationApi
65
+ def self.from_config(config)
66
+ return new(config)
67
+ end
68
+
69
+ # Removes annotations from document.
70
+ #
71
+ # @param request delete_clean_document_request
72
+ # @return [File]
73
+ def delete_clean_document(request)
74
+ data, _status_code, _headers = delete_clean_document_with_http_info(request)
75
+ data
76
+ end
77
+
78
+ # Removes annotations from document.
79
+ #
80
+ # @param request delete_clean_document_request
81
+ # @return [Array<(File, Fixnum, Hash)>]
82
+ # File data, response status code and response headers
83
+ def delete_clean_document_with_http_info(request)
84
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? DeleteCleanDocumentRequest
85
+
86
+ @api_client.config.logger.debug 'Calling API: AnnotationApi.delete_clean_document ...' if @api_client.config.debugging
87
+ # verify the required parameter 'name' is set
88
+ raise ArgumentError, 'Missing the required parameter name when calling AnnotationApi.delete_clean_document' if @api_client.config.client_side_validation && request.name.nil?
89
+ # resource path
90
+ local_var_path = '/annotation/{name}/annotations'
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(:DELETE, 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
+ AnnotationApi#delete_clean_document\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
128
+ end
129
+ [data, status_code, headers]
130
+ end
131
+
132
+ # Extracts annotations from document.
133
+ #
134
+ # @param request get_import_request
135
+ # @return [Array<AnnotationInfo>]
136
+ def get_import(request)
137
+ data, _status_code, _headers = get_import_with_http_info(request)
138
+ data
139
+ end
140
+
141
+ # Extracts annotations from document.
142
+ #
143
+ # @param request get_import_request
144
+ # @return [Array<(Array<AnnotationInfo>, Fixnum, Hash)>]
145
+ # Array<AnnotationInfo> data, response status code and response headers
146
+ def get_import_with_http_info(request)
147
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? GetImportRequest
148
+
149
+ @api_client.config.logger.debug 'Calling API: AnnotationApi.get_import ...' if @api_client.config.debugging
150
+ # verify the required parameter 'name' is set
151
+ raise ArgumentError, 'Missing the required parameter name when calling AnnotationApi.get_import' if @api_client.config.client_side_validation && request.name.nil?
152
+ # resource path
153
+ local_var_path = '/annotation/{name}/annotations'
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: 'Array<AnnotationInfo>')
188
+ if @api_client.config.debugging
189
+ @api_client.config.logger.debug "API called:
190
+ AnnotationApi#get_import\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
191
+ end
192
+ [data, status_code, headers]
193
+ end
194
+
195
+ # Adds annotations to the document.
196
+ #
197
+ # @param request put_export_request
198
+ # @return [File]
199
+ def put_export(request)
200
+ data, _status_code, _headers = put_export_with_http_info(request)
201
+ data
202
+ end
203
+
204
+ # Adds annotations to the document.
205
+ #
206
+ # @param request put_export_request
207
+ # @return [Array<(File, Fixnum, Hash)>]
208
+ # File data, response status code and response headers
209
+ def put_export_with_http_info(request)
210
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? PutExportRequest
211
+
212
+ @api_client.config.logger.debug 'Calling API: AnnotationApi.put_export ...' if @api_client.config.debugging
213
+ # verify the required parameter 'name' is set
214
+ raise ArgumentError, 'Missing the required parameter name when calling AnnotationApi.put_export' if @api_client.config.client_side_validation && request.name.nil?
215
+ # resource path
216
+ local_var_path = '/annotation/{name}/annotations'
217
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Name') + '}', request.name.to_s)
218
+
219
+ # query parameters
220
+ query_params = {}
221
+ if local_var_path.include? ('{' + downcase_first_letter('Folder') + '}')
222
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Folder') + '}', request.folder.to_s)
223
+ else
224
+ query_params[downcase_first_letter('Folder')] = request.folder unless request.folder.nil?
225
+ end
226
+ if local_var_path.include? ('{' + downcase_first_letter('Password') + '}')
227
+ local_var_path = local_var_path.sub('{' + downcase_first_letter('Password') + '}', request.password.to_s)
228
+ else
229
+ query_params[downcase_first_letter('Password')] = request.password unless request.password.nil?
230
+ end
231
+
232
+ # header parameters
233
+ header_params = {}
234
+ # HTTP header 'Accept' (if needed)
235
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', 'application/xml'])
236
+ # HTTP header 'Content-Type'
237
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', 'application/xml'])
238
+
239
+ # form parameters
240
+ form_params = {}
241
+
242
+ # http body (model)
243
+ post_body = @api_client.object_to_http_body(request.body)
244
+ data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
245
+ header_params: header_params,
246
+ query_params: query_params,
247
+ form_params: form_params,
248
+ body: post_body,
249
+ access_token: get_access_token,
250
+ return_type: 'File')
251
+ if @api_client.config.debugging
252
+ @api_client.config.logger.debug "API called:
253
+ AnnotationApi#put_export\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
254
+ end
255
+ [data, status_code, headers]
256
+ end
257
+
258
+ #
259
+ # Helper method to convert first letter to downcase
260
+ #
261
+ private def downcase_first_letter(str)
262
+ value = str[0].downcase + str[1..-1]
263
+ value
264
+ end
265
+
266
+ #
267
+ # Retrieves access token
268
+ #
269
+ private def get_access_token
270
+ if @access_token.nil? then
271
+ request_access_token
272
+ else
273
+ access_token_expired = @access_token_expires_at < DateTime.now
274
+ if access_token_expired then
275
+ reset_access_token
276
+ end
277
+ end
278
+
279
+ @access_token
280
+ end
281
+
282
+ #
283
+ # Gets a access token from server
284
+ #
285
+ private def request_access_token
286
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
287
+ auth_config.api_base_url = @config.api_base_url
288
+ auth_config.debugging = @config.debugging
289
+ auth_config.logger = @config.logger
290
+ auth_config.temp_folder_path = @config.temp_folder_path
291
+ auth_config.client_side_validation = @config.client_side_validation
292
+ auth_config.api_version = ''
293
+
294
+ auth_api_client = ApiClient.new(auth_config)
295
+
296
+ request_url = "/oauth2/token"
297
+ post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
298
+
299
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
300
+
301
+ @access_token = data[:access_token]
302
+ @refresh_token = data[:refresh_token]
303
+
304
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
305
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
306
+ @access_token_expires_at = DateTime.now + expires_in_days
307
+ end
308
+
309
+ #
310
+ # Resets access token
311
+ #
312
+ private def reset_access_token
313
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
314
+ auth_config.api_base_url = @config.api_base_url
315
+ auth_config.debugging = @config.debugging
316
+ auth_config.logger = @config.logger
317
+ auth_config.temp_folder_path = @config.temp_folder_path
318
+ auth_config.client_side_validation = @config.client_side_validation
319
+ auth_config.api_version = ''
320
+
321
+ auth_api_client = ApiClient.new(auth_config)
322
+
323
+ request_url = "/oauth2/token"
324
+ post_data = "grant_type=refresh_token&refresh_token=#{@refresh_token}"
325
+
326
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
327
+
328
+ @access_token = data[:access_token]
329
+ @refresh_token = data[:refresh_token]
330
+
331
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
332
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
333
+ @access_token_expires_at = DateTime.now + expires_in_days
334
+ end
335
+
336
+ # requires all files inside a directory from current dir
337
+ # @param _dir can be relative path like '/lib' or "../lib"
338
+ private def require_all(_dir)
339
+ Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
340
+ require file
341
+ end
342
+ end
343
+ end
344
+ end
@@ -0,0 +1,218 @@
1
+ # -----------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="imageInfo.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 ImageInfoApi
34
+ attr_accessor :config
35
+
36
+ #make ImageInfoApi.new private
37
+ private_class_method :new
38
+
39
+ # Initializes new instance of ImageInfoApi
40
+ #
41
+ # @param [config] Configuration
42
+ # @return [ImageInfoApi] New instance of ImageInfoApi
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 ImageInfoApi
52
+ #
53
+ # @param [app_sid] Application identifier (App SID)
54
+ # @param [app_key] Application private key (App Key)
55
+ # @return [ImageInfoApi] New instance of ImageInfoApi
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 ImageInfoApi
62
+ #
63
+ # @param [config] Configuration
64
+ # @return [ImageInfoApi] New instance of ImageInfoApi
65
+ def self.from_config(config)
66
+ return new(config)
67
+ end
68
+
69
+ # Retrieves document's information.
70
+ #
71
+ # @param request get_info_request
72
+ # @return [DocumentInfo]
73
+ def get_info(request)
74
+ data, _status_code, _headers = get_info_with_http_info(request)
75
+ data
76
+ end
77
+
78
+ # Retrieves document's information.
79
+ #
80
+ # @param request get_info_request
81
+ # @return [Array<(DocumentInfo, Fixnum, Hash)>]
82
+ # DocumentInfo data, response status code and response headers
83
+ def get_info_with_http_info(request)
84
+ raise ArgumentError, 'Incorrect request type' unless request.is_a? GetInfoRequest
85
+
86
+ @api_client.config.logger.debug 'Calling API: ImageInfoApi.get_info ...' if @api_client.config.debugging
87
+ # verify the required parameter 'name' is set
88
+ raise ArgumentError, 'Missing the required parameter name when calling ImageInfoApi.get_info' if @api_client.config.client_side_validation && request.name.nil?
89
+ # resource path
90
+ local_var_path = '/annotation/{name}/image/info'
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: 'DocumentInfo')
125
+ if @api_client.config.debugging
126
+ @api_client.config.logger.debug "API called:
127
+ ImageInfoApi#get_info\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
128
+ end
129
+ [data, status_code, headers]
130
+ end
131
+
132
+ #
133
+ # Helper method to convert first letter to downcase
134
+ #
135
+ private def downcase_first_letter(str)
136
+ value = str[0].downcase + str[1..-1]
137
+ value
138
+ end
139
+
140
+ #
141
+ # Retrieves access token
142
+ #
143
+ private def get_access_token
144
+ if @access_token.nil? then
145
+ request_access_token
146
+ else
147
+ access_token_expired = @access_token_expires_at < DateTime.now
148
+ if access_token_expired then
149
+ reset_access_token
150
+ end
151
+ end
152
+
153
+ @access_token
154
+ end
155
+
156
+ #
157
+ # Gets a access token from server
158
+ #
159
+ private def request_access_token
160
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
161
+ auth_config.api_base_url = @config.api_base_url
162
+ auth_config.debugging = @config.debugging
163
+ auth_config.logger = @config.logger
164
+ auth_config.temp_folder_path = @config.temp_folder_path
165
+ auth_config.client_side_validation = @config.client_side_validation
166
+ auth_config.api_version = ''
167
+
168
+ auth_api_client = ApiClient.new(auth_config)
169
+
170
+ request_url = "/oauth2/token"
171
+ post_data = "grant_type=client_credentials&client_id=#{@config.app_sid}&client_secret=#{@config.app_key}"
172
+
173
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
174
+
175
+ @access_token = data[:access_token]
176
+ @refresh_token = data[:refresh_token]
177
+
178
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
179
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
180
+ @access_token_expires_at = DateTime.now + expires_in_days
181
+ end
182
+
183
+ #
184
+ # Resets access token
185
+ #
186
+ private def reset_access_token
187
+ auth_config = Configuration.new(@config.app_sid, @config.app_key)
188
+ auth_config.api_base_url = @config.api_base_url
189
+ auth_config.debugging = @config.debugging
190
+ auth_config.logger = @config.logger
191
+ auth_config.temp_folder_path = @config.temp_folder_path
192
+ auth_config.client_side_validation = @config.client_side_validation
193
+ auth_config.api_version = ''
194
+
195
+ auth_api_client = ApiClient.new(auth_config)
196
+
197
+ request_url = "/oauth2/token"
198
+ post_data = "grant_type=refresh_token&refresh_token=#{@refresh_token}"
199
+
200
+ data, _status_code, _header = auth_api_client.call_api(:POST, request_url, :body => post_data, :return_type => 'Object')
201
+
202
+ @access_token = data[:access_token]
203
+ @refresh_token = data[:refresh_token]
204
+
205
+ expires_in_seconds = data[:expires_in].to_i - 5 * 60
206
+ expires_in_days = Rational(expires_in_seconds, 60 * 60 * 24)
207
+ @access_token_expires_at = DateTime.now + expires_in_days
208
+ end
209
+
210
+ # requires all files inside a directory from current dir
211
+ # @param _dir can be relative path like '/lib' or "../lib"
212
+ private def require_all(_dir)
213
+ Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/*.rb"].each do |file|
214
+ require file
215
+ end
216
+ end
217
+ end
218
+ end