aspose_email_cloud 1.0.2 → 18.7.0

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 (40) hide show
  1. checksums.yaml +5 -5
  2. data/src/asposeemailcloud.rb +55 -0
  3. data/src/asposeemailcloud/api/email_api.rb +418 -0
  4. data/src/asposeemailcloud/api/email_client_api.rb +960 -0
  5. data/src/asposeemailcloud/api_client.rb +389 -0
  6. data/src/asposeemailcloud/api_error.rb +38 -0
  7. data/{lib/aspose_email_cloud → src/asposeemailcloud}/configuration.rb +223 -166
  8. data/src/asposeemailcloud/models/email_document.rb +201 -0
  9. data/src/asposeemailcloud/models/email_document_response.rb +212 -0
  10. data/src/asposeemailcloud/models/email_properties.rb +200 -0
  11. data/src/asposeemailcloud/models/email_property.rb +199 -0
  12. data/src/asposeemailcloud/models/email_property_response.rb +212 -0
  13. data/src/asposeemailcloud/models/http_status_code.rb +76 -0
  14. data/src/asposeemailcloud/models/link.rb +219 -0
  15. data/src/asposeemailcloud/models/list_folders_response.rb +214 -0
  16. data/src/asposeemailcloud/models/list_response.rb +214 -0
  17. data/src/asposeemailcloud/models/mail_server_folder.rb +199 -0
  18. data/src/asposeemailcloud/models/mime_response.rb +212 -0
  19. data/src/asposeemailcloud/models/protocol_type.rb +34 -0
  20. data/src/asposeemailcloud/models/saa_spose_response.rb +202 -0
  21. data/src/asposeemailcloud/models/security_options.rb +33 -0
  22. data/src/asposeemailcloud/version.rb +15 -0
  23. metadata +173 -53
  24. data/LICENSE +0 -22
  25. data/README.md +0 -49
  26. data/aspose_email_cloud.gemspec +0 -26
  27. data/lib/aspose_email_cloud.rb +0 -38
  28. data/lib/aspose_email_cloud/api/email_api.rb +0 -431
  29. data/lib/aspose_email_cloud/api_client.rb +0 -335
  30. data/lib/aspose_email_cloud/api_error.rb +0 -24
  31. data/lib/aspose_email_cloud/models/base_object.rb +0 -88
  32. data/lib/aspose_email_cloud/models/email_document.rb +0 -63
  33. data/lib/aspose_email_cloud/models/email_document_response.rb +0 -79
  34. data/lib/aspose_email_cloud/models/email_properties.rb +0 -47
  35. data/lib/aspose_email_cloud/models/email_property.rb +0 -53
  36. data/lib/aspose_email_cloud/models/email_property_response.rb +0 -61
  37. data/lib/aspose_email_cloud/models/link.rb +0 -61
  38. data/lib/aspose_email_cloud/models/stream.rb +0 -37
  39. data/lib/aspose_email_cloud/version.rb +0 -3
  40. data/test/email_tests.rb +0 -111
@@ -1,335 +0,0 @@
1
- require 'date'
2
- require 'json'
3
- require 'logger'
4
- require 'tempfile'
5
- require 'typhoeus'
6
- require 'uri'
7
- require 'openssl'
8
- require 'base64'
9
- require 'rexml/document'
10
-
11
- module AsposeEmailCloud
12
- class ApiClient
13
-
14
- include AsposeStorageCloud
15
-
16
- attr_accessor :host
17
-
18
- # Defines the headers to be used in HTTP requests of all API calls by default.
19
- #
20
- # @return [Hash]
21
- attr_accessor :default_headers
22
-
23
- # Stores the HTTP response from the last API call using this API client.
24
- attr_accessor :last_response
25
-
26
- def initialize(host = nil)
27
- @host = host || Configuration.base_url
28
- @format = 'json'
29
- @user_agent = "ruby-swagger-#{VERSION}"
30
- @default_headers = {
31
- 'Content-Type' => "application/#{@format.downcase}",
32
- 'User-Agent' => @user_agent
33
- }
34
- end
35
-
36
- def call_api(http_method, path, opts = {})
37
- request = build_request(http_method, path, opts)
38
- response = request.run
39
-
40
- # record as last response
41
- @last_response = response
42
-
43
- if Configuration.debugging
44
- Configuration.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
45
- end
46
-
47
- unless response.success?
48
- fail ApiError.new(:code => response.code,
49
- :response_headers => response.headers,
50
- :response_body => response.body),
51
- response.status_message
52
- end
53
-
54
- if opts[:return_type]
55
- deserialize(response, opts[:return_type])
56
- else
57
- nil
58
- end
59
- end
60
-
61
- def build_request(http_method, path, opts = {})
62
- url = build_request_url(path)
63
- http_method = http_method.to_sym.downcase
64
-
65
- header_params = @default_headers.merge(opts[:header_params] || {})
66
- query_params = {}
67
- form_params = opts[:form_params] || {}
68
-
69
- req_opts = {
70
- :method => http_method,
71
- :headers => header_params,
72
- :params => query_params,
73
- :ssl_verifypeer => Configuration.verify_ssl,
74
- :sslcert => Configuration.cert_file,
75
- :sslkey => Configuration.key_file,
76
- :cainfo => Configuration.ssl_ca_cert,
77
- :verbose => Configuration.debugging
78
- }
79
-
80
- if [:post, :patch, :put, :delete].include?(http_method)
81
- req_body = build_request_body(header_params, form_params, opts[:body])
82
- req_opts.update :body => req_body
83
- if Configuration.debugging
84
- Configuration.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
85
- end
86
- end
87
-
88
- url = sign(url, opts[:query_params])
89
- Typhoeus::Request.new(url, req_opts)
90
-
91
- end
92
-
93
- # Signs a URI with your appSID and Key.
94
- # * :url describes the URL to sign
95
-
96
- def sign(url, query_params)
97
-
98
- fail "Please set Aspose App key and SID first. You can get App key and App SID from https://cloud.aspose.com" if AsposeApp.app_key.nil? || AsposeApp.app_sid.nil?
99
-
100
- url = url[0..-2] if url[-1].eql? '/'
101
-
102
- unless query_params.empty?
103
- url = "#{url}?"
104
- query_params.each { |key, value|
105
- url = "#{url}#{key}=#{value}&"
106
- }
107
- url = url[0..-2]
108
- end
109
-
110
- url = URI.escape(url)
111
- parsed_url = URI.parse(url)
112
-
113
- url_to_sign = "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.path}"
114
- url_to_sign += "?#{parsed_url.query}" if parsed_url.query
115
- if parsed_url.query
116
- url_to_sign += "&appSID=#{AsposeApp.app_sid}"
117
- else
118
- url_to_sign += "?appSID=#{AsposeApp.app_sid}"
119
- end
120
-
121
- # create a signature using the private key and the URL
122
- raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), AsposeApp.app_key, url_to_sign)
123
-
124
- #Convert raw to encoded string
125
- signature = Base64.strict_encode64(raw_signature).tr('+/', '-_')
126
-
127
- #remove invalid character
128
- signature = signature.gsub(/[=_-]/, '=' => '', '_' => '%2f', '-' => '%2b')
129
-
130
- #Define expression
131
- pat = Regexp.new('%[0-9a-f]{2}')
132
-
133
- #Replace the portion matched to the above pattern to upper case
134
- 6.times do
135
- signature = signature.sub(pat, pat.match(signature).to_s.upcase)
136
- end
137
-
138
- # prepend the server and append the signature.
139
- url_to_sign + "&signature=#{signature}"
140
-
141
- end
142
-
143
- # Deserialize the response to the given return type.
144
- #
145
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
146
- def deserialize(response, return_type)
147
- body = response.body
148
- return nil if body.nil? || body.empty?
149
-
150
- # handle file downloading - save response body into a tmp file and return the File instance
151
- return download_file(response) if return_type == 'File'
152
-
153
- # ensuring a default content type
154
- content_type = response.headers['Content-Type'] || 'application/json'
155
-
156
- unless content_type.start_with?('application/json')
157
- fail "Content-Type is not supported: #{content_type}"
158
- end
159
-
160
- begin
161
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
162
- rescue JSON::ParserError => e
163
- if %w(String Date DateTime).include?(return_type)
164
- data = body
165
- else
166
- raise e
167
- end
168
- end
169
-
170
- convert_to_type data, return_type
171
- end
172
-
173
- # Convert data to the given return type.
174
- def convert_to_type(data, return_type)
175
- return nil if data.nil?
176
- case return_type
177
- when 'String'
178
- data.to_s
179
- when 'Integer'
180
- data.to_i
181
- when 'Float'
182
- data.to_f
183
- when 'BOOLEAN'
184
- data == true
185
- when 'DateTime'
186
- # parse date time (expecting ISO 8601 format)
187
- DateTime.parse data
188
- when 'Date'
189
- # parse date time (expecting ISO 8601 format)
190
- Date.parse data
191
- when 'Object'
192
- # generic object, return directly
193
- data
194
- when /\AArray<(.+)>\z/
195
- # e.g. Array<Pet>
196
- sub_type = $1
197
- data.map {|item| convert_to_type(item, sub_type) }
198
- when /\AHash\<String, (.+)\>\z/
199
- # e.g. Hash<String, Integer>
200
- sub_type = $1
201
- {}.tap do |hash|
202
- data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
203
- end
204
- else
205
- # models, e.g. Pet
206
- AsposeEmailCloud.const_get(return_type).new.tap do |model|
207
- model.build_from_hash data
208
- end
209
- end
210
- end
211
-
212
- # Save response body into a file in (the defined) temporary folder, using the filename
213
- # from the "Content-Disposition" header if provided, otherwise a random filename.
214
- #
215
- # @see Configuration#temp_folder_path
216
- # @return [File] the file downloaded
217
- def download_file(response)
218
- tmp_file = Tempfile.new '', Configuration.temp_folder_path
219
- content_disposition = response.headers['Content-Disposition']
220
-
221
- if content_disposition
222
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
223
- path = File.join File.dirname(tmp_file), filename
224
- else
225
- path = tmp_file.path
226
- end
227
- # close and delete temp file
228
- tmp_file.close!
229
-
230
- File.open(path, 'wb') { |file| file.write(response.body) }
231
- Configuration.logger.info "File written to #{path}. Please move the file to a proper "\
232
- "folder for further processing and delete the temp afterwards"
233
- File.new(path)
234
- end
235
-
236
- def build_request_url(path)
237
- # Add leading and trailing slashes to path
238
- path = "/#{path}".gsub(/\/+/, '/')
239
- URI.encode(host + path)
240
- end
241
-
242
- def build_request_body(header_params, form_params, body)
243
- # http form
244
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
245
- header_params['Content-Type'] == 'multipart/form-data'
246
-
247
- data = form_params.dup
248
- data.each do |key, value|
249
- if key.eql? "file"
250
- data = value
251
- break
252
- else
253
- data[key] = value.to_s if value && !value.is_a?(File)
254
- end
255
- end
256
- elsif body
257
- data = body.is_a?(String) ? body : body.to_json
258
- else
259
- data = nil
260
- end
261
- data
262
- end
263
-
264
- # Update hearder and query params based on authentication settings.
265
- def update_params_for_auth!(header_params, query_params, auth_names)
266
- Array(auth_names).each do |auth_name|
267
- auth_setting = Configuration.auth_settings[auth_name]
268
- next unless auth_setting
269
- case auth_setting[:in]
270
- when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
271
- when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
272
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
273
- end
274
- end
275
- end
276
-
277
- def user_agent=(user_agent)
278
- @user_agent = user_agent
279
- @default_headers['User-Agent'] = @user_agent
280
- end
281
-
282
- # Return Accept header based on an array of accepts provided.
283
- # @param [Array] accepts array for Accept
284
- # @return [String] the Accept header (e.g. application/json)
285
- def select_header_accept(accepts)
286
- if accepts.empty?
287
- return
288
- elsif accepts.any?{ |s| s.casecmp('application/json') == 0 }
289
- 'application/json' # look for json data by default
290
- else
291
- accepts.join(',')
292
- end
293
- end
294
-
295
- # Return Content-Type header based on an array of content types provided.
296
- # @param [Array] content_types array for Content-Type
297
- # @return [String] the Content-Type header (e.g. application/json)
298
- def select_header_content_type(content_types)
299
- if content_types.empty?
300
- 'application/json' # use application/json by default
301
- elsif content_types.any?{ |s| s.casecmp('application/json')==0 }
302
- 'application/json' # use application/json if it's included
303
- else
304
- content_types[0] # otherwise, use the first one
305
- end
306
- end
307
-
308
- # Convert object (array, hash, object, etc) to JSON string.
309
- # @param [Object] model object to be converted into JSON string
310
- # @return [String] JSON string representation of the object
311
- def object_to_http_body(model)
312
- return if model.nil?
313
- _body = nil
314
- if model.is_a?(Array)
315
- _body = model.map{|m| object_to_hash(m) }
316
- else
317
- _body = object_to_hash(model)
318
- end
319
- _body.to_json
320
- end
321
-
322
- # Convert object(non-array) to hash.
323
- # @param [Object] obj object to be converted into JSON string
324
- # @return [String] JSON string representation of the object
325
- def object_to_hash(obj)
326
- if obj.respond_to?(:to_hash)
327
- obj.to_hash
328
- else
329
- obj
330
- end
331
- end
332
-
333
-
334
- end
335
- end
@@ -1,24 +0,0 @@
1
- module AsposeEmailCloud
2
- class ApiError < StandardError
3
- attr_reader :code, :response_headers, :response_body
4
-
5
- # Usage examples:
6
- # ApiError.new
7
- # ApiError.new("message")
8
- # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
9
- # ApiError.new(:code => 404, :message => "Not Found")
10
- def initialize(arg = nil)
11
- if arg.is_a? Hash
12
- arg.each do |k, v|
13
- if k.to_s == 'message'
14
- super v
15
- else
16
- instance_variable_set "@#{k}", v
17
- end
18
- end
19
- else
20
- super arg
21
- end
22
- end
23
- end
24
- end
@@ -1,88 +0,0 @@
1
- require 'date'
2
-
3
- module AsposeEmailCloud
4
- # base class containing fundamental method such as to_hash, build_from_hash and more
5
- class BaseObject
6
-
7
- # build the object from hash
8
- def build_from_hash(attributes)
9
- return nil unless attributes.is_a?(Hash)
10
- self.class.swagger_types.each_pair do |key, type|
11
- if type =~ /^Array<(.*)>/i
12
- if attributes[self.class.attribute_map[key]].is_a?(Array)
13
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
14
- else
15
- #TODO show warning in debug mode
16
- end
17
- elsif !attributes[self.class.attribute_map[key]].nil?
18
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
19
- else
20
- # data not found in attributes(hash), not an issue as the data can be optional
21
- end
22
- end
23
-
24
- self
25
- end
26
-
27
- def _deserialize(type, value)
28
- case type.to_sym
29
- when :DateTime
30
- DateTime.parse(value)
31
- when :Date
32
- Date.parse(value)
33
- when :String
34
- value.to_s
35
- when :Integer
36
- value.to_i
37
- when :Float
38
- value.to_f
39
- when :BOOLEAN
40
- if value =~ /^(true|t|yes|y|1)$/i
41
- true
42
- else
43
- false
44
- end
45
- when :Object
46
- value
47
- else # model
48
- _model = AsposeEmailCloud.const_get(type).new
49
- _model.build_from_hash(value)
50
- end
51
- end
52
-
53
- def to_s
54
- to_hash.to_s
55
- end
56
-
57
- # to_body is an alias to to_body (backward compatibility))
58
- def to_body
59
- to_hash
60
- end
61
-
62
- # return the object in the form of hash
63
- def to_hash
64
- hash = {}
65
- self.class.attribute_map.each_pair do |attr, param|
66
- value = self.send(attr)
67
- next if value.nil?
68
- if value.is_a?(Array)
69
- hash[param] = value.compact.map{ |v| _to_hash(v) }
70
- else
71
- hash[param] = _to_hash(value)
72
- end
73
- end
74
- hash
75
- end
76
-
77
- # Method to output non-array value in the form of hash
78
- # For object, use to_hash. Otherwise, just return the value
79
- def _to_hash(value)
80
- if value.respond_to? :to_hash
81
- value.to_hash
82
- else
83
- value
84
- end
85
- end
86
-
87
- end
88
- end
@@ -1,63 +0,0 @@
1
- module AsposeEmailCloud
2
- #
3
- class EmailDocument < BaseObject
4
- attr_accessor :links, :document_properties, :data, :format
5
- # attribute mapping from ruby-style variable name to JSON key
6
- def self.attribute_map
7
- {
8
-
9
- #
10
- :'links' => :'Links',
11
-
12
- #
13
- :'document_properties' => :'DocumentProperties',
14
-
15
- #
16
- :'data' => :'Data',
17
-
18
- #
19
- :'format' => :'Format'
20
-
21
- }
22
- end
23
-
24
- # attribute type
25
- def self.swagger_types
26
- {
27
- :'links' => :'Array<Link>',
28
- :'document_properties' => :'EmailProperties',
29
- :'data' => :'Stream',
30
- :'format' => :'String'
31
-
32
- }
33
- end
34
-
35
- def initialize(attributes = {})
36
- return if !attributes.is_a?(Hash) || attributes.empty?
37
-
38
- # convert string to symbol for hash key
39
- attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
40
-
41
-
42
- if attributes[:'Links']
43
- if (value = attributes[:'Links']).is_a?(Array)
44
- self.links = value
45
- end
46
- end
47
-
48
- if attributes[:'DocumentProperties']
49
- self.document_properties = attributes[:'DocumentProperties']
50
- end
51
-
52
- if attributes[:'Data']
53
- self.data = attributes[:'Data']
54
- end
55
-
56
- if attributes[:'Format']
57
- self.format = attributes[:'Format']
58
- end
59
-
60
- end
61
-
62
- end
63
- end