aspose_email_cloud 18.7.0 → 19.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aspose-email-cloud.rb +145 -0
- data/lib/aspose-email-cloud/api/email_api.rb +577 -0
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/api_client.rb +125 -133
- data/lib/aspose-email-cloud/api_error.rb +42 -0
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/configuration.rb +56 -43
- data/lib/aspose-email-cloud/models/account_base_request.rb +250 -0
- data/lib/aspose-email-cloud/models/add_attachment_request.rb +219 -0
- data/lib/aspose-email-cloud/models/append_email_account_base_request.rb +300 -0
- data/lib/aspose-email-cloud/models/append_email_base_request.rb +316 -0
- data/lib/aspose-email-cloud/models/append_email_mime_base_request.rb +335 -0
- data/lib/aspose-email-cloud/models/base_object.rb +225 -0
- data/lib/aspose-email-cloud/models/contact_format.rb +45 -0
- data/lib/aspose-email-cloud/models/create_email_request.rb +224 -0
- data/lib/aspose-email-cloud/models/create_folder_base_request.rb +297 -0
- data/lib/aspose-email-cloud/models/delete_folder_base_request.rb +302 -0
- data/lib/aspose-email-cloud/models/delete_message_base_request.rb +302 -0
- data/lib/aspose-email-cloud/models/disc_usage.rb +229 -0
- data/lib/aspose-email-cloud/models/email_account_request.rb +342 -0
- data/lib/aspose-email-cloud/models/email_document.rb +226 -0
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/models/email_document_response.rb +105 -109
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/models/email_properties.rb +122 -97
- data/lib/aspose-email-cloud/models/email_property.rb +256 -0
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/models/email_property_response.rb +105 -109
- data/lib/aspose-email-cloud/models/error.rb +241 -0
- data/lib/aspose-email-cloud/models/error_details.rb +224 -0
- data/lib/aspose-email-cloud/models/file_version.rb +289 -0
- data/lib/aspose-email-cloud/models/file_versions.rb +210 -0
- data/lib/aspose-email-cloud/models/files_list.rb +210 -0
- data/lib/aspose-email-cloud/models/files_upload_result.rb +223 -0
- data/lib/aspose-email-cloud/models/hierarchical_object.rb +238 -0
- data/lib/aspose-email-cloud/models/hierarchical_object_request.rb +224 -0
- data/lib/aspose-email-cloud/models/hierarchical_object_response.rb +219 -0
- data/lib/aspose-email-cloud/models/indexed_hierarchical_object.rb +254 -0
- data/lib/aspose-email-cloud/models/indexed_primitive_object.rb +252 -0
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/models/link.rb +138 -116
- data/lib/aspose-email-cloud/models/list_response_of_hierarchical_object_response.rb +208 -0
- data/{src/asposeemailcloud/models/email_document.rb → lib/aspose-email-cloud/models/list_response_of_mail_server_folder.rb} +105 -98
- data/{src/asposeemailcloud/models/list_folders_response.rb → lib/aspose-email-cloud/models/list_response_of_string.rb} +105 -111
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/models/mail_server_folder.rb +116 -96
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/models/mime_response.rb +105 -109
- data/lib/aspose-email-cloud/models/object_exist.rb +229 -0
- data/lib/aspose-email-cloud/models/primitive_object.rb +236 -0
- data/lib/aspose-email-cloud/models/requests/add_calendar_attachment_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/add_contact_attachment_request_data.rb +101 -0
- data/lib/aspose-email-cloud/models/requests/add_email_attachment_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/add_mapi_attachment_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/append_email_message_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/append_mime_message_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/copy_file_request_data.rb +92 -0
- data/lib/aspose-email-cloud/models/requests/copy_folder_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/create_calendar_request_data.rb +82 -0
- data/lib/aspose-email-cloud/models/requests/create_contact_request_data.rb +94 -0
- data/lib/aspose-email-cloud/models/requests/create_email_folder_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/create_email_request_data.rb +82 -0
- data/lib/aspose-email-cloud/models/requests/create_folder_request_data.rb +78 -0
- data/lib/aspose-email-cloud/models/requests/create_mapi_request_data.rb +82 -0
- data/lib/aspose-email-cloud/models/requests/delete_calendar_property_request_data.rb +96 -0
- data/lib/aspose-email-cloud/models/requests/delete_contact_property_request_data.rb +108 -0
- data/lib/aspose-email-cloud/models/requests/delete_email_folder_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/delete_email_message_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/delete_file_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/delete_folder_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/delete_mapi_attachment_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/delete_mapi_properties_request_data.rb +82 -0
- data/lib/aspose-email-cloud/models/requests/download_file_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/email_request.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/fetch_email_message_request_data.rb +93 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_attachment_request_data.rb +88 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_list_request_data.rb +95 -0
- data/lib/aspose-email-cloud/models/requests/get_calendar_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_attachment_request_data.rb +100 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_list_request_data.rb +92 -0
- data/lib/aspose-email-cloud/models/requests/get_contact_properties_request_data.rb +93 -0
- data/lib/aspose-email-cloud/models/requests/get_disc_usage_request_data.rb +71 -0
- data/lib/aspose-email-cloud/models/requests/get_email_attachment_request_data.rb +88 -0
- data/lib/aspose-email-cloud/models/requests/get_email_property_request_data.rb +88 -0
- data/lib/aspose-email-cloud/models/requests/get_email_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/get_file_versions_request_data.rb +78 -0
- data/lib/aspose-email-cloud/models/requests/get_files_list_request_data.rb +78 -0
- data/lib/aspose-email-cloud/models/requests/get_mapi_attachment_request_data.rb +88 -0
- data/lib/aspose-email-cloud/models/requests/get_mapi_attachments_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/get_mapi_list_request_data.rb +80 -0
- data/lib/aspose-email-cloud/models/requests/get_mapi_properties_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/http_request.rb +51 -0
- data/lib/aspose-email-cloud/models/requests/list_email_folders_request_data.rb +88 -0
- data/lib/aspose-email-cloud/models/requests/list_email_messages_request_data.rb +105 -0
- data/lib/aspose-email-cloud/models/requests/move_file_request_data.rb +92 -0
- data/lib/aspose-email-cloud/models/requests/move_folder_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/object_exists_request_data.rb +81 -0
- data/lib/aspose-email-cloud/models/requests/save_mail_account_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/save_mail_o_auth_account_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/send_email_mime_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/send_email_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/set_email_property_request_data.rb +89 -0
- data/lib/aspose-email-cloud/models/requests/set_email_read_flag_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/storage_exists_request_data.rb +75 -0
- data/lib/aspose-email-cloud/models/requests/update_calendar_properties_request_data.rb +82 -0
- data/lib/aspose-email-cloud/models/requests/update_contact_properties_request_data.rb +94 -0
- data/lib/aspose-email-cloud/models/requests/update_mapi_properties_request_data.rb +82 -0
- data/lib/aspose-email-cloud/models/requests/upload_file_request_data.rb +87 -0
- data/lib/aspose-email-cloud/models/save_email_account_request.rb +377 -0
- data/lib/aspose-email-cloud/models/save_o_auth_email_account_request.rb +447 -0
- data/lib/aspose-email-cloud/models/send_email_base_request.rb +267 -0
- data/lib/aspose-email-cloud/models/send_email_mime_base_request.rb +286 -0
- data/lib/aspose-email-cloud/models/set_email_property_request.rb +224 -0
- data/lib/aspose-email-cloud/models/set_message_read_flag_account_base_request.rb +302 -0
- data/{src/asposeemailcloud/models/email_property.rb → lib/aspose-email-cloud/models/storage_exist.rb} +110 -96
- data/lib/aspose-email-cloud/models/storage_file.rb +262 -0
- data/lib/aspose-email-cloud/models/storage_file_location.rb +254 -0
- data/lib/aspose-email-cloud/models/storage_folder_location.rb +219 -0
- data/{src/asposeemailcloud/models/list_response.rb → lib/aspose-email-cloud/models/value_response.rb} +105 -111
- data/{src/asposeemailcloud → lib/aspose-email-cloud}/version.rb +4 -4
- metadata +128 -38
- data/src/asposeemailcloud.rb +0 -55
- data/src/asposeemailcloud/api/email_api.rb +0 -418
- data/src/asposeemailcloud/api/email_client_api.rb +0 -960
- data/src/asposeemailcloud/api_error.rb +0 -38
- data/src/asposeemailcloud/models/http_status_code.rb +0 -76
- data/src/asposeemailcloud/models/protocol_type.rb +0 -34
- data/src/asposeemailcloud/models/saa_spose_response.rb +0 -202
- data/src/asposeemailcloud/models/security_options.rb +0 -33
@@ -1,23 +1,40 @@
|
|
1
|
-
|
2
|
-
#Aspose.
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose" file="api_client.rb">
|
3
|
+
# Copyright (c) 2018-2019 Aspose Pty Ltd. All rights reserved.
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
7
|
+
# copy of this software and associated documentation files (the "Software"),
|
8
|
+
# to deal in the Software without restriction, including without limitation
|
9
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
11
|
+
# Software is furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all 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
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
|
+
# DEALINGS IN THE SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# ----------------------------------------------------------------------------
|
12
25
|
|
13
26
|
require 'date'
|
14
27
|
require 'json'
|
15
28
|
require 'logger'
|
16
29
|
require 'tempfile'
|
17
|
-
require '
|
30
|
+
require 'faraday'
|
31
|
+
require 'mimemagic'
|
18
32
|
require 'uri'
|
19
33
|
|
20
|
-
module
|
34
|
+
module AsposeEmailCloud
|
35
|
+
# Generic API client
|
36
|
+
# Swagger generic API client. This client handles the client-
|
37
|
+
# server communication, and is invariant across implementations.
|
21
38
|
class ApiClient
|
22
39
|
# The Configuration object holding settings to be used in the API client.
|
23
40
|
attr_accessor :config
|
@@ -28,53 +45,47 @@ module asposeemailcloud
|
|
28
45
|
attr_accessor :default_headers
|
29
46
|
|
30
47
|
# Initializes the ApiClient
|
31
|
-
# @
|
32
|
-
|
33
|
-
|
34
|
-
|
48
|
+
# @param [String] app_key Key to access the server.
|
49
|
+
# @param [String] app_sid ID to access the server.
|
50
|
+
# @param [String] base_url Server URL.
|
51
|
+
# @param [String] api_version Api version.
|
52
|
+
# @param [Object] debug Debug switch [true, false].
|
53
|
+
def initialize(app_key = nil, app_sid = nil, base_url = 'api-qa.aspose.cloud', api_version = 'v3.0', debug = false)
|
54
|
+
@config = Configuration.new(app_key, app_sid, base_url, api_version, debug)
|
35
55
|
@default_headers = {
|
36
|
-
'
|
37
|
-
'
|
56
|
+
'x-aspose-client' => 'ruby sdk',
|
57
|
+
'x-aspose-version' => '19.7'
|
38
58
|
}
|
39
59
|
end
|
40
60
|
|
41
|
-
def self.default
|
42
|
-
@@default ||= ApiClient.new
|
43
|
-
end
|
44
|
-
|
45
61
|
# Call an API with given options.
|
46
62
|
#
|
47
63
|
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
48
64
|
# the data deserialized from response body (could be nil), response status code and response headers.
|
49
65
|
def call_api(http_method, path, opts = {})
|
50
|
-
|
51
|
-
response
|
66
|
+
response = build_request(http_method, path, opts)
|
67
|
+
download_file response if opts[:return_type] == 'File'
|
52
68
|
|
53
69
|
if @config.debugging
|
54
|
-
@config.logger.debug "HTTP response body ~BEGIN
|
70
|
+
@config.logger.debug "'HTTP' response body '~BEGIN~'\n #{response.body}\n'~END~'\n"
|
55
71
|
end
|
56
72
|
|
57
73
|
unless response.success?
|
58
|
-
if response.
|
59
|
-
fail ApiError.new('Connection timed out')
|
60
|
-
elsif response.code == 0
|
74
|
+
if response.status.zero?
|
61
75
|
# Errors from libcurl will be made visible here
|
62
|
-
|
63
|
-
:message => response.return_message)
|
76
|
+
raise ApiError.new(response.return_message, 0)
|
64
77
|
else
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
begin
|
79
|
+
error = convert_to_type(JSON.parse(response.body, symbolize_names: true)[:error], "Error")
|
80
|
+
ensure
|
81
|
+
raise ApiError.new("#{response.status} Error connecting to the API #{path}; Message: #{error}",
|
82
|
+
response.status, error)
|
83
|
+
end
|
69
84
|
end
|
70
85
|
end
|
71
86
|
|
72
|
-
if opts[:return_type]
|
73
|
-
|
74
|
-
else
|
75
|
-
data = nil
|
76
|
-
end
|
77
|
-
return data, response.code, response.headers
|
87
|
+
data = (deserialize(response, opts[:return_type]) if opts[:return_type])
|
88
|
+
[data, response.status, response.headers]
|
78
89
|
end
|
79
90
|
|
80
91
|
# Builds the HTTP request
|
@@ -85,7 +96,7 @@ module asposeemailcloud
|
|
85
96
|
# @option opts [Hash] :query_params Query parameters
|
86
97
|
# @option opts [Hash] :form_params Query parameters
|
87
98
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
88
|
-
# @return [
|
99
|
+
# @return [Faraday::Response] A Faraday Response
|
89
100
|
def build_request(http_method, path, opts = {})
|
90
101
|
url = build_request_url(path)
|
91
102
|
http_method = http_method.to_sym.downcase
|
@@ -93,39 +104,45 @@ module asposeemailcloud
|
|
93
104
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
94
105
|
query_params = opts[:query_params] || {}
|
95
106
|
form_params = opts[:form_params] || {}
|
107
|
+
body = opts[:body] if opts[:body] || nil?
|
96
108
|
|
97
109
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
98
110
|
|
99
|
-
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
100
|
-
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
101
|
-
|
102
111
|
req_opts = {
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
:timeout => @config.timeout,
|
108
|
-
:ssl_verifypeer => @config.verify_ssl,
|
109
|
-
:ssl_verifyhost => _verify_ssl_host,
|
110
|
-
:sslcert => @config.cert_file,
|
111
|
-
:sslkey => @config.key_file,
|
112
|
-
:verbose => @config.debugging
|
112
|
+
:method => http_method,
|
113
|
+
:headers => header_params,
|
114
|
+
:params => query_params,
|
115
|
+
:body => body
|
113
116
|
}
|
114
117
|
|
115
|
-
# set custom cert, if provided
|
116
|
-
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
117
|
-
|
118
118
|
if [:post, :patch, :put, :delete].include?(http_method)
|
119
119
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
120
120
|
req_opts.update :body => req_body
|
121
121
|
if @config.debugging
|
122
122
|
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
123
123
|
end
|
124
|
+
elsif http_method == :get && body.nil? && !form_params.any? && header_params['Content-Type'] == 'multipart/form-data'
|
125
|
+
req_opts[:headers].delete('Content-Type')
|
126
|
+
end
|
127
|
+
|
128
|
+
conn = Faraday.new url, { :params => query_params, :headers => header_params } do |f|
|
129
|
+
f.request :multipart
|
130
|
+
f.request :url_encoded
|
131
|
+
f.adapter Faraday.default_adapter
|
124
132
|
end
|
125
133
|
|
126
|
-
|
127
|
-
|
128
|
-
|
134
|
+
case http_method
|
135
|
+
when :post
|
136
|
+
return conn.post url, req_opts[:body]
|
137
|
+
when :put
|
138
|
+
return conn.put url, req_opts[:body]
|
139
|
+
when :get
|
140
|
+
return conn.get url, req_opts[:body]
|
141
|
+
else
|
142
|
+
return conn.delete url do |c|
|
143
|
+
c.body = req_opts[:body]
|
144
|
+
end
|
145
|
+
end
|
129
146
|
end
|
130
147
|
|
131
148
|
# Check if the given MIME is a JSON MIME.
|
@@ -137,7 +154,7 @@ module asposeemailcloud
|
|
137
154
|
# @param [String] mime MIME
|
138
155
|
# @return [Boolean] True if the MIME is application/json
|
139
156
|
def json_mime?(mime)
|
140
|
-
|
157
|
+
(mime == '*/*') || !(mime =~ %r{Application/.*json(?!p)(;.*)?}i).nil?
|
141
158
|
end
|
142
159
|
|
143
160
|
# Deserialize the response to the given return type.
|
@@ -159,12 +176,12 @@ module asposeemailcloud
|
|
159
176
|
# ensuring a default content type
|
160
177
|
content_type = response.headers['Content-Type'] || 'application/json'
|
161
178
|
|
162
|
-
|
179
|
+
raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
163
180
|
|
164
181
|
begin
|
165
|
-
data = JSON.parse("[#{body}]", :
|
182
|
+
data = JSON.parse("[#{body}]", symbolize_names: true)[0]
|
166
183
|
rescue JSON::ParserError => e
|
167
|
-
if %w
|
184
|
+
if %w[String Date DateTime].include?(return_type)
|
168
185
|
data = body
|
169
186
|
else
|
170
187
|
raise e
|
@@ -180,6 +197,7 @@ module asposeemailcloud
|
|
180
197
|
# @return [Mixed] Data in a particular type
|
181
198
|
def convert_to_type(data, return_type)
|
182
199
|
return nil if data.nil?
|
200
|
+
|
183
201
|
case return_type
|
184
202
|
when 'String'
|
185
203
|
data.to_s
|
@@ -200,17 +218,17 @@ module asposeemailcloud
|
|
200
218
|
data
|
201
219
|
when /\AArray<(.+)>\z/
|
202
220
|
# e.g. Array<Pet>
|
203
|
-
sub_type =
|
204
|
-
data.map {|item| convert_to_type(item, sub_type) }
|
221
|
+
sub_type = Regexp.last_match(1)
|
222
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
205
223
|
when /\AHash\<String, (.+)\>\z/
|
206
224
|
# e.g. Hash<String, Integer>
|
207
|
-
sub_type =
|
225
|
+
sub_type = Regexp.last_match(1)
|
208
226
|
{}.tap do |hash|
|
209
|
-
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
227
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
210
228
|
end
|
211
229
|
else
|
212
230
|
# models, e.g. Pet
|
213
|
-
|
231
|
+
AsposeEmailCloud.const_get(return_type).new.tap do |model|
|
214
232
|
model.build_from_hash data
|
215
233
|
end
|
216
234
|
end
|
@@ -223,27 +241,22 @@ module asposeemailcloud
|
|
223
241
|
# process can use.
|
224
242
|
#
|
225
243
|
# @see Configuration#temp_folder_path
|
226
|
-
def download_file(
|
244
|
+
def download_file(response)
|
227
245
|
tempfile = nil
|
228
246
|
encoding = nil
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
prefix = 'download-'
|
236
|
-
end
|
237
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
238
|
-
encoding = response.body.encoding
|
239
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
240
|
-
@tempfile = tempfile
|
241
|
-
end
|
242
|
-
request.on_body do |chunk|
|
243
|
-
chunk.force_encoding(encoding)
|
244
|
-
tempfile.write(chunk)
|
247
|
+
content_disposition = response.headers['Content-Disposition']
|
248
|
+
if content_disposition and content_disposition =~ /filename=/i
|
249
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
250
|
+
prefix = sanitize_filename(filename)
|
251
|
+
else
|
252
|
+
prefix = 'download-'
|
245
253
|
end
|
246
|
-
|
254
|
+
prefix += '-' unless prefix.end_with?('-')
|
255
|
+
encoding = response.body.encoding
|
256
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
257
|
+
@tempfile = tempfile
|
258
|
+
tempfile.write(response.body)
|
259
|
+
response.on_complete do |resp|
|
247
260
|
tempfile.close
|
248
261
|
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
249
262
|
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
@@ -258,12 +271,12 @@ module asposeemailcloud
|
|
258
271
|
# @param [String] filename the filename to be sanitized
|
259
272
|
# @return [String] the sanitized filename
|
260
273
|
def sanitize_filename(filename)
|
261
|
-
filename.gsub(
|
274
|
+
filename.gsub(%r{.*[/\\]}, '')
|
262
275
|
end
|
263
276
|
|
264
277
|
def build_request_url(path)
|
265
278
|
# Add leading and trailing slashes to path
|
266
|
-
path = "/#{path}".gsub(
|
279
|
+
path = "/#{path}".gsub(%r{/+}, '/')
|
267
280
|
URI.encode(@config.base_url + path)
|
268
281
|
end
|
269
282
|
|
@@ -275,13 +288,16 @@ module asposeemailcloud
|
|
275
288
|
# @return [String] HTTP body data in the form of string
|
276
289
|
def build_request_body(header_params, form_params, body)
|
277
290
|
# http form
|
278
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
279
|
-
|
291
|
+
if (header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
292
|
+
header_params['Content-Type'] == 'multipart/form-data') && form_params.any?
|
280
293
|
data = {}
|
281
294
|
form_params.each do |key, value|
|
282
295
|
case value
|
283
|
-
when File
|
284
|
-
|
296
|
+
when ::File
|
297
|
+
data[key] = Faraday::UploadIO.new(value.path, MimeMagic.by_magic(value).to_s, key)
|
298
|
+
when ::Tempfile
|
299
|
+
data[key] = Faraday::UploadIO.new(value.path, key)
|
300
|
+
when ::Array, nil
|
285
301
|
data[key] = value
|
286
302
|
else
|
287
303
|
data[key] = value.to_s
|
@@ -302,56 +318,32 @@ module asposeemailcloud
|
|
302
318
|
# @param [String] auth_names Authentication scheme name
|
303
319
|
def update_params_for_auth!(header_params, query_params, auth_names)
|
304
320
|
Array(auth_names).each do |auth_name|
|
305
|
-
auth_setting = @config.auth_settings[auth_name]
|
321
|
+
auth_setting = @config.auth_settings[auth_name.to_sym]
|
306
322
|
next unless auth_setting
|
323
|
+
|
307
324
|
case auth_setting[:in]
|
308
|
-
when 'header'
|
309
|
-
|
310
|
-
|
325
|
+
when 'header'
|
326
|
+
header_params[auth_setting[:key]] = auth_setting[:value]
|
327
|
+
when 'query'
|
328
|
+
query_params[auth_setting[:key]] = auth_setting[:value]
|
329
|
+
else
|
330
|
+
raise ArgumentError, 'Authentication token must be in `query` of `header`'
|
311
331
|
end
|
312
332
|
end
|
313
333
|
end
|
314
334
|
|
315
|
-
# Sets user agent in HTTP header
|
316
|
-
#
|
317
|
-
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
318
|
-
def user_agent=(user_agent)
|
319
|
-
@user_agent = user_agent
|
320
|
-
@default_headers['User-Agent'] = @user_agent
|
321
|
-
end
|
322
|
-
|
323
|
-
# Return Accept header based on an array of accepts provided.
|
324
|
-
# @param [Array] accepts array for Accept
|
325
|
-
# @return [String] the Accept header (e.g. application/json)
|
326
|
-
def select_header_accept(accepts)
|
327
|
-
return nil if accepts.nil? || accepts.empty?
|
328
|
-
# use JSON when present, otherwise use all of the provided
|
329
|
-
json_accept = accepts.find { |s| json_mime?(s) }
|
330
|
-
return json_accept || accepts.join(',')
|
331
|
-
end
|
332
|
-
|
333
|
-
# Return Content-Type header based on an array of content types provided.
|
334
|
-
# @param [Array] content_types array for Content-Type
|
335
|
-
# @return [String] the Content-Type header (e.g. application/json)
|
336
|
-
def select_header_content_type(content_types)
|
337
|
-
# use application/json by default
|
338
|
-
return 'application/json' if content_types.nil? || content_types.empty?
|
339
|
-
# use JSON when present, otherwise use the first one
|
340
|
-
json_content_type = content_types.find { |s| json_mime?(s) }
|
341
|
-
return json_content_type || content_types.first
|
342
|
-
end
|
343
|
-
|
344
335
|
# Convert object (array, hash, object, etc) to JSON string.
|
345
336
|
# @param [Object] model object to be converted into JSON string
|
346
337
|
# @return [String] JSON string representation of the object
|
347
338
|
def object_to_http_body(model)
|
348
339
|
return model if model.nil? || model.is_a?(String)
|
340
|
+
|
349
341
|
local_body = nil
|
350
|
-
if model.is_a?(Array)
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
342
|
+
local_body = if model.is_a?(Array)
|
343
|
+
model.map { |m| object_to_hash(m) }
|
344
|
+
else
|
345
|
+
object_to_hash(model)
|
346
|
+
end
|
355
347
|
local_body.to_json
|
356
348
|
end
|
357
349
|
|
@@ -382,7 +374,7 @@ module asposeemailcloud
|
|
382
374
|
# return the array directly as typhoeus will handle it as expected
|
383
375
|
param
|
384
376
|
else
|
385
|
-
|
377
|
+
raise "unknown collection format: #{collection_format.inspect}"
|
386
378
|
end
|
387
379
|
end
|
388
380
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose" file="api_error.rb">
|
3
|
+
# Copyright (c) 2018-2019 Aspose Pty Ltd. All rights reserved.
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
7
|
+
# copy of this software and associated documentation files (the "Software"),
|
8
|
+
# to deal in the Software without restriction, including without limitation
|
9
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
11
|
+
# Software is furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all 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
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
|
+
# DEALINGS IN THE SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# ----------------------------------------------------------------------------
|
25
|
+
|
26
|
+
|
27
|
+
module AsposeEmailCloud
|
28
|
+
# Email API Exception
|
29
|
+
class ApiError < StandardError
|
30
|
+
attr_reader :message, :code, :error
|
31
|
+
|
32
|
+
# Initializes a new instance of the ApiError class
|
33
|
+
# @param [String] message
|
34
|
+
# @param [String] code
|
35
|
+
# @param [String] error
|
36
|
+
def initialize(message, code, error = nil)
|
37
|
+
@message = message
|
38
|
+
@code = code
|
39
|
+
@error = error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|