Skip to content

Commit 42b2cc6

Browse files
author
evgeny.ivanov
committed
SDK regenerated by CI server [ci skip]
1 parent 64a0dbd commit 42b2cc6

File tree

299 files changed

+32046
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+32046
-10
lines changed

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
source 'https://rubygems.org'
22

3-
gem 'faraday', '~> 0.14.0'
4-
gem 'mimemagic', '~> 0.3.2'
3+
gem 'faraday', '>= 1.4.1'
4+
gem 'marcel', '>= 1.0.0'
55
gem 'multipart-parser', '~> 0.1.1'
66

77
group :development do
88
gem 'rake'
99
gem 'ci_reporter_minitest'
1010
gem 'rubocop', '~> 0.58.2'
1111
gem 'rubocop-checkstyle_formatter'
12-
gem 'aspose_storage_cloud', '~> 18.6', '>= 18.5'
1312
gem 'minitest', '~> 5.11', '>= 5.11.3'
1413
end

lib/aspose_words_cloud/api/words_api.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
require 'uri'
2727
require 'json'
28+
require 'faraday'
2829

2930
module AsposeWordsCloud
3031
#
@@ -40,6 +41,26 @@ def initialize(api_client = ApiClient.default)
4041
request_token
4142
end
4243

44+
def batch(requests)
45+
raise ArgumentError, 'Requests array is nil' unless requests != nil
46+
raise ArgumentError, 'There must be at least one request' unless requests.length != 0
47+
form_params = {}
48+
request_token
49+
header_params = {'Content-Type' => 'multipart/form-data'}
50+
@api_client.update_params_for_auth! header_params, {}, "JWT"
51+
requests.each_with_index do |request, index|
52+
form_params["request-#{index}"] = Faraday::ParamPart.new(request.to_batch_part(@api_client), "application/http; msgtype=request")
53+
end
54+
data, status_code, headers = @api_client.call_api(:PUT, "/v4.0/words/batch",
55+
header_params: header_params,
56+
query_params: {},
57+
form_params: form_params,
58+
body: nil,
59+
batch: true,
60+
parts: requests,
61+
auth_names: ['JWT'])
62+
end
63+
4364
# Accepts all revisions in the document.
4465
# @param request AcceptAllRevisionsRequest
4566
# @return [RevisionsModificationResponse]

lib/aspose_words_cloud/api_client.rb

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
require 'tempfile'
3030
require 'uri'
3131
require 'faraday'
32-
require 'mimemagic'
32+
require 'marcel'
3333
require 'multipart_parser/reader'
3434
require_relative 'version'
3535
require_relative 'api_error'
@@ -96,6 +96,8 @@ def call_api(http_method, path, opts = {})
9696

9797
if opts[:multipart_response] == true
9898
data = deserialize_multipart(response)
99+
elsif opts[:batch] == true
100+
data = deserialize_batch(response, opts[:parts])
99101
else
100102
data = deserialize(response.body, opts[:return_type]) if opts[:return_type]
101103
end
@@ -223,6 +225,50 @@ def deserialize_multipart(response)
223225
parts
224226
end
225227

228+
# Deserialize batch
229+
def deserialize_batch(response, requests)
230+
result = { errors: [], parts: [] }
231+
def result.part(name)
232+
hash = self[:parts].detect { |h| h[:part].name == name }
233+
[hash[:part], hash[:body].join]
234+
end
235+
responses_data = []
236+
content_type = response.headers['content-type']
237+
reader = MultipartParser::Reader.new(MultipartParser::Reader::extract_boundary_value(content_type))
238+
reader.on_part do |part|
239+
result[:parts] << thispart = {
240+
part: part,
241+
body: []
242+
}
243+
part.on_data do |chunk|
244+
thispart[:body] << chunk
245+
end
246+
end
247+
reader.on_error do |msg|
248+
result[:errors] << msg
249+
end
250+
reader.write response.body
251+
reader.ended? or raise Exception, 'Truncated multipart message'
252+
253+
separator = "\r\n\r\n"
254+
result[:parts].each do |part|
255+
part[:body] = part[:body].join("")
256+
part_body = part[:body]
257+
data_index = part_body.index(separator)
258+
if data_index != nil
259+
header_data = part_body[0..data_index]
260+
body_data = part_body[data_index+separator.length, part_body.length]
261+
part[:body] = body_data
262+
end
263+
end
264+
265+
result[:parts].each_with_index do |response_data, index|
266+
return_type = requests[index].get_response_type
267+
responses_data.push(deserialize(response_data[:body], return_type))
268+
end
269+
responses_data
270+
end
271+
226272
# Convert data to the given return type.
227273
# @param [Object] data Data to be converted
228274
# @param [String] return_type Return type
@@ -339,14 +385,43 @@ def build_request_url(path)
339385
# @return [String] HTTP body data in the form of string
340386
def build_request_body(header_params, form_params, body)
341387
# http form
342-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
343-
header_params['Content-Type'] == 'multipart/form-data'
388+
if header_params['Content-Type']['application/x-www-form-urlencoded'] ||
389+
header_params['Content-Type']['multipart/form-data']
390+
data = {}
391+
form_params.each do |key, value|
392+
case value
393+
when ::File, ::Tempfile
394+
data[key] = Faraday::UploadIO.new(value.path, Marcel::Magic.by_magic(value).to_s, key)
395+
when ::Array, nil, Faraday::ParamPart
396+
data[key] = value
397+
else
398+
data[key] = value.to_s
399+
end
400+
end
401+
elsif body
402+
data = body.is_a?(String) ? body : body.to_json
403+
else
404+
data = nil
405+
end
406+
data
407+
end
408+
409+
# Builds the HTTP request body
410+
#
411+
# @param [Hash] header_params Header parameters
412+
# @param [Hash] form_params Query parameters
413+
# @param [Object] body HTTP body (JSON/XML)
414+
# @return [String] HTTP body data in the form of string
415+
def build_request_body_batch(header_params, form_params, body)
416+
# http form
417+
if header_params['Content-Type']['application/x-www-form-urlencoded'] ||
418+
header_params['Content-Type']['multipart/form-data']
344419
data = {}
345420
form_params.each do |key, value|
346421
case value
347-
when ::File
348-
data[key] = Faraday::UploadIO.new(value.path, MimeMagic.by_magic(value).to_s, key)
349-
when ::Array, nil
422+
when ::File, ::Tempfile
423+
data[key] = File.open(value.path, 'rb') { |f| f.read }
424+
when ::Array, nil, Faraday::ParamPart
350425
data[key] = value
351426
else
352427
data[key] = value.to_s
@@ -360,6 +435,18 @@ def build_request_body(header_params, form_params, body)
360435
data
361436
end
362437

438+
# Append query parameter to url
439+
#
440+
# @param [String] url current url
441+
# @param [String] param_name query parameter name
442+
# @param [String] param_value query parameter value
443+
def add_param_to_query(url, param_name, param_value)
444+
uri = URI(url)
445+
params = URI.decode_www_form(uri.query || "") << [param_name, param_value]
446+
uri.query = URI.encode_www_form(params)
447+
uri.to_s
448+
end
449+
363450
# Update hearder and query params based on authentication settings.
364451
#
365452
# @param [Hash] header_params Header parameters

lib/aspose_words_cloud/configuration.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def getFullUrl(path, withoutVersion)
119119
return URI.join(baseUrl, path).to_s
120120
end
121121

122-
return URI.join(baseUrl, "/v4.0/", URI.encode(path)).to_s
122+
p = URI::Parser.new
123+
URI.join(baseUrl, "/v4.0/", p.escape(path)).to_s
123124
end
124125

125126
# Gets API key (with prefix if set).

lib/aspose_words_cloud/models/requests/accept_all_revisions_online_request.rb

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,104 @@ def initialize(document, load_encoding = nil, password = nil, dest_file_name = n
5454
self.password = password
5555
self.dest_file_name = dest_file_name
5656
end
57+
58+
# Creating batch part from request
59+
def to_batch_part(api_client)
60+
# verify the required parameter 'document' is set
61+
raise ArgumentError, 'Missing the required parameter document when calling WordsApi.accept_all_revisions_online' if api_client.config.client_side_validation && self.document.nil?
62+
63+
# resource path
64+
local_var_path = '/words/online/put/revisions/acceptAll'[7..-1]
65+
local_var_path = local_var_path.sub('//', '/')
66+
67+
# query parameters
68+
query_params = {}
69+
query_params[downcase_first_letter('LoadEncoding')] = self.load_encoding unless self.load_encoding.nil?
70+
query_params[downcase_first_letter('Password')] = self.password unless self.password.nil?
71+
query_params[downcase_first_letter('DestFileName')] = self.dest_file_name unless self.dest_file_name.nil?
72+
73+
if query_params
74+
query_params.each { |key, value| local_var_path = api_client.add_param_to_query(local_var_path, key, value) }
75+
end
76+
77+
header_params = {}
78+
# header parameters
79+
# HTTP header 'Content-Type'
80+
header_params['Content-Type'] = api_client.select_header_content_type(['multipart/form-data'])
81+
82+
# form parameters
83+
form_params = {}
84+
form_params[downcase_first_letter('Document')] = self.document
85+
86+
# http body (model)
87+
post_body = nil
88+
body = api_client.build_request_body_batch(header_params, form_params, post_body)
89+
part = ""
90+
part.concat("PUT".force_encoding('UTF-8'))
91+
part.concat(" ".force_encoding('UTF-8'))
92+
part.concat(local_var_path.force_encoding('UTF-8'))
93+
part.concat(" \r\n".force_encoding('UTF-8'))
94+
95+
header_params.each_pair {|key, value| part.concat(key.dup.force_encoding('UTF-8') , ": ".force_encoding('UTF-8'), value.dup.force_encoding('UTF-8'), "\r\n".force_encoding('UTF-8')) }
96+
part.concat("\r\n".force_encoding('UTF-8'))
97+
if body
98+
if body.is_a?(Hash)
99+
body.each do |key, value|
100+
part.concat(value, "\r\n")
101+
end
102+
else
103+
part.concat(body)
104+
end
105+
end
106+
part
107+
end
108+
109+
def create_http_request(api_client)
110+
# verify the required parameter 'document' is set
111+
raise ArgumentError, 'Missing the required parameter document when calling WordsApi.accept_all_revisions_online' if api_client.config.client_side_validation && self.document.nil?
112+
113+
# resource path
114+
local_var_path = '/words/online/put/revisions/acceptAll'[1..-1]
115+
local_var_path = local_var_path.sub('//', '/')
116+
117+
# query parameters
118+
query_params = {}
119+
query_params[downcase_first_letter('LoadEncoding')] = self.load_encoding unless self.load_encoding.nil?
120+
query_params[downcase_first_letter('Password')] = self.password unless self.password.nil?
121+
query_params[downcase_first_letter('DestFileName')] = self.dest_file_name unless self.dest_file_name.nil?
122+
123+
# header parameters
124+
header_params = {}
125+
# HTTP header 'Content-Type'
126+
header_params['Content-Type'] = api_client.select_header_content_type(['multipart/form-data'])
127+
128+
# form parameters
129+
form_params = {}
130+
form_params[downcase_first_letter('Document')] = self.document
131+
132+
# http body (model)
133+
post_body = nil
134+
body = api_client.build_request_body(header_params, form_params, post_body)
135+
{
136+
'method': :PUT,
137+
'path': local_var_path,
138+
'header_params': header_params,
139+
'query_params': query_params,
140+
'body': body,
141+
'auth_names': ['JWT']
142+
}
143+
end
144+
145+
#
146+
# Helper method to convert first letter to downcase
147+
#
148+
def downcase_first_letter(str)
149+
str[0].downcase + str[1..-1]
150+
end
151+
152+
# Get response type
153+
def get_response_type
154+
'AcceptAllRevisionsOnlineResponse'
155+
end
57156
end
58157
end

0 commit comments

Comments
 (0)