aspose_slides_cloud 21.3.0 → 21.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -61
  3. data/TestData/TemplatingCVDataWithBase64.xml +22 -22
  4. data/TestData/watermark.png +0 -0
  5. data/lib/aspose_slides_cloud.rb +213 -215
  6. data/lib/aspose_slides_cloud/api/slides_api.rb +17689 -17009
  7. data/lib/aspose_slides_cloud/api/slides_api_requests.rb +4742 -4624
  8. data/lib/aspose_slides_cloud/api_client.rb +439 -434
  9. data/lib/aspose_slides_cloud/models/add_layout_slide.rb +244 -244
  10. data/lib/aspose_slides_cloud/models/add_master_slide.rb +259 -259
  11. data/lib/aspose_slides_cloud/models/add_shape.rb +239 -239
  12. data/lib/aspose_slides_cloud/models/add_slide.rb +269 -269
  13. data/lib/aspose_slides_cloud/models/api_info.rb +217 -217
  14. data/lib/aspose_slides_cloud/models/arrow_head_properties.rb +285 -285
  15. data/lib/aspose_slides_cloud/models/audio_frame.rb +359 -359
  16. data/lib/aspose_slides_cloud/models/axes.rb +237 -237
  17. data/lib/aspose_slides_cloud/models/axis.rb +699 -699
  18. data/lib/aspose_slides_cloud/models/base64_input_file.rb +230 -230
  19. data/lib/aspose_slides_cloud/models/blur_effect.rb +227 -227
  20. data/lib/aspose_slides_cloud/models/box_and_whisker_series.rb +299 -299
  21. data/lib/aspose_slides_cloud/models/bubble_chart_data_point.rb +212 -212
  22. data/lib/aspose_slides_cloud/models/bubble_series.rb +248 -248
  23. data/lib/aspose_slides_cloud/models/chart.rb +365 -365
  24. data/lib/aspose_slides_cloud/models/chart_category.rb +271 -271
  25. data/lib/aspose_slides_cloud/models/chart_title.rb +222 -222
  26. data/lib/aspose_slides_cloud/models/chart_wall.rb +281 -281
  27. data/lib/aspose_slides_cloud/models/color_scheme.rb +317 -317
  28. data/lib/aspose_slides_cloud/models/common_slide_view_properties.rb +217 -217
  29. data/lib/aspose_slides_cloud/models/connector.rb +275 -275
  30. data/lib/aspose_slides_cloud/models/custom_dash_pattern.rb +209 -209
  31. data/lib/aspose_slides_cloud/models/data_point.rb +197 -197
  32. data/lib/aspose_slides_cloud/models/disc_usage.rb +227 -227
  33. data/lib/aspose_slides_cloud/models/document.rb +257 -257
  34. data/lib/aspose_slides_cloud/models/document_properties.rb +209 -209
  35. data/lib/aspose_slides_cloud/models/document_property.rb +232 -232
  36. data/lib/aspose_slides_cloud/models/document_replace_result.rb +218 -218
  37. data/lib/aspose_slides_cloud/models/effect.rb +424 -424
  38. data/lib/aspose_slides_cloud/models/effect_format.rb +277 -277
  39. data/lib/aspose_slides_cloud/models/entity_exists.rb +212 -212
  40. data/lib/aspose_slides_cloud/models/error.rb +237 -237
  41. data/lib/aspose_slides_cloud/models/error_details.rb +222 -222
  42. data/lib/aspose_slides_cloud/models/export_format.rb +60 -60
  43. data/lib/aspose_slides_cloud/models/export_options.rb +216 -216
  44. data/lib/aspose_slides_cloud/models/file_version.rb +225 -225
  45. data/lib/aspose_slides_cloud/models/file_versions.rb +209 -209
  46. data/lib/aspose_slides_cloud/models/files_list.rb +209 -209
  47. data/lib/aspose_slides_cloud/models/files_upload_result.rb +221 -221
  48. data/lib/aspose_slides_cloud/models/fill_format.rb +240 -240
  49. data/lib/aspose_slides_cloud/models/fill_overlay_effect.rb +246 -246
  50. data/lib/aspose_slides_cloud/models/font_scheme.rb +227 -227
  51. data/lib/aspose_slides_cloud/models/font_set.rb +227 -227
  52. data/lib/aspose_slides_cloud/models/format_scheme.rb +245 -245
  53. data/lib/aspose_slides_cloud/models/geometry_shape.rb +260 -260
  54. data/lib/aspose_slides_cloud/models/glow_effect.rb +222 -222
  55. data/lib/aspose_slides_cloud/models/gradient_fill.rb +342 -342
  56. data/lib/aspose_slides_cloud/models/gradient_fill_stop.rb +222 -222
  57. data/lib/aspose_slides_cloud/models/graphical_object.rb +234 -234
  58. data/lib/aspose_slides_cloud/models/group_shape.rb +234 -234
  59. data/lib/aspose_slides_cloud/models/header_footer.rb +247 -247
  60. data/lib/aspose_slides_cloud/models/html_export_options.rb +421 -421
  61. data/lib/aspose_slides_cloud/models/i_shape_export_options.rb +197 -197
  62. data/lib/aspose_slides_cloud/models/image.rb +237 -237
  63. data/lib/aspose_slides_cloud/models/image_export_format.rb +43 -43
  64. data/lib/aspose_slides_cloud/models/image_export_options.rb +299 -299
  65. data/lib/aspose_slides_cloud/models/images.rb +209 -209
  66. data/lib/aspose_slides_cloud/models/inner_shadow_effect.rb +252 -252
  67. data/lib/aspose_slides_cloud/models/input.rb +227 -227
  68. data/lib/aspose_slides_cloud/models/input_file.rb +250 -250
  69. data/lib/aspose_slides_cloud/models/interactive_sequence.rb +224 -224
  70. data/lib/aspose_slides_cloud/models/layout_slide.rb +278 -278
  71. data/lib/aspose_slides_cloud/models/layout_slides.rb +209 -209
  72. data/lib/aspose_slides_cloud/models/legend.rb +321 -321
  73. data/lib/aspose_slides_cloud/models/line_format.rb +411 -411
  74. data/lib/aspose_slides_cloud/models/master_slide.rb +231 -231
  75. data/lib/aspose_slides_cloud/models/master_slides.rb +209 -209
  76. data/lib/aspose_slides_cloud/models/merge.rb +231 -231
  77. data/lib/aspose_slides_cloud/models/merging_source.rb +219 -219
  78. data/lib/aspose_slides_cloud/models/no_fill.rb +219 -219
  79. data/lib/aspose_slides_cloud/models/normal_view_restored_properties.rb +217 -217
  80. data/lib/aspose_slides_cloud/models/notes_slide.rb +217 -217
  81. data/lib/aspose_slides_cloud/models/notes_slide_export_format.rb +43 -43
  82. data/lib/aspose_slides_cloud/models/notes_slide_header_footer.rb +267 -267
  83. data/lib/aspose_slides_cloud/models/object_exist.rb +227 -227
  84. data/lib/aspose_slides_cloud/models/ole_object_frame.rb +259 -259
  85. data/lib/aspose_slides_cloud/models/one_value_chart_data_point.rb +210 -210
  86. data/lib/aspose_slides_cloud/models/one_value_series.rb +248 -248
  87. data/lib/aspose_slides_cloud/models/ordered_merge_request.rb +209 -209
  88. data/lib/aspose_slides_cloud/models/outer_shadow_effect.rb +252 -252
  89. data/lib/aspose_slides_cloud/models/output_file.rb +240 -240
  90. data/lib/aspose_slides_cloud/models/paragraph.rb +517 -517
  91. data/lib/aspose_slides_cloud/models/paragraphs.rb +209 -209
  92. data/lib/aspose_slides_cloud/models/path_input_file.rb +240 -240
  93. data/lib/aspose_slides_cloud/models/path_output_file.rb +239 -239
  94. data/lib/aspose_slides_cloud/models/pattern_fill.rb +266 -266
  95. data/lib/aspose_slides_cloud/models/pdf_export_options.rb +547 -547
  96. data/lib/aspose_slides_cloud/models/picture_fill.rb +351 -351
  97. data/lib/aspose_slides_cloud/models/picture_frame.rb +245 -245
  98. data/lib/aspose_slides_cloud/models/pipeline.rb +219 -219
  99. data/lib/aspose_slides_cloud/models/placeholder.rb +325 -325
  100. data/lib/aspose_slides_cloud/models/placeholders.rb +209 -209
  101. data/lib/aspose_slides_cloud/models/plot_area.rb +311 -311
  102. data/lib/aspose_slides_cloud/models/portion.rb +589 -589
  103. data/lib/aspose_slides_cloud/models/portions.rb +209 -209
  104. data/lib/aspose_slides_cloud/models/pptx_export_options.rb +247 -247
  105. data/lib/aspose_slides_cloud/models/presentation_to_merge.rb +273 -273
  106. data/lib/aspose_slides_cloud/models/presentations_merge_request.rb +221 -221
  107. data/lib/aspose_slides_cloud/models/preset_shadow_effect.rb +286 -286
  108. data/lib/aspose_slides_cloud/models/protection_properties.rb +267 -217
  109. data/lib/aspose_slides_cloud/models/reflection_effect.rb +441 -441
  110. data/lib/aspose_slides_cloud/models/remove_shape.rb +229 -229
  111. data/lib/aspose_slides_cloud/models/remove_slide.rb +234 -234
  112. data/lib/aspose_slides_cloud/models/reorder_slide.rb +249 -249
  113. data/lib/aspose_slides_cloud/models/replace_text.rb +269 -269
  114. data/lib/aspose_slides_cloud/models/request_input_file.rb +235 -235
  115. data/lib/aspose_slides_cloud/models/reset_slide.rb +234 -234
  116. data/lib/aspose_slides_cloud/models/resource_base.rb +219 -219
  117. data/lib/aspose_slides_cloud/models/resource_uri.rb +237 -237
  118. data/lib/aspose_slides_cloud/models/response_output_file.rb +219 -219
  119. data/lib/aspose_slides_cloud/models/save.rb +266 -266
  120. data/lib/aspose_slides_cloud/models/save_shape.rb +276 -276
  121. data/lib/aspose_slides_cloud/models/save_slide.rb +301 -301
  122. data/lib/aspose_slides_cloud/models/scatter_chart_data_point.rb +225 -225
  123. data/lib/aspose_slides_cloud/models/scatter_series.rb +248 -248
  124. data/lib/aspose_slides_cloud/models/section.rb +234 -234
  125. data/lib/aspose_slides_cloud/models/sections.rb +209 -209
  126. data/lib/aspose_slides_cloud/models/series.rb +422 -422
  127. data/lib/aspose_slides_cloud/models/series_marker.rb +281 -281
  128. data/lib/aspose_slides_cloud/models/shape.rb +255 -255
  129. data/lib/aspose_slides_cloud/models/shape_base.rb +375 -375
  130. data/lib/aspose_slides_cloud/models/shape_export_format.rb +44 -44
  131. data/lib/aspose_slides_cloud/models/shape_image_export_options.rb +286 -286
  132. data/lib/aspose_slides_cloud/models/shape_thumbnail_bounds.rb +41 -41
  133. data/lib/aspose_slides_cloud/models/shapes.rb +209 -209
  134. data/lib/aspose_slides_cloud/models/{scale_type.rb → shapes_alignment_type.rb} +46 -41
  135. data/lib/aspose_slides_cloud/models/slide.rb +322 -322
  136. data/lib/aspose_slides_cloud/models/slide_animation.rb +221 -221
  137. data/lib/aspose_slides_cloud/models/slide_background.rb +266 -266
  138. data/lib/aspose_slides_cloud/models/slide_comment.rb +239 -239
  139. data/lib/aspose_slides_cloud/models/slide_comments.rb +209 -209
  140. data/lib/aspose_slides_cloud/models/slide_export_format.rb +59 -59
  141. data/lib/aspose_slides_cloud/models/slide_properties.rb +315 -315
  142. data/lib/aspose_slides_cloud/models/slide_replace_result.rb +223 -223
  143. data/lib/aspose_slides_cloud/models/slides.rb +209 -209
  144. data/lib/aspose_slides_cloud/models/smart_art.rb +342 -342
  145. data/lib/aspose_slides_cloud/models/smart_art_node.rb +293 -293
  146. data/lib/aspose_slides_cloud/models/smart_art_shape.rb +235 -235
  147. data/lib/aspose_slides_cloud/models/soft_edge_effect.rb +212 -212
  148. data/lib/aspose_slides_cloud/models/solid_fill.rb +229 -229
  149. data/lib/aspose_slides_cloud/models/split_document_result.rb +209 -209
  150. data/lib/aspose_slides_cloud/models/storage_exist.rb +212 -212
  151. data/lib/aspose_slides_cloud/models/storage_file.rb +257 -257
  152. data/lib/aspose_slides_cloud/models/svg_export_options.rb +379 -379
  153. data/lib/aspose_slides_cloud/models/swf_export_options.rb +529 -529
  154. data/lib/aspose_slides_cloud/models/table.rb +350 -350
  155. data/lib/aspose_slides_cloud/models/table_cell.rb +403 -403
  156. data/lib/aspose_slides_cloud/models/table_column.rb +212 -212
  157. data/lib/aspose_slides_cloud/models/table_row.rb +239 -239
  158. data/lib/aspose_slides_cloud/models/task.rb +240 -240
  159. data/lib/aspose_slides_cloud/models/text_item.rb +217 -217
  160. data/lib/aspose_slides_cloud/models/text_items.rb +209 -209
  161. data/lib/aspose_slides_cloud/models/theme.rb +237 -237
  162. data/lib/aspose_slides_cloud/models/tiff_export_options.rb +423 -423
  163. data/lib/aspose_slides_cloud/models/update_background.rb +241 -241
  164. data/lib/aspose_slides_cloud/models/update_shape.rb +239 -239
  165. data/lib/aspose_slides_cloud/models/video_frame.rb +329 -329
  166. data/lib/aspose_slides_cloud/models/view_properties.rb +357 -357
  167. data/lib/aspose_slides_cloud/models/waterfall_chart_data_point.rb +206 -206
  168. data/lib/aspose_slides_cloud/models/waterfall_series.rb +247 -247
  169. data/lib/aspose_slides_cloud/models/xps_export_options.rb +243 -243
  170. data/lib/aspose_slides_cloud/type_registry.rb +323 -325
  171. data/lib/aspose_slides_cloud/version.rb +25 -25
  172. data/spec/api/slides_api_spec.rb +39435 -38557
  173. data/spec/extra/extra_spec.rb +202 -202
  174. data/spec/spec_utils.rb +182 -180
  175. data/testConfig.json +7 -7
  176. data/testRules.json +511 -495
  177. metadata +4 -4
  178. data/lib/aspose_slides_cloud/models/size_type.rb +0 -55
@@ -1,434 +1,439 @@
1
- =begin
2
- Copyright (c) 2019 Aspose Pty Ltd
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
21
- =end
22
-
23
- require 'date'
24
- require 'json'
25
- require 'logger'
26
- require 'tempfile'
27
- require 'faraday'
28
- require 'uri'
29
-
30
- module AsposeSlidesCloud
31
- class ApiClient
32
- # The Configuration object holding settings to be used in the API client.
33
- attr_accessor :config
34
-
35
- # Defines the headers to be used in HTTP requests of all API calls by default.
36
- #
37
- # @return [Hash]
38
- attr_accessor :default_headers
39
-
40
- # Initializes the ApiClient
41
- # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
42
- def initialize(config = Configuration.default)
43
- @config = config
44
- end
45
-
46
- def self.default
47
- @@default ||= ApiClient.new
48
- end
49
-
50
- # Call an API with given options.
51
- #
52
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
53
- # the data deserialized from response body (could be nil), response status code and response headers.
54
- def call_api(http_method, path, opts = {})
55
- response = call_api_method(http_method, path, opts)
56
- if @config.debugging
57
- @config.logger.debug "HTTP response\nHeaders: #{response.headers}\nStatus: #{response.status}\nBody: #{response.body}\n"
58
- end
59
-
60
- if (response.status == 401 || (response.status == 500 && response.body.length == 0)) and @config.access_token
61
- @config.access_token = nil
62
- return repeat_call_api(http_method, path, opts)
63
- end
64
-
65
- return process_response(response, opts)
66
- end
67
-
68
- # Call an API with given options.
69
- #
70
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
71
- # the data deserialized from response body (could be nil), response status code and response headers.
72
- def repeat_call_api(http_method, path, opts = {})
73
- response = call_api_method(http_method, path, opts)
74
- if @config.debugging
75
- @config.logger.debug "HTTP response\nHeaders: #{response.headers}\nStatus: #{response.status}\nBody: #{response.body}\n"
76
- end
77
-
78
- return process_response(response, opts)
79
- end
80
-
81
- # Call an API with given options.
82
- #
83
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
84
- # the data deserialized from response body (could be nil), response status code and response headers.
85
- def process_response(response, opts)
86
- unless response.success?
87
- if response.status == 0
88
- # Errors from libcurl will be made visible here
89
- fail ApiError.new(:code => 0,
90
- :message => response.return_message)
91
- else
92
- fail ApiError.new(:code => response.status,
93
- :response_headers => response.headers,
94
- :response_body => response.body)
95
- end
96
- end
97
-
98
- if opts[:return_type]
99
- data = deserialize(response, opts[:return_type])
100
- else
101
- data = nil
102
- end
103
-
104
- return data, response.status, response.headers
105
- end
106
-
107
- # Call an API with given options.
108
- #
109
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
110
- # the data deserialized from response body (could be nil), response status code and response headers.
111
- def call_api_method(http_method, path, opts = {})
112
- connection = Faraday.new(:url => @config.base_path)
113
- case http_method
114
- when :GET
115
- response = connection.get do |req|
116
- build_request(req, http_method, path, opts)
117
- end
118
- when :POST
119
- response = connection.post do |req|
120
- build_request(req, http_method, path, opts)
121
- end
122
- when :PUT
123
- response = connection.put do |req|
124
- build_request(req, http_method, path, opts)
125
- end
126
- when :DELETE
127
- response = connection.delete do |req|
128
- build_request(req, http_method, path, opts)
129
- end
130
- end
131
- response
132
- end
133
-
134
- # Builds the HTTP request
135
- #
136
- # @param [String] http_method HTTP method/verb (e.g. POST)
137
- # @param [String] path URL path (e.g. /account/new)
138
- # @option opts [Hash] :header_params Header parameters
139
- # @option opts [Hash] :query_params Query parameters
140
- # @option opts [Hash] :form_params Query parameters
141
- # @option opts [Object] :body HTTP body (JSON/XML)
142
- # @return [Typhoeus::Request] A Typhoeus Request
143
- def build_request(req, http_method, path, opts = {})
144
- opts[:query_params].each_key do |key|
145
- if opts[:query_params][key].kind_of?(Array)
146
- opts[:query_params][key] = opts[:query_params][key].join[","]
147
- end
148
- end
149
- if @config.http_request_timeout > 0
150
- req.options.timeout = @config.http_request_timeout
151
- end
152
- req.url path.sub(/^\/+/, '')
153
- req.headers = opts[:header_params]
154
- req.params = opts[:query_params]
155
- form_params = opts[:form_params] || {}
156
- req.body = build_request_body(req.headers, form_params, opts[:body], opts[:files])
157
- set_headers(req.headers)
158
- if @config.debugging
159
- @config.logger.debug "HTTP request\nMethod: #{req.method}\nPath: #{req.path}\nParams: #{req.params}\nHeaders: #{req.headers}\nBody: #{req.body}\n"
160
- end
161
- end
162
-
163
- def set_headers(headers)
164
- headers['x-aspose-client'] = "ruby sdk v#{AsposeSlidesCloud::VERSION}"
165
- if @config.timeout > 0
166
- headers['x-aspose-timeout'] = @config.timeout.to_s
167
- end
168
- @config.custom_headers.each do |key, value|
169
- headers[key] = value
170
- end
171
- set_auth_header(headers)
172
- end
173
-
174
- def set_auth_header(headers)
175
- if config.app_sid || config.access_token
176
- unless @config.access_token
177
- auth_token_response = Faraday.post(
178
- @config.auth_base_url + '/connect/token',
179
- { :grant_type => 'client_credentials', 'client_id' => @config.app_sid, 'client_secret' => @config.app_key })
180
- unless auth_token_response.success?
181
- if auth_token_response.status == 0
182
- # Errors from libcurl will be made visible here
183
- fail ApiError.new(:code => 0,
184
- :message => auth_token_response.return_message)
185
- else
186
- fail ApiError.new(:code => 401,
187
- :response_headers => auth_token_response.headers,
188
- :response_body => auth_token_response.body),
189
- "unauthorized"
190
- end
191
- end
192
- @config.access_token = JSON.parse("[#{auth_token_response.body}]", :symbolize_names => true)[0][:access_token]
193
- end
194
- headers['Authorization'] = 'Bearer ' + @config.access_token
195
- end
196
- end
197
-
198
- # Check if the given MIME is a JSON MIME.
199
- # JSON MIME examples:
200
- # application/json
201
- # application/json; charset=UTF8
202
- # APPLICATION/JSON
203
- # */*
204
- # @param [String] mime MIME
205
- # @return [Boolean] True if the MIME is application/json
206
- def json_mime?(mime)
207
- (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
208
- end
209
-
210
- # Deserialize the response to the given return type.
211
- #
212
- # @param [Response] response HTTP response
213
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
214
- def deserialize(response, return_type)
215
- body = response.body
216
-
217
- # handle file downloading - return the File instance processed in request callbacks
218
- # note that response body is empty when the file is written in chunks in request on_body callback
219
-
220
- return nil if body.nil? || body.empty?
221
-
222
- # return response body directly for String return type
223
- return body if return_type == 'String' or return_type == 'File'
224
-
225
- # ensuring a default content type
226
- content_type = response.headers['Content-Type'] || 'application/json'
227
-
228
- fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
229
-
230
- begin
231
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
232
- rescue JSON::ParserError => e
233
- if %w(String Date DateTime).include?(return_type)
234
- data = body
235
- else
236
- raise e
237
- end
238
- end
239
-
240
- convert_to_type data, return_type
241
- end
242
-
243
- # Convert data to the given return type.
244
- # @param [Object] data Data to be converted
245
- # @param [String] return_type Return type
246
- # @return [Mixed] Data in a particular type
247
- def convert_to_type(data, return_type)
248
- return nil if data.nil?
249
- case return_type
250
- when 'String'
251
- data.to_s
252
- when 'Integer'
253
- data.to_i
254
- when 'Float'
255
- data.to_f
256
- when 'BOOLEAN'
257
- data == true
258
- when 'DateTime'
259
- # parse date time (expecting ISO 8601 format)
260
- DateTime.parse data
261
- when 'Date'
262
- # parse date time (expecting ISO 8601 format)
263
- Date.parse data
264
- when 'Object'
265
- # generic object (usually a Hash), return directly
266
- data
267
- when /\AArray<(.+)>\z/
268
- # e.g. Array<Pet>
269
- sub_type = $1
270
- data.map { |item| convert_to_type(item, sub_type) }
271
- when /\AHash\<String, (.+)\>\z/
272
- # e.g. Hash<String, Integer>
273
- sub_type = $1
274
- {}.tap do |hash|
275
- data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
276
- end
277
- else
278
- type = AsposeSlidesCloud::TypeRegistry.get_type(return_type, data)
279
- if !type
280
- type = return_type
281
- end
282
- AsposeSlidesCloud.const_get(type).new.tap do |model|
283
- model.build_from_hash data
284
- end
285
- end
286
- end
287
-
288
- # Builds the HTTP request body
289
- #
290
- # @param [Hash] header_params Header parameters
291
- # @param [Hash] form_params Query parameters
292
- # @param [Object] body HTTP body (JSON/XML)
293
- # @return [String] HTTP body data in the form of string
294
- def build_request_body(header_params, form_params, body, files)
295
- if files and files.length > 0
296
- boundary = "7d70fb31-0eb9-4846-9ea8-933dfb69d8f1"
297
- header_params['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
298
- data = ""
299
- if body
300
- put_multipart!(data, boundary, 0, body)
301
- end
302
- files.each_with_index do |val, index|
303
- put_multipart!(data, boundary, index + 1, val)
304
- end
305
- data << "\r\n--#{boundary}--\r\n"
306
- data
307
- else
308
- header_params['Content-Type'] = 'text/json'
309
- if body
310
- data = body.is_a?(String) ? body : body.to_json
311
- else
312
- data = nil
313
- end
314
- end
315
- data
316
- end
317
-
318
- # Builds the HTTP request body
319
- #
320
- # @param [Hash] header_params Header parameters
321
- # @param [Hash] form_params Query parameters
322
- # @param [Object] body HTTP body (JSON/XML)
323
- # @return [String] HTTP body data in the form of string
324
- def put_multipart!(data, boundary, part_index, part_data)
325
- data << "\r\n--#{boundary}\r\n"
326
- if part_index > 0
327
- data << "Content-Disposition: form-data; name=\"file#{part_index}\";filename=\"file#{part_index}\"\r\n"
328
- data << "Content-Type: application/octet-stream\r\n"
329
- elsif
330
- data << "Content-Disposition: form-data; name=\"data\"\r\n"
331
- data << "Content-Type: text/json\r\n"
332
- end
333
- data << "Content-Length: #{part_data.length}\r\n"
334
- data << "\r\n"
335
- data << part_data
336
- end
337
-
338
- # Update hearder and query params based on authentication settings.
339
- #
340
- # @param [Hash] header_params Header parameters
341
- # @param [Hash] query_params Query parameters
342
- # @param [String] auth_names Authentication scheme name
343
- def update_params_for_auth!(header_params, query_params, auth_names)
344
- Array(auth_names).each do |auth_name|
345
- auth_setting = @config.auth_settings[auth_name]
346
- next unless auth_setting
347
- case auth_setting[:in]
348
- when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
349
- when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
350
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
351
- end
352
- end
353
- end
354
-
355
- # Return Accept header based on an array of accepts provided.
356
- # @param [Array] accepts array for Accept
357
- # @return [String] the Accept header (e.g. application/json)
358
- def select_header_accept(accepts)
359
- return nil if accepts.nil? || accepts.empty?
360
- # use JSON when present, otherwise use all of the provided
361
- json_accept = accepts.find { |s| json_mime?(s) }
362
- json_accept || accepts.join(',')
363
- end
364
-
365
- # Return Content-Type header based on an array of content types provided.
366
- # @param [Array] content_types array for Content-Type
367
- # @return [String] the Content-Type header (e.g. application/json)
368
- def select_header_content_type(content_types)
369
- # use application/json by default
370
- return 'application/json' if content_types.nil? || content_types.empty?
371
- # use JSON when present, otherwise use the first one
372
- json_content_type = content_types.find { |s| json_mime?(s) }
373
- json_content_type || content_types.first
374
- end
375
-
376
- # Convert object (array, hash, object, etc) to JSON string.
377
- # @param [Object] model object to be converted into JSON string
378
- # @return [String] JSON string representation of the object
379
- def object_to_http_body(model)
380
- return model if model.nil? || model.is_a?(String)
381
- local_body = nil
382
- if model.is_a?(Array)
383
- local_body = model.map { |m| object_to_hash(m) }
384
- else
385
- local_body = object_to_hash(model)
386
- end
387
- local_body.to_json
388
- end
389
-
390
- # Convert object(non-array) to hash.
391
- # @param [Object] obj object to be converted into JSON string
392
- # @return [String] JSON string representation of the object
393
- def object_to_hash(obj)
394
- if obj.respond_to?(:to_hash)
395
- obj.to_hash
396
- else
397
- obj
398
- end
399
- end
400
-
401
- # Convert object(non-array) to hash.
402
- # @param [Object] obj object to be converted into JSON string
403
- # @return [String] JSON string representation of the object
404
- def replace_path_parameter(path, name, value)
405
- if value == nil
406
- value = ""
407
- end
408
- if value.to_s != ""
409
- value = "/" + value.to_s
410
- end
411
- path.sub('/{' + name + '}', URI::encode(value))
412
- end
413
-
414
- # Build parameter value according to the given collection format.
415
- # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
416
- def build_collection_param(param, collection_format)
417
- case collection_format
418
- when :csv
419
- param.join(',')
420
- when :ssv
421
- param.join(' ')
422
- when :tsv
423
- param.join("\t")
424
- when :pipes
425
- param.join('|')
426
- when :multi
427
- # return the array directly as typhoeus will handle it as expected
428
- param
429
- else
430
- fail "unknown collection format: #{collection_format.inspect}"
431
- end
432
- end
433
- end
434
- end
1
+ =begin
2
+ Copyright (c) 2019 Aspose Pty Ltd
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ =end
22
+
23
+ require 'date'
24
+ require 'json'
25
+ require 'logger'
26
+ require 'tempfile'
27
+ require 'faraday'
28
+ require 'uri'
29
+
30
+ module AsposeSlidesCloud
31
+ class ApiClient
32
+ # The Configuration object holding settings to be used in the API client.
33
+ attr_accessor :config
34
+
35
+ # Defines the headers to be used in HTTP requests of all API calls by default.
36
+ #
37
+ # @return [Hash]
38
+ attr_accessor :default_headers
39
+
40
+ # Initializes the ApiClient
41
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
42
+ def initialize(config = Configuration.default)
43
+ @config = config
44
+ end
45
+
46
+ def self.default
47
+ @@default ||= ApiClient.new
48
+ end
49
+
50
+ # Call an API with given options.
51
+ #
52
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
53
+ # the data deserialized from response body (could be nil), response status code and response headers.
54
+ def call_api(http_method, path, opts = {})
55
+ response = call_api_method(http_method, path, opts)
56
+ if @config.debugging
57
+ @config.logger.debug "HTTP response\nHeaders: #{response.headers}\nStatus: #{response.status}\nBody: #{response.body}\n"
58
+ end
59
+
60
+ if (response.status == 401 || (response.status == 500 && response.body.length == 0)) and @config.access_token
61
+ @config.access_token = nil
62
+ return repeat_call_api(http_method, path, opts)
63
+ end
64
+
65
+ return process_response(response, opts)
66
+ end
67
+
68
+ # Call an API with given options.
69
+ #
70
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
71
+ # the data deserialized from response body (could be nil), response status code and response headers.
72
+ def repeat_call_api(http_method, path, opts = {})
73
+ response = call_api_method(http_method, path, opts)
74
+ if @config.debugging
75
+ @config.logger.debug "HTTP response\nHeaders: #{response.headers}\nStatus: #{response.status}\nBody: #{response.body}\n"
76
+ end
77
+
78
+ return process_response(response, opts)
79
+ end
80
+
81
+ # Call an API with given options.
82
+ #
83
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
84
+ # the data deserialized from response body (could be nil), response status code and response headers.
85
+ def process_response(response, opts)
86
+ unless response.success?
87
+ if response.status == 0
88
+ # Errors from libcurl will be made visible here
89
+ fail ApiError.new(:code => 0,
90
+ :message => response.return_message)
91
+ else
92
+ fail ApiError.new(:code => response.status,
93
+ :response_headers => response.headers,
94
+ :response_body => response.body)
95
+ end
96
+ end
97
+
98
+ if opts[:return_type]
99
+ data = deserialize(response, opts[:return_type])
100
+ else
101
+ data = nil
102
+ end
103
+
104
+ return data, response.status, response.headers
105
+ end
106
+
107
+ # Call an API with given options.
108
+ #
109
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
110
+ # the data deserialized from response body (could be nil), response status code and response headers.
111
+ def call_api_method(http_method, path, opts = {})
112
+ connection = Faraday.new(:url => @config.base_path)
113
+ case http_method
114
+ when :GET
115
+ response = connection.get do |req|
116
+ build_request(req, http_method, path, opts)
117
+ end
118
+ when :POST
119
+ response = connection.post do |req|
120
+ build_request(req, http_method, path, opts)
121
+ end
122
+ when :PUT
123
+ response = connection.put do |req|
124
+ build_request(req, http_method, path, opts)
125
+ end
126
+ when :DELETE
127
+ response = connection.delete do |req|
128
+ build_request(req, http_method, path, opts)
129
+ end
130
+ end
131
+ response
132
+ end
133
+
134
+ # Builds the HTTP request
135
+ #
136
+ # @param [String] http_method HTTP method/verb (e.g. POST)
137
+ # @param [String] path URL path (e.g. /account/new)
138
+ # @option opts [Hash] :header_params Header parameters
139
+ # @option opts [Hash] :query_params Query parameters
140
+ # @option opts [Object] :body HTTP body (JSON/XML)
141
+ # @return [Typhoeus::Request] A Typhoeus Request
142
+ def build_request(req, http_method, path, opts = {})
143
+ opts[:query_params].each_key do |key|
144
+ if opts[:query_params][key].kind_of?(Array)
145
+ opts[:query_params][key] = opts[:query_params][key].join[","]
146
+ end
147
+ end
148
+ if @config.http_request_timeout > 0
149
+ req.options.timeout = @config.http_request_timeout
150
+ end
151
+ req.url path.sub(/^\/+/, '')
152
+ req.headers = opts[:header_params]
153
+ req.params = opts[:query_params]
154
+ req.body = build_request_body(req.headers, opts[:body], opts[:files])
155
+ set_headers(req.headers)
156
+ if @config.debugging
157
+ @config.logger.debug "HTTP request\nMethod: #{req.method}\nPath: #{req.path}\nParams: #{req.params}\nHeaders: #{req.headers}\nBody: #{req.body}\n"
158
+ end
159
+ end
160
+
161
+ def set_headers(headers)
162
+ headers['x-aspose-client'] = "ruby sdk v#{AsposeSlidesCloud::VERSION}"
163
+ if @config.timeout > 0
164
+ headers['x-aspose-timeout'] = @config.timeout.to_s
165
+ end
166
+ @config.custom_headers.each do |key, value|
167
+ headers[key] = value
168
+ end
169
+ set_auth_header(headers)
170
+ end
171
+
172
+ def set_auth_header(headers)
173
+ if config.app_sid || config.access_token
174
+ unless @config.access_token
175
+ auth_token_response = Faraday.post(
176
+ @config.auth_base_url + '/connect/token',
177
+ { :grant_type => 'client_credentials', 'client_id' => @config.app_sid, 'client_secret' => @config.app_key })
178
+ unless auth_token_response.success?
179
+ if auth_token_response.status == 0
180
+ # Errors from libcurl will be made visible here
181
+ fail ApiError.new(:code => 0,
182
+ :message => auth_token_response.return_message)
183
+ else
184
+ fail ApiError.new(:code => 401,
185
+ :response_headers => auth_token_response.headers,
186
+ :response_body => auth_token_response.body),
187
+ "unauthorized"
188
+ end
189
+ end
190
+ @config.access_token = JSON.parse("[#{auth_token_response.body}]", :symbolize_names => true)[0][:access_token]
191
+ end
192
+ headers['Authorization'] = 'Bearer ' + @config.access_token
193
+ end
194
+ end
195
+
196
+ # Check if the given MIME is a JSON MIME.
197
+ # JSON MIME examples:
198
+ # application/json
199
+ # application/json; charset=UTF8
200
+ # APPLICATION/JSON
201
+ # */*
202
+ # @param [String] mime MIME
203
+ # @return [Boolean] True if the MIME is application/json
204
+ def json_mime?(mime)
205
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
206
+ end
207
+
208
+ # Deserialize the response to the given return type.
209
+ #
210
+ # @param [Response] response HTTP response
211
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
212
+ def deserialize(response, return_type)
213
+ body = response.body
214
+
215
+ # handle file downloading - return the File instance processed in request callbacks
216
+ # note that response body is empty when the file is written in chunks in request on_body callback
217
+
218
+ return nil if body.nil? || body.empty?
219
+
220
+ # return response body directly for String return type
221
+ return body if return_type == 'String' or return_type == 'File'
222
+
223
+ # ensuring a default content type
224
+ content_type = response.headers['Content-Type'] || 'application/json'
225
+
226
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
227
+
228
+ begin
229
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
230
+ rescue JSON::ParserError => e
231
+ if %w(String Date DateTime).include?(return_type)
232
+ data = body
233
+ else
234
+ raise e
235
+ end
236
+ end
237
+
238
+ convert_to_type data, return_type
239
+ end
240
+
241
+ # Convert data to the given return type.
242
+ # @param [Object] data Data to be converted
243
+ # @param [String] return_type Return type
244
+ # @return [Mixed] Data in a particular type
245
+ def convert_to_type(data, return_type)
246
+ return nil if data.nil?
247
+ case return_type
248
+ when 'String'
249
+ data.to_s
250
+ when 'Integer'
251
+ data.to_i
252
+ when 'Float'
253
+ data.to_f
254
+ when 'BOOLEAN'
255
+ data == true
256
+ when 'DateTime'
257
+ # parse date time (expecting ISO 8601 format)
258
+ DateTime.parse data
259
+ when 'Date'
260
+ # parse date time (expecting ISO 8601 format)
261
+ Date.parse data
262
+ when 'Object'
263
+ # generic object (usually a Hash), return directly
264
+ data
265
+ when /\AArray<(.+)>\z/
266
+ # e.g. Array<Pet>
267
+ sub_type = $1
268
+ data.map { |item| convert_to_type(item, sub_type) }
269
+ when /\AHash\<String, (.+)\>\z/
270
+ # e.g. Hash<String, Integer>
271
+ sub_type = $1
272
+ {}.tap do |hash|
273
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
274
+ end
275
+ else
276
+ type = AsposeSlidesCloud::TypeRegistry.get_type(return_type, data)
277
+ if !type
278
+ type = return_type
279
+ end
280
+ AsposeSlidesCloud.const_get(type).new.tap do |model|
281
+ model.build_from_hash data
282
+ end
283
+ end
284
+ end
285
+
286
+ # Builds the HTTP request body
287
+ #
288
+ # @param [Hash] header_params Header parameters
289
+ # @param [Object] body HTTP body (JSON/XML)
290
+ # @return [String] HTTP body data in the form of string
291
+ def build_request_body(header_params, body, files)
292
+ partCount = 0
293
+ if files
294
+ partCount += files.length
295
+ end
296
+ if body
297
+ partCount += 1
298
+ end
299
+ if partCount > 1
300
+ boundary = "7d70fb31-0eb9-4846-9ea8-933dfb69d8f1"
301
+ header_params['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
302
+ data = ""
303
+ if body
304
+ put_multipart!(data, boundary, 0, body)
305
+ end
306
+ files.each_with_index do |val, index|
307
+ put_multipart!(data, boundary, index + 1, val)
308
+ end
309
+ data << "\r\n--#{boundary}--\r\n"
310
+ elsif partCount == 1
311
+ if body
312
+ header_params['Content-Type'] = "text/json"
313
+ data = body.is_a?(String) ? body : body.to_json
314
+ else
315
+ header_params['Content-Type'] = "application/octet-stream"
316
+ data = files[0]
317
+ end
318
+ else
319
+ data = nil
320
+ end
321
+ data
322
+ end
323
+
324
+ # Builds the HTTP request body
325
+ #
326
+ # @param [Hash] header_params Header parameters
327
+ # @param [Object] body HTTP body (JSON/XML)
328
+ # @return [String] HTTP body data in the form of string
329
+ def put_multipart!(data, boundary, part_index, part_data)
330
+ data << "\r\n--#{boundary}\r\n"
331
+ if part_index > 0
332
+ data << "Content-Disposition: form-data; name=\"file#{part_index}\";filename=\"file#{part_index}\"\r\n"
333
+ data << "Content-Type: application/octet-stream\r\n"
334
+ elsif
335
+ data << "Content-Disposition: form-data; name=\"data\"\r\n"
336
+ data << "Content-Type: text/json\r\n"
337
+ end
338
+ data << "Content-Length: #{part_data.length}\r\n"
339
+ data << "\r\n"
340
+ data << part_data
341
+ end
342
+
343
+ # Update hearder and query params based on authentication settings.
344
+ #
345
+ # @param [Hash] header_params Header parameters
346
+ # @param [Hash] query_params Query parameters
347
+ # @param [String] auth_names Authentication scheme name
348
+ def update_params_for_auth!(header_params, query_params, auth_names)
349
+ Array(auth_names).each do |auth_name|
350
+ auth_setting = @config.auth_settings[auth_name]
351
+ next unless auth_setting
352
+ case auth_setting[:in]
353
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
354
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
355
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
356
+ end
357
+ end
358
+ end
359
+
360
+ # Return Accept header based on an array of accepts provided.
361
+ # @param [Array] accepts array for Accept
362
+ # @return [String] the Accept header (e.g. application/json)
363
+ def select_header_accept(accepts)
364
+ return nil if accepts.nil? || accepts.empty?
365
+ # use JSON when present, otherwise use all of the provided
366
+ json_accept = accepts.find { |s| json_mime?(s) }
367
+ json_accept || accepts.join(',')
368
+ end
369
+
370
+ # Return Content-Type header based on an array of content types provided.
371
+ # @param [Array] content_types array for Content-Type
372
+ # @return [String] the Content-Type header (e.g. application/json)
373
+ def select_header_content_type(content_types)
374
+ # use application/json by default
375
+ return 'application/json' if content_types.nil? || content_types.empty?
376
+ # use JSON when present, otherwise use the first one
377
+ json_content_type = content_types.find { |s| json_mime?(s) }
378
+ json_content_type || content_types.first
379
+ end
380
+
381
+ # Convert object (array, hash, object, etc) to JSON string.
382
+ # @param [Object] model object to be converted into JSON string
383
+ # @return [String] JSON string representation of the object
384
+ def object_to_http_body(model)
385
+ return model if model.nil? || model.is_a?(String)
386
+ local_body = nil
387
+ if model.is_a?(Array)
388
+ local_body = model.map { |m| object_to_hash(m) }
389
+ else
390
+ local_body = object_to_hash(model)
391
+ end
392
+ local_body.to_json
393
+ end
394
+
395
+ # Convert object(non-array) to hash.
396
+ # @param [Object] obj object to be converted into JSON string
397
+ # @return [String] JSON string representation of the object
398
+ def object_to_hash(obj)
399
+ if obj.respond_to?(:to_hash)
400
+ obj.to_hash
401
+ else
402
+ obj
403
+ end
404
+ end
405
+
406
+ # Convert object(non-array) to hash.
407
+ # @param [Object] obj object to be converted into JSON string
408
+ # @return [String] JSON string representation of the object
409
+ def replace_path_parameter(path, name, value)
410
+ if value == nil
411
+ value = ""
412
+ end
413
+ if value.to_s != ""
414
+ value = "/" + value.to_s
415
+ end
416
+ path.sub('/{' + name + '}', URI::encode(value))
417
+ end
418
+
419
+ # Build parameter value according to the given collection format.
420
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
421
+ def build_collection_param(param, collection_format)
422
+ case collection_format
423
+ when :csv
424
+ param.join(',')
425
+ when :ssv
426
+ param.join(' ')
427
+ when :tsv
428
+ param.join("\t")
429
+ when :pipes
430
+ param.join('|')
431
+ when :multi
432
+ # return the array directly as typhoeus will handle it as expected
433
+ param
434
+ else
435
+ fail "unknown collection format: #{collection_format.inspect}"
436
+ end
437
+ end
438
+ end
439
+ end