sendpost_ruby_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +79 -0
  4. data/Rakefile +10 -0
  5. data/config-ruby.json +11 -0
  6. data/docs/Attachment.md +20 -0
  7. data/docs/City.md +26 -0
  8. data/docs/CopyTo.md +22 -0
  9. data/docs/Device.md +18 -0
  10. data/docs/EmailApi.md +145 -0
  11. data/docs/EmailMessage.md +46 -0
  12. data/docs/EmailResponse.md +26 -0
  13. data/docs/EventMetadata.md +30 -0
  14. data/docs/From.md +20 -0
  15. data/docs/Os.md +26 -0
  16. data/docs/QEmailMessage.md +70 -0
  17. data/docs/QEvent.md +42 -0
  18. data/docs/ReplyTo.md +20 -0
  19. data/docs/To.md +26 -0
  20. data/docs/UserAgent.md +24 -0
  21. data/docs/WebhookEvent.md +20 -0
  22. data/generate-libs.bash +1 -0
  23. data/git_push.sh +57 -0
  24. data/lib/sendpost_ruby_sdk/api/email_api.rb +160 -0
  25. data/lib/sendpost_ruby_sdk/api_client.rb +391 -0
  26. data/lib/sendpost_ruby_sdk/api_error.rb +58 -0
  27. data/lib/sendpost_ruby_sdk/configuration.rb +288 -0
  28. data/lib/sendpost_ruby_sdk/models/attachment.rb +228 -0
  29. data/lib/sendpost_ruby_sdk/models/city.rb +255 -0
  30. data/lib/sendpost_ruby_sdk/models/copy_to.rb +237 -0
  31. data/lib/sendpost_ruby_sdk/models/device.rb +219 -0
  32. data/lib/sendpost_ruby_sdk/models/email_message.rb +351 -0
  33. data/lib/sendpost_ruby_sdk/models/email_response.rb +255 -0
  34. data/lib/sendpost_ruby_sdk/models/event_metadata.rb +273 -0
  35. data/lib/sendpost_ruby_sdk/models/from.rb +228 -0
  36. data/lib/sendpost_ruby_sdk/models/os.rb +255 -0
  37. data/lib/sendpost_ruby_sdk/models/q_email_message.rb +461 -0
  38. data/lib/sendpost_ruby_sdk/models/q_event.rb +329 -0
  39. data/lib/sendpost_ruby_sdk/models/reply_to.rb +228 -0
  40. data/lib/sendpost_ruby_sdk/models/to.rb +259 -0
  41. data/lib/sendpost_ruby_sdk/models/user_agent.rb +246 -0
  42. data/lib/sendpost_ruby_sdk/models/webhook_event.rb +228 -0
  43. data/lib/sendpost_ruby_sdk/version.rb +15 -0
  44. data/lib/sendpost_ruby_sdk.rb +55 -0
  45. data/sendpost.yaml +438 -0
  46. data/sendpost_ruby_sdk.gemspec +38 -0
  47. data/spec/api/email_api_spec.rb +59 -0
  48. data/spec/api_client_spec.rb +228 -0
  49. data/spec/configuration_spec.rb +42 -0
  50. data/spec/models/attachment_spec.rb +40 -0
  51. data/spec/models/city_spec.rb +58 -0
  52. data/spec/models/copy_to_spec.rb +46 -0
  53. data/spec/models/device_spec.rb +34 -0
  54. data/spec/models/email_message_spec.rb +118 -0
  55. data/spec/models/email_response_spec.rb +58 -0
  56. data/spec/models/event_metadata_spec.rb +70 -0
  57. data/spec/models/from_spec.rb +40 -0
  58. data/spec/models/os_spec.rb +58 -0
  59. data/spec/models/q_email_message_spec.rb +190 -0
  60. data/spec/models/q_event_spec.rb +106 -0
  61. data/spec/models/reply_to_spec.rb +40 -0
  62. data/spec/models/to_spec.rb +58 -0
  63. data/spec/models/user_agent_spec.rb +52 -0
  64. data/spec/models/webhook_event_spec.rb +40 -0
  65. data/spec/spec_helper.rb +111 -0
  66. metadata +168 -0
@@ -0,0 +1,255 @@
1
+ =begin
2
+ #SendPost API
3
+
4
+ #Email API and SMTP relay to not just send and measure email sending, but also alert and optimise. We provide you with tools, expertise and support needed to reliably deliver emails to your customers inboxes on time, every time.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: hello@sendpost.io
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.6.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Sendpost
17
+ class Os
18
+ attr_accessor :family
19
+
20
+ attr_accessor :major
21
+
22
+ attr_accessor :minor
23
+
24
+ attr_accessor :patch
25
+
26
+ attr_accessor :patch_minor
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'family' => :'Family',
32
+ :'major' => :'Major',
33
+ :'minor' => :'Minor',
34
+ :'patch' => :'Patch',
35
+ :'patch_minor' => :'PatchMinor'
36
+ }
37
+ end
38
+
39
+ # Returns all the JSON keys this model knows about
40
+ def self.acceptable_attributes
41
+ attribute_map.values
42
+ end
43
+
44
+ # Attribute type mapping.
45
+ def self.openapi_types
46
+ {
47
+ :'family' => :'String',
48
+ :'major' => :'String',
49
+ :'minor' => :'String',
50
+ :'patch' => :'String',
51
+ :'patch_minor' => :'String'
52
+ }
53
+ end
54
+
55
+ # List of attributes with nullable: true
56
+ def self.openapi_nullable
57
+ Set.new([
58
+ ])
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ if (!attributes.is_a?(Hash))
65
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Sendpost::Os` initialize method"
66
+ end
67
+
68
+ # check to see if the attribute exists and convert string to symbol for hash key
69
+ attributes = attributes.each_with_object({}) { |(k, v), h|
70
+ if (!self.class.attribute_map.key?(k.to_sym))
71
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Sendpost::Os`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
72
+ end
73
+ h[k.to_sym] = v
74
+ }
75
+
76
+ if attributes.key?(:'family')
77
+ self.family = attributes[:'family']
78
+ end
79
+
80
+ if attributes.key?(:'major')
81
+ self.major = attributes[:'major']
82
+ end
83
+
84
+ if attributes.key?(:'minor')
85
+ self.minor = attributes[:'minor']
86
+ end
87
+
88
+ if attributes.key?(:'patch')
89
+ self.patch = attributes[:'patch']
90
+ end
91
+
92
+ if attributes.key?(:'patch_minor')
93
+ self.patch_minor = attributes[:'patch_minor']
94
+ end
95
+ end
96
+
97
+ # Show invalid properties with the reasons. Usually used together with valid?
98
+ # @return Array for valid properties with the reasons
99
+ def list_invalid_properties
100
+ invalid_properties = Array.new
101
+ invalid_properties
102
+ end
103
+
104
+ # Check to see if the all the properties in the model are valid
105
+ # @return true if the model is valid
106
+ def valid?
107
+ true
108
+ end
109
+
110
+ # Checks equality by comparing each attribute.
111
+ # @param [Object] Object to be compared
112
+ def ==(o)
113
+ return true if self.equal?(o)
114
+ self.class == o.class &&
115
+ family == o.family &&
116
+ major == o.major &&
117
+ minor == o.minor &&
118
+ patch == o.patch &&
119
+ patch_minor == o.patch_minor
120
+ end
121
+
122
+ # @see the `==` method
123
+ # @param [Object] Object to be compared
124
+ def eql?(o)
125
+ self == o
126
+ end
127
+
128
+ # Calculates hash code according to all attributes.
129
+ # @return [Integer] Hash code
130
+ def hash
131
+ [family, major, minor, patch, patch_minor].hash
132
+ end
133
+
134
+ # Builds the object from hash
135
+ # @param [Hash] attributes Model attributes in the form of hash
136
+ # @return [Object] Returns the model itself
137
+ def self.build_from_hash(attributes)
138
+ new.build_from_hash(attributes)
139
+ end
140
+
141
+ # Builds the object from hash
142
+ # @param [Hash] attributes Model attributes in the form of hash
143
+ # @return [Object] Returns the model itself
144
+ def build_from_hash(attributes)
145
+ return nil unless attributes.is_a?(Hash)
146
+ attributes = attributes.transform_keys(&:to_sym)
147
+ self.class.openapi_types.each_pair do |key, type|
148
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
149
+ self.send("#{key}=", nil)
150
+ elsif type =~ /\AArray<(.*)>/i
151
+ # check to ensure the input is an array given that the attribute
152
+ # is documented as an array but the input is not
153
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
154
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
155
+ end
156
+ elsif !attributes[self.class.attribute_map[key]].nil?
157
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
158
+ end
159
+ end
160
+
161
+ self
162
+ end
163
+
164
+ # Deserializes the data based on type
165
+ # @param string type Data type
166
+ # @param string value Value to be deserialized
167
+ # @return [Object] Deserialized data
168
+ def _deserialize(type, value)
169
+ case type.to_sym
170
+ when :Time
171
+ Time.parse(value)
172
+ when :Date
173
+ Date.parse(value)
174
+ when :String
175
+ value.to_s
176
+ when :Integer
177
+ value.to_i
178
+ when :Float
179
+ value.to_f
180
+ when :Boolean
181
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
182
+ true
183
+ else
184
+ false
185
+ end
186
+ when :Object
187
+ # generic object (usually a Hash), return directly
188
+ value
189
+ when /\AArray<(?<inner_type>.+)>\z/
190
+ inner_type = Regexp.last_match[:inner_type]
191
+ value.map { |v| _deserialize(inner_type, v) }
192
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
193
+ k_type = Regexp.last_match[:k_type]
194
+ v_type = Regexp.last_match[:v_type]
195
+ {}.tap do |hash|
196
+ value.each do |k, v|
197
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
198
+ end
199
+ end
200
+ else # model
201
+ # models (e.g. Pet) or oneOf
202
+ klass = Sendpost.const_get(type)
203
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
204
+ end
205
+ end
206
+
207
+ # Returns the string representation of the object
208
+ # @return [String] String presentation of the object
209
+ def to_s
210
+ to_hash.to_s
211
+ end
212
+
213
+ # to_body is an alias to to_hash (backward compatibility)
214
+ # @return [Hash] Returns the object in the form of hash
215
+ def to_body
216
+ to_hash
217
+ end
218
+
219
+ # Returns the object in the form of hash
220
+ # @return [Hash] Returns the object in the form of hash
221
+ def to_hash
222
+ hash = {}
223
+ self.class.attribute_map.each_pair do |attr, param|
224
+ value = self.send(attr)
225
+ if value.nil?
226
+ is_nullable = self.class.openapi_nullable.include?(attr)
227
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
228
+ end
229
+
230
+ hash[param] = _to_hash(value)
231
+ end
232
+ hash
233
+ end
234
+
235
+ # Outputs non-array value in the form of hash
236
+ # For object, use to_hash. Otherwise, just return the value
237
+ # @param [Object] value Any valid value
238
+ # @return [Hash] Returns the value in the form of hash
239
+ def _to_hash(value)
240
+ if value.is_a?(Array)
241
+ value.compact.map { |v| _to_hash(v) }
242
+ elsif value.is_a?(Hash)
243
+ {}.tap do |hash|
244
+ value.each { |k, v| hash[k] = _to_hash(v) }
245
+ end
246
+ elsif value.respond_to? :to_hash
247
+ value.to_hash
248
+ else
249
+ value
250
+ end
251
+ end
252
+
253
+ end
254
+
255
+ end
@@ -0,0 +1,461 @@
1
+ =begin
2
+ #SendPost API
3
+
4
+ #Email API and SMTP relay to not just send and measure email sending, but also alert and optimise. We provide you with tools, expertise and support needed to reliably deliver emails to your customers inboxes on time, every time.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: hello@sendpost.io
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.6.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Sendpost
17
+ class QEmailMessage
18
+ attr_accessor :account_id
19
+
20
+ attr_accessor :amp_body
21
+
22
+ attr_accessor :attachments
23
+
24
+ attr_accessor :attempt
25
+
26
+ attr_accessor :custom_fields
27
+
28
+ attr_accessor :email_type
29
+
30
+ attr_accessor :from
31
+
32
+ attr_accessor :groups
33
+
34
+ attr_accessor :header_bcc
35
+
36
+ attr_accessor :header_cc
37
+
38
+ attr_accessor :header_to
39
+
40
+ attr_accessor :headers
41
+
42
+ attr_accessor :html_body
43
+
44
+ attr_accessor :ip_id
45
+
46
+ attr_accessor :ip_pool
47
+
48
+ attr_accessor :local_ip
49
+
50
+ attr_accessor :message_id
51
+
52
+ attr_accessor :pre_text
53
+
54
+ attr_accessor :public_ip
55
+
56
+ attr_accessor :reply_to
57
+
58
+ attr_accessor :sub_account_id
59
+
60
+ attr_accessor :subject
61
+
62
+ attr_accessor :submitted_at
63
+
64
+ attr_accessor :text_body
65
+
66
+ attr_accessor :to
67
+
68
+ attr_accessor :track_clicks
69
+
70
+ attr_accessor :track_opens
71
+
72
+ # Attribute mapping from ruby-style variable name to JSON key.
73
+ def self.attribute_map
74
+ {
75
+ :'account_id' => :'accountID',
76
+ :'amp_body' => :'ampBody',
77
+ :'attachments' => :'attachments',
78
+ :'attempt' => :'attempt',
79
+ :'custom_fields' => :'customFields',
80
+ :'email_type' => :'emailType',
81
+ :'from' => :'from',
82
+ :'groups' => :'groups',
83
+ :'header_bcc' => :'headerBcc',
84
+ :'header_cc' => :'headerCc',
85
+ :'header_to' => :'headerTo',
86
+ :'headers' => :'headers',
87
+ :'html_body' => :'htmlBody',
88
+ :'ip_id' => :'ipID',
89
+ :'ip_pool' => :'ipPool',
90
+ :'local_ip' => :'localIP',
91
+ :'message_id' => :'messageID',
92
+ :'pre_text' => :'preText',
93
+ :'public_ip' => :'publicIP',
94
+ :'reply_to' => :'replyTo',
95
+ :'sub_account_id' => :'subAccountID',
96
+ :'subject' => :'subject',
97
+ :'submitted_at' => :'submittedAt',
98
+ :'text_body' => :'textBody',
99
+ :'to' => :'to',
100
+ :'track_clicks' => :'trackClicks',
101
+ :'track_opens' => :'trackOpens'
102
+ }
103
+ end
104
+
105
+ # Returns all the JSON keys this model knows about
106
+ def self.acceptable_attributes
107
+ attribute_map.values
108
+ end
109
+
110
+ # Attribute type mapping.
111
+ def self.openapi_types
112
+ {
113
+ :'account_id' => :'Integer',
114
+ :'amp_body' => :'String',
115
+ :'attachments' => :'Array<Attachment>',
116
+ :'attempt' => :'Integer',
117
+ :'custom_fields' => :'Object',
118
+ :'email_type' => :'String',
119
+ :'from' => :'From',
120
+ :'groups' => :'Array<String>',
121
+ :'header_bcc' => :'Array<CopyTo>',
122
+ :'header_cc' => :'Array<CopyTo>',
123
+ :'header_to' => :'To',
124
+ :'headers' => :'Object',
125
+ :'html_body' => :'String',
126
+ :'ip_id' => :'Integer',
127
+ :'ip_pool' => :'String',
128
+ :'local_ip' => :'String',
129
+ :'message_id' => :'String',
130
+ :'pre_text' => :'String',
131
+ :'public_ip' => :'String',
132
+ :'reply_to' => :'ReplyTo',
133
+ :'sub_account_id' => :'Integer',
134
+ :'subject' => :'String',
135
+ :'submitted_at' => :'Integer',
136
+ :'text_body' => :'String',
137
+ :'to' => :'To',
138
+ :'track_clicks' => :'Boolean',
139
+ :'track_opens' => :'Boolean'
140
+ }
141
+ end
142
+
143
+ # List of attributes with nullable: true
144
+ def self.openapi_nullable
145
+ Set.new([
146
+ ])
147
+ end
148
+
149
+ # Initializes the object
150
+ # @param [Hash] attributes Model attributes in the form of hash
151
+ def initialize(attributes = {})
152
+ if (!attributes.is_a?(Hash))
153
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Sendpost::QEmailMessage` initialize method"
154
+ end
155
+
156
+ # check to see if the attribute exists and convert string to symbol for hash key
157
+ attributes = attributes.each_with_object({}) { |(k, v), h|
158
+ if (!self.class.attribute_map.key?(k.to_sym))
159
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Sendpost::QEmailMessage`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
160
+ end
161
+ h[k.to_sym] = v
162
+ }
163
+
164
+ if attributes.key?(:'account_id')
165
+ self.account_id = attributes[:'account_id']
166
+ end
167
+
168
+ if attributes.key?(:'amp_body')
169
+ self.amp_body = attributes[:'amp_body']
170
+ end
171
+
172
+ if attributes.key?(:'attachments')
173
+ if (value = attributes[:'attachments']).is_a?(Array)
174
+ self.attachments = value
175
+ end
176
+ end
177
+
178
+ if attributes.key?(:'attempt')
179
+ self.attempt = attributes[:'attempt']
180
+ end
181
+
182
+ if attributes.key?(:'custom_fields')
183
+ self.custom_fields = attributes[:'custom_fields']
184
+ end
185
+
186
+ if attributes.key?(:'email_type')
187
+ self.email_type = attributes[:'email_type']
188
+ end
189
+
190
+ if attributes.key?(:'from')
191
+ self.from = attributes[:'from']
192
+ end
193
+
194
+ if attributes.key?(:'groups')
195
+ if (value = attributes[:'groups']).is_a?(Array)
196
+ self.groups = value
197
+ end
198
+ end
199
+
200
+ if attributes.key?(:'header_bcc')
201
+ if (value = attributes[:'header_bcc']).is_a?(Array)
202
+ self.header_bcc = value
203
+ end
204
+ end
205
+
206
+ if attributes.key?(:'header_cc')
207
+ if (value = attributes[:'header_cc']).is_a?(Array)
208
+ self.header_cc = value
209
+ end
210
+ end
211
+
212
+ if attributes.key?(:'header_to')
213
+ self.header_to = attributes[:'header_to']
214
+ end
215
+
216
+ if attributes.key?(:'headers')
217
+ self.headers = attributes[:'headers']
218
+ end
219
+
220
+ if attributes.key?(:'html_body')
221
+ self.html_body = attributes[:'html_body']
222
+ end
223
+
224
+ if attributes.key?(:'ip_id')
225
+ self.ip_id = attributes[:'ip_id']
226
+ end
227
+
228
+ if attributes.key?(:'ip_pool')
229
+ self.ip_pool = attributes[:'ip_pool']
230
+ end
231
+
232
+ if attributes.key?(:'local_ip')
233
+ self.local_ip = attributes[:'local_ip']
234
+ end
235
+
236
+ if attributes.key?(:'message_id')
237
+ self.message_id = attributes[:'message_id']
238
+ end
239
+
240
+ if attributes.key?(:'pre_text')
241
+ self.pre_text = attributes[:'pre_text']
242
+ end
243
+
244
+ if attributes.key?(:'public_ip')
245
+ self.public_ip = attributes[:'public_ip']
246
+ end
247
+
248
+ if attributes.key?(:'reply_to')
249
+ self.reply_to = attributes[:'reply_to']
250
+ end
251
+
252
+ if attributes.key?(:'sub_account_id')
253
+ self.sub_account_id = attributes[:'sub_account_id']
254
+ end
255
+
256
+ if attributes.key?(:'subject')
257
+ self.subject = attributes[:'subject']
258
+ end
259
+
260
+ if attributes.key?(:'submitted_at')
261
+ self.submitted_at = attributes[:'submitted_at']
262
+ end
263
+
264
+ if attributes.key?(:'text_body')
265
+ self.text_body = attributes[:'text_body']
266
+ end
267
+
268
+ if attributes.key?(:'to')
269
+ self.to = attributes[:'to']
270
+ end
271
+
272
+ if attributes.key?(:'track_clicks')
273
+ self.track_clicks = attributes[:'track_clicks']
274
+ end
275
+
276
+ if attributes.key?(:'track_opens')
277
+ self.track_opens = attributes[:'track_opens']
278
+ end
279
+ end
280
+
281
+ # Show invalid properties with the reasons. Usually used together with valid?
282
+ # @return Array for valid properties with the reasons
283
+ def list_invalid_properties
284
+ invalid_properties = Array.new
285
+ invalid_properties
286
+ end
287
+
288
+ # Check to see if the all the properties in the model are valid
289
+ # @return true if the model is valid
290
+ def valid?
291
+ true
292
+ end
293
+
294
+ # Checks equality by comparing each attribute.
295
+ # @param [Object] Object to be compared
296
+ def ==(o)
297
+ return true if self.equal?(o)
298
+ self.class == o.class &&
299
+ account_id == o.account_id &&
300
+ amp_body == o.amp_body &&
301
+ attachments == o.attachments &&
302
+ attempt == o.attempt &&
303
+ custom_fields == o.custom_fields &&
304
+ email_type == o.email_type &&
305
+ from == o.from &&
306
+ groups == o.groups &&
307
+ header_bcc == o.header_bcc &&
308
+ header_cc == o.header_cc &&
309
+ header_to == o.header_to &&
310
+ headers == o.headers &&
311
+ html_body == o.html_body &&
312
+ ip_id == o.ip_id &&
313
+ ip_pool == o.ip_pool &&
314
+ local_ip == o.local_ip &&
315
+ message_id == o.message_id &&
316
+ pre_text == o.pre_text &&
317
+ public_ip == o.public_ip &&
318
+ reply_to == o.reply_to &&
319
+ sub_account_id == o.sub_account_id &&
320
+ subject == o.subject &&
321
+ submitted_at == o.submitted_at &&
322
+ text_body == o.text_body &&
323
+ to == o.to &&
324
+ track_clicks == o.track_clicks &&
325
+ track_opens == o.track_opens
326
+ end
327
+
328
+ # @see the `==` method
329
+ # @param [Object] Object to be compared
330
+ def eql?(o)
331
+ self == o
332
+ end
333
+
334
+ # Calculates hash code according to all attributes.
335
+ # @return [Integer] Hash code
336
+ def hash
337
+ [account_id, amp_body, attachments, attempt, custom_fields, email_type, from, groups, header_bcc, header_cc, header_to, headers, html_body, ip_id, ip_pool, local_ip, message_id, pre_text, public_ip, reply_to, sub_account_id, subject, submitted_at, text_body, to, track_clicks, track_opens].hash
338
+ end
339
+
340
+ # Builds the object from hash
341
+ # @param [Hash] attributes Model attributes in the form of hash
342
+ # @return [Object] Returns the model itself
343
+ def self.build_from_hash(attributes)
344
+ new.build_from_hash(attributes)
345
+ end
346
+
347
+ # Builds the object from hash
348
+ # @param [Hash] attributes Model attributes in the form of hash
349
+ # @return [Object] Returns the model itself
350
+ def build_from_hash(attributes)
351
+ return nil unless attributes.is_a?(Hash)
352
+ attributes = attributes.transform_keys(&:to_sym)
353
+ self.class.openapi_types.each_pair do |key, type|
354
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
355
+ self.send("#{key}=", nil)
356
+ elsif type =~ /\AArray<(.*)>/i
357
+ # check to ensure the input is an array given that the attribute
358
+ # is documented as an array but the input is not
359
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
360
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
361
+ end
362
+ elsif !attributes[self.class.attribute_map[key]].nil?
363
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
364
+ end
365
+ end
366
+
367
+ self
368
+ end
369
+
370
+ # Deserializes the data based on type
371
+ # @param string type Data type
372
+ # @param string value Value to be deserialized
373
+ # @return [Object] Deserialized data
374
+ def _deserialize(type, value)
375
+ case type.to_sym
376
+ when :Time
377
+ Time.parse(value)
378
+ when :Date
379
+ Date.parse(value)
380
+ when :String
381
+ value.to_s
382
+ when :Integer
383
+ value.to_i
384
+ when :Float
385
+ value.to_f
386
+ when :Boolean
387
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
388
+ true
389
+ else
390
+ false
391
+ end
392
+ when :Object
393
+ # generic object (usually a Hash), return directly
394
+ value
395
+ when /\AArray<(?<inner_type>.+)>\z/
396
+ inner_type = Regexp.last_match[:inner_type]
397
+ value.map { |v| _deserialize(inner_type, v) }
398
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
399
+ k_type = Regexp.last_match[:k_type]
400
+ v_type = Regexp.last_match[:v_type]
401
+ {}.tap do |hash|
402
+ value.each do |k, v|
403
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
404
+ end
405
+ end
406
+ else # model
407
+ # models (e.g. Pet) or oneOf
408
+ klass = Sendpost.const_get(type)
409
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
410
+ end
411
+ end
412
+
413
+ # Returns the string representation of the object
414
+ # @return [String] String presentation of the object
415
+ def to_s
416
+ to_hash.to_s
417
+ end
418
+
419
+ # to_body is an alias to to_hash (backward compatibility)
420
+ # @return [Hash] Returns the object in the form of hash
421
+ def to_body
422
+ to_hash
423
+ end
424
+
425
+ # Returns the object in the form of hash
426
+ # @return [Hash] Returns the object in the form of hash
427
+ def to_hash
428
+ hash = {}
429
+ self.class.attribute_map.each_pair do |attr, param|
430
+ value = self.send(attr)
431
+ if value.nil?
432
+ is_nullable = self.class.openapi_nullable.include?(attr)
433
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
434
+ end
435
+
436
+ hash[param] = _to_hash(value)
437
+ end
438
+ hash
439
+ end
440
+
441
+ # Outputs non-array value in the form of hash
442
+ # For object, use to_hash. Otherwise, just return the value
443
+ # @param [Object] value Any valid value
444
+ # @return [Hash] Returns the value in the form of hash
445
+ def _to_hash(value)
446
+ if value.is_a?(Array)
447
+ value.compact.map { |v| _to_hash(v) }
448
+ elsif value.is_a?(Hash)
449
+ {}.tap do |hash|
450
+ value.each { |k, v| hash[k] = _to_hash(v) }
451
+ end
452
+ elsif value.respond_to? :to_hash
453
+ value.to_hash
454
+ else
455
+ value
456
+ end
457
+ end
458
+
459
+ end
460
+
461
+ end