adzerk_decision_sdk 1.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +70 -0
  4. data/README.md +97 -0
  5. data/Rakefile +10 -0
  6. data/adzerk_decision_sdk.gemspec +39 -0
  7. data/docs/Consent.md +17 -0
  8. data/docs/ConsentRequest.md +19 -0
  9. data/docs/Content.md +25 -0
  10. data/docs/Decision.md +35 -0
  11. data/docs/DecisionApi.md +57 -0
  12. data/docs/DecisionData.md +25 -0
  13. data/docs/DecisionRequest.md +43 -0
  14. data/docs/DecisionResponse.md +21 -0
  15. data/docs/Event.md +19 -0
  16. data/docs/GdprConsent.md +19 -0
  17. data/docs/Placement.md +47 -0
  18. data/docs/PricingData.md +25 -0
  19. data/docs/Request.md +43 -0
  20. data/docs/RequestConsent.md +17 -0
  21. data/docs/Response.md +21 -0
  22. data/docs/User.md +17 -0
  23. data/docs/UserdbApi.md +536 -0
  24. data/git_push.sh +58 -0
  25. data/lib/adzerk_decision_sdk/api/decision_api.rb +80 -0
  26. data/lib/adzerk_decision_sdk/api/userdb_api.rb +731 -0
  27. data/lib/adzerk_decision_sdk/api_client.rb +386 -0
  28. data/lib/adzerk_decision_sdk/api_error.rb +57 -0
  29. data/lib/adzerk_decision_sdk/client.rb +43 -0
  30. data/lib/adzerk_decision_sdk/configuration.rb +262 -0
  31. data/lib/adzerk_decision_sdk/decision_client.rb +73 -0
  32. data/lib/adzerk_decision_sdk/event_type.rb +61 -0
  33. data/lib/adzerk_decision_sdk/models/consent_request.rb +215 -0
  34. data/lib/adzerk_decision_sdk/models/content.rb +242 -0
  35. data/lib/adzerk_decision_sdk/models/decision.rb +291 -0
  36. data/lib/adzerk_decision_sdk/models/decision_data.rb +242 -0
  37. data/lib/adzerk_decision_sdk/models/decision_request.rb +359 -0
  38. data/lib/adzerk_decision_sdk/models/decision_response.rb +224 -0
  39. data/lib/adzerk_decision_sdk/models/event.rb +215 -0
  40. data/lib/adzerk_decision_sdk/models/placement.rb +377 -0
  41. data/lib/adzerk_decision_sdk/models/pricing_data.rb +242 -0
  42. data/lib/adzerk_decision_sdk/models/user.rb +208 -0
  43. data/lib/adzerk_decision_sdk/pixel_client.rb +26 -0
  44. data/lib/adzerk_decision_sdk/rate_type.rb +8 -0
  45. data/lib/adzerk_decision_sdk/user_db_client.rb +64 -0
  46. data/lib/adzerk_decision_sdk/version.rb +15 -0
  47. data/lib/adzerk_decision_sdk.rb +58 -0
  48. data/pkg/adzerk_decision_sdk-1.0.0.gem +0 -0
  49. data/spec/.gitkeep +0 -0
  50. data/spec/placeholder_spec.rb +9 -0
  51. metadata +153 -0
@@ -0,0 +1,262 @@
1
+ =begin
2
+ #Adzerk Decision API
3
+
4
+ #Adzerk Decision API
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ module AdzerkDecisionSdk
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Defines API keys used with API Key authentications.
25
+ #
26
+ # @return [Hash] key: parameter name, value: parameter value (API key)
27
+ #
28
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
29
+ # config.api_key['api_key'] = 'xxx'
30
+ attr_accessor :api_key
31
+
32
+ # Defines API key prefixes used with API Key authentications.
33
+ #
34
+ # @return [Hash] key: parameter name, value: API key prefix
35
+ #
36
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
37
+ # config.api_key_prefix['api_key'] = 'Token'
38
+ attr_accessor :api_key_prefix
39
+
40
+ # Defines the username used with HTTP basic authentication.
41
+ #
42
+ # @return [String]
43
+ attr_accessor :username
44
+
45
+ # Defines the password used with HTTP basic authentication.
46
+ #
47
+ # @return [String]
48
+ attr_accessor :password
49
+
50
+ # Defines the access token (Bearer) used with OAuth2.
51
+ attr_accessor :access_token
52
+
53
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
54
+ # details will be logged with `logger.debug` (see the `logger` attribute).
55
+ # Default to false.
56
+ #
57
+ # @return [true, false]
58
+ attr_accessor :debugging
59
+
60
+ # Defines the logger used for debugging.
61
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
62
+ #
63
+ # @return [#debug]
64
+ attr_accessor :logger
65
+
66
+ # Defines the temporary folder to store downloaded files
67
+ # (for API endpoints that have file response).
68
+ # Default to use `Tempfile`.
69
+ #
70
+ # @return [String]
71
+ attr_accessor :temp_folder_path
72
+
73
+ # The time limit for HTTP request in seconds.
74
+ # Default to 0 (never times out).
75
+ attr_accessor :timeout
76
+
77
+ # Set this to false to skip client side validation in the operation.
78
+ # Default to true.
79
+ # @return [true, false]
80
+ attr_accessor :client_side_validation
81
+
82
+ ### TLS/SSL setting
83
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
84
+ # Default to true.
85
+ #
86
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
87
+ #
88
+ # @return [true, false]
89
+ attr_accessor :verify_ssl
90
+
91
+ ### TLS/SSL setting
92
+ # Set this to false to skip verifying SSL host name
93
+ # Default to true.
94
+ #
95
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
96
+ #
97
+ # @return [true, false]
98
+ attr_accessor :verify_ssl_host
99
+
100
+ ### TLS/SSL setting
101
+ # Set this to customize the certificate file to verify the peer.
102
+ #
103
+ # @return [String] the path to the certificate file
104
+ #
105
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
106
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
107
+ attr_accessor :ssl_ca_cert
108
+
109
+ ### TLS/SSL setting
110
+ # Client certificate file (for client certificate)
111
+ attr_accessor :cert_file
112
+
113
+ ### TLS/SSL setting
114
+ # Client private key file (for client certificate)
115
+ attr_accessor :key_file
116
+
117
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
118
+ # Default to nil.
119
+ #
120
+ # @see The params_encoding option of Ethon. Related source code:
121
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
122
+ attr_accessor :params_encoding
123
+
124
+ attr_accessor :inject_format
125
+
126
+ attr_accessor :force_ending_format
127
+
128
+ def initialize
129
+ @scheme = 'https'
130
+ @host = 'e-23.adzerk.net'
131
+ @base_path = ''
132
+ @api_key = {}
133
+ @api_key_prefix = {}
134
+ @timeout = 0
135
+ @client_side_validation = true
136
+ @verify_ssl = true
137
+ @verify_ssl_host = true
138
+ @params_encoding = nil
139
+ @cert_file = nil
140
+ @key_file = nil
141
+ @debugging = false
142
+ @inject_format = false
143
+ @force_ending_format = false
144
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
145
+
146
+ yield(self) if block_given?
147
+ end
148
+
149
+ # The default Configuration object.
150
+ def self.default
151
+ @@default ||= Configuration.new
152
+ end
153
+
154
+ def configure
155
+ yield(self) if block_given?
156
+ end
157
+
158
+ def scheme=(scheme)
159
+ # remove :// from scheme
160
+ @scheme = scheme.sub(/:\/\//, '')
161
+ end
162
+
163
+ def host=(host)
164
+ # remove http(s):// and anything after a slash
165
+ @host = host.sub(/https?:\/\//, '').split('/').first
166
+ end
167
+
168
+ def base_path=(base_path)
169
+ # Add leading and trailing slashes to base_path
170
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
171
+ @base_path = '' if @base_path == '/'
172
+ end
173
+
174
+ def base_url
175
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
176
+ end
177
+
178
+ # Gets API key (with prefix if set).
179
+ # @param [String] param_name the parameter name of API key auth
180
+ def api_key_with_prefix(param_name)
181
+ if @api_key_prefix[param_name]
182
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
183
+ else
184
+ @api_key[param_name]
185
+ end
186
+ end
187
+
188
+ # Gets Basic Auth token string
189
+ def basic_auth_token
190
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
191
+ end
192
+
193
+ # Returns Auth Settings hash for api client.
194
+ def auth_settings
195
+ {
196
+ 'ApiKeyAuth' =>
197
+ {
198
+ type: 'api_key',
199
+ in: 'header',
200
+ key: 'X-Adzerk-ApiKey',
201
+ value: api_key_with_prefix('X-Adzerk-ApiKey')
202
+ },
203
+ }
204
+ end
205
+
206
+ # Returns an array of Server setting
207
+ def server_settings
208
+ [
209
+ {
210
+ url: "{protocol}://e-{networkId}.adzerk.net",
211
+ description: "No description provided",
212
+ variables: {
213
+ protocol: {
214
+ description: "No description provided",
215
+ default_value: "https",
216
+ enum_values: [
217
+ "http",
218
+ "https"
219
+ ]
220
+ },
221
+ networkId: {
222
+ description: "Your Adzerk Network Id",
223
+ default_value: "23",
224
+ }
225
+ }
226
+ }
227
+ ]
228
+ end
229
+
230
+ # Returns URL based on server settings
231
+ #
232
+ # @param index array index of the server settings
233
+ # @param variables hash of variable and the corresponding value
234
+ def server_url(index, variables = {})
235
+ servers = server_settings
236
+
237
+ # check array index out of bound
238
+ if (index < 0 || index >= servers.size)
239
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
240
+ end
241
+
242
+ server = servers[index]
243
+ url = server[:url]
244
+
245
+ # go through variable and assign a value
246
+ server[:variables].each do |name, variable|
247
+ if variables.key?(name)
248
+ if (server[:variables][name][:enum_values].include? variables[name])
249
+ url.gsub! "{" + name.to_s + "}", variables[name]
250
+ else
251
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
252
+ end
253
+ else
254
+ # use default value
255
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
256
+ end
257
+ end
258
+
259
+ url
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,73 @@
1
+ require 'adzerk_decision_sdk/api/decision_api'
2
+
3
+ module AdzerkDecisionSdk
4
+ class DecisionClient
5
+ def initialize(network_id, site_id, api_client, logger)
6
+ @network_id = network_id
7
+ @site_id = site_id
8
+ @api = DecisionApi.new(api_client)
9
+ @logger = logger
10
+ end
11
+
12
+ def get(request, opts = {})
13
+ opts ||= {}
14
+ header_params = opts[:header_params] || {}
15
+ opts[:body] ||= request.respond_to?('to_hash') ? request.to_hash() : request
16
+
17
+ @logger.info("Processing request: #{opts[:body]}")
18
+
19
+ opts[:body][:enableBotFiltering] = false if not opts[:body].has_key?(:enableBotFiltering)
20
+
21
+ if !opts[:body].has_key?(:placements) or !opts[:body][:placements] or !opts[:body][:placements].length() == 0
22
+ fail ArgumentError, "Each request requires at least one placement"
23
+ end
24
+
25
+ opts[:body][:placements].each_with_index do |placement, idx|
26
+ if !placement.has_key?(:adTypes) or !placements[:adTypes] or placement[:adTypes].length() == 0
27
+ fail ArgumentError, "Each placement needs at least one ad type"
28
+ end
29
+ placement[:networkId] = @network_id if not placement.has_key?(:networkId)
30
+ placement[:siteId] = @site_id if not placement.has_key?(:siteId)
31
+ placement[:divName] = "div#{idx}" if not placement.has_key?(:divName)
32
+ end
33
+
34
+ header_params['User-Agent'] = opts[:user_agent] if opts.has_key?(:user_agent)
35
+
36
+ if opts.has_key?(:include_explanation) and opts[:include_explanation] == true
37
+ header_params['X-Adzerk-Explain'] = opts[:api_key]
38
+ @logger.info("--------------------------------------------------------------")
39
+ @logger.info(" !!! WARNING - WARNING - WARNING !!! ")
40
+ @logger.info("")
41
+ @logger.info("You have opted to include explainer details with this request!")
42
+ @logger.info("This will cause performance degradation and should not be done")
43
+ @logger.info("in production environments.")
44
+ @logger.info("--------------------------------------------------------------")
45
+ end
46
+
47
+ opts[:header_params] = header_params
48
+
49
+ @logger.info("Processed request: #{opts[:body]}")
50
+ @logger.info("Requesting with headers: #{opts[:header_params]}")
51
+
52
+ response = @api.get_decisions(opts)
53
+
54
+ parsed_response = parse_response(response)
55
+ @logger.info("Recieved response: #{parsed_response}")
56
+
57
+ return parsed_response
58
+ end
59
+
60
+ private
61
+
62
+ def parse_response(response)
63
+ response.decisions.keys.each do |k|
64
+ response.decisions[k] = response.decisions[k].is_a?(Array) ? response.decisions[k] : [response.decisions[k]]
65
+ response.decisions[k].each_with_index do |d, i|
66
+ response.decisions[k][i] = AdzerkDecisionSdk::Decision.build_from_hash(d)
67
+ end
68
+ end
69
+
70
+ response
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,61 @@
1
+ module EventType
2
+ VIEW_CONVERSION = 1
3
+ CLICK_CONVERSION = 2
4
+ SERVER_TO_SERVER_CONVERSION = 3
5
+ UPVOTE = 10
6
+ DOWNVOTE = 11
7
+ DOWNVOTE_UNINTERESTING = 12
8
+ DOWNVOTE_MISLEADING = 13
9
+ DOWNVOTE_OFFENSIVE = 14
10
+ DOWNVOTE_REPETITIVE = 15
11
+ DOWNVOTE_OTHER = 16
12
+ CLOSE_AD = 17
13
+ LIKE = 20
14
+ SHARE = 21
15
+ COMMENT = 22
16
+ COMMENT_REPLY = 101
17
+ COMMENT_UPVOTE = 102
18
+ COMMENT_DOWNVOTE = 103
19
+ VISIBLE = 30
20
+ HOVER = 31
21
+ EXPAND_DIV = 32
22
+ VIEWABLE_IMPRESSION = 40
23
+ SHARE_ON_FACEBOOK = 50
24
+ SHARE_ON_TWITTER = 51
25
+ SHARE_ON_PINTEREST = 52
26
+ SHARE_ON_REDDIT = 53
27
+ SHARE_ON_EMAIL = 54
28
+ VIDEO_START = 70
29
+ VIDEO_FIRST_QUARTILE = 71
30
+ VIDEO_MID_POINT = 72
31
+ VIDEO_THIRD_QUARTILE = 73
32
+ VIDEO_COMPLETE = 74
33
+ VIDEO_MUTE = 75
34
+ VIDEO_UNMUTE = 76
35
+ VIDEO_PAUSE = 77
36
+ VIDEO_REWIND = 78
37
+ VIDEO_RESUME = 79
38
+ VIDEO_FULL_SCREEN = 80
39
+ VIDEO_EXIT_FULL_SCREEN = 81
40
+ VIDEO_EXPAND = 82
41
+ VIDEO_COLLAPSE = 83
42
+ VIDEO_ACCEPT_INVITATION_LINEAR = 84
43
+ VIDEO_CLOSE_LINEAR = 85
44
+ VIDEO_SKIP = 86
45
+ VIDEO_PROGRESS = 87
46
+ VIDEO_ZERO_SECONDS_VIEWED = 400
47
+ VIDEO_ONE_SECONDS_VIEWED = 401
48
+ VIDEO_TWO_SECONDS_VIEWED = 402
49
+ VIDEO_THREE_SECONDS_VIEWED = 403
50
+ VIDEO_FOUR_SECONDS_VIEWED = 404
51
+ VIDEO_FIVE_SECONDS_VIEWED = 405
52
+ VIDEO_SIX_SECONDS_VIEWED = 406
53
+ VIDEO_SEVEN_SECONDS_VIEWED = 407
54
+ VIDEO_EIGHT_SECONDS_VIEWED = 408
55
+ VIDEO_NINE_SECONDS_VIEWED = 409
56
+ VIDEO_TEN_SECONDS_VIEWED = 410
57
+ VIDEO_FIFTEEN_SECONDS_VIEWED = 415
58
+ VIDEO_TWENTY_SECONDS_VIEWED = 420
59
+ VIDEO_TWENTY_FIVE_SECONDS_VIEWED = 425
60
+ VIDEO_THIRTY_SECONDS_VIEWED = 430
61
+ end
@@ -0,0 +1,215 @@
1
+ =begin
2
+ #Adzerk Decision API
3
+
4
+ #Adzerk Decision API
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.3
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module AdzerkDecisionSdk
16
+ class ConsentRequest
17
+ attr_accessor :user_key
18
+
19
+ attr_accessor :consent
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'user_key' => :'userKey',
25
+ :'consent' => :'consent'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'user_key' => :'String',
33
+ :'consent' => :'Object'
34
+ }
35
+ end
36
+
37
+ # List of attributes with nullable: true
38
+ def self.openapi_nullable
39
+ Set.new([
40
+ ])
41
+ end
42
+
43
+ # Initializes the object
44
+ # @param [Hash] attributes Model attributes in the form of hash
45
+ def initialize(attributes = {})
46
+ if (!attributes.is_a?(Hash))
47
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AdzerkDecisionSdk::ConsentRequest` initialize method"
48
+ end
49
+
50
+ # check to see if the attribute exists and convert string to symbol for hash key
51
+ attributes = attributes.each_with_object({}) { |(k, v), h|
52
+ if (!self.class.attribute_map.key?(k.to_sym))
53
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AdzerkDecisionSdk::ConsentRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
54
+ end
55
+ h[k.to_sym] = v
56
+ }
57
+
58
+ if attributes.key?(:'user_key')
59
+ self.user_key = attributes[:'user_key']
60
+ end
61
+
62
+ if attributes.key?(:'consent')
63
+ self.consent = attributes[:'consent']
64
+ end
65
+ end
66
+
67
+ # Show invalid properties with the reasons. Usually used together with valid?
68
+ # @return Array for valid properties with the reasons
69
+ def list_invalid_properties
70
+ invalid_properties = Array.new
71
+ invalid_properties
72
+ end
73
+
74
+ # Check to see if the all the properties in the model are valid
75
+ # @return true if the model is valid
76
+ def valid?
77
+ true
78
+ end
79
+
80
+ # Checks equality by comparing each attribute.
81
+ # @param [Object] Object to be compared
82
+ def ==(o)
83
+ return true if self.equal?(o)
84
+ self.class == o.class &&
85
+ user_key == o.user_key &&
86
+ consent == o.consent
87
+ end
88
+
89
+ # @see the `==` method
90
+ # @param [Object] Object to be compared
91
+ def eql?(o)
92
+ self == o
93
+ end
94
+
95
+ # Calculates hash code according to all attributes.
96
+ # @return [Integer] Hash code
97
+ def hash
98
+ [user_key, consent].hash
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def self.build_from_hash(attributes)
105
+ new.build_from_hash(attributes)
106
+ end
107
+
108
+ # Builds the object from hash
109
+ # @param [Hash] attributes Model attributes in the form of hash
110
+ # @return [Object] Returns the model itself
111
+ def build_from_hash(attributes)
112
+ return nil unless attributes.is_a?(Hash)
113
+ self.class.openapi_types.each_pair do |key, type|
114
+ if type =~ /\AArray<(.*)>/i
115
+ # check to ensure the input is an array given that the attribute
116
+ # is documented as an array but the input is not
117
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
118
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
119
+ end
120
+ elsif !attributes[self.class.attribute_map[key]].nil?
121
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
122
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
123
+ end
124
+
125
+ self
126
+ end
127
+
128
+ # Deserializes the data based on type
129
+ # @param string type Data type
130
+ # @param string value Value to be deserialized
131
+ # @return [Object] Deserialized data
132
+ def _deserialize(type, value)
133
+ case type.to_sym
134
+ when :DateTime
135
+ DateTime.parse(value)
136
+ when :Date
137
+ Date.parse(value)
138
+ when :String
139
+ value.to_s
140
+ when :Integer
141
+ value.to_i
142
+ when :Float
143
+ value.to_f
144
+ when :Boolean
145
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
146
+ true
147
+ else
148
+ false
149
+ end
150
+ when :Object
151
+ # generic object (usually a Hash), return directly
152
+ value
153
+ when /\AArray<(?<inner_type>.+)>\z/
154
+ inner_type = Regexp.last_match[:inner_type]
155
+ value.map { |v| _deserialize(inner_type, v) }
156
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
157
+ k_type = Regexp.last_match[:k_type]
158
+ v_type = Regexp.last_match[:v_type]
159
+ {}.tap do |hash|
160
+ value.each do |k, v|
161
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
162
+ end
163
+ end
164
+ else # model
165
+ AdzerkDecisionSdk.const_get(type).build_from_hash(value)
166
+ end
167
+ end
168
+
169
+ # Returns the string representation of the object
170
+ # @return [String] String presentation of the object
171
+ def to_s
172
+ to_hash.to_s
173
+ end
174
+
175
+ # to_body is an alias to to_hash (backward compatibility)
176
+ # @return [Hash] Returns the object in the form of hash
177
+ def to_body
178
+ to_hash
179
+ end
180
+
181
+ # Returns the object in the form of hash
182
+ # @return [Hash] Returns the object in the form of hash
183
+ def to_hash
184
+ hash = {}
185
+ self.class.attribute_map.each_pair do |attr, param|
186
+ value = self.send(attr)
187
+ if value.nil?
188
+ is_nullable = self.class.openapi_nullable.include?(attr)
189
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
190
+ end
191
+
192
+ hash[param] = _to_hash(value)
193
+ end
194
+ hash
195
+ end
196
+
197
+ # Outputs non-array value in the form of hash
198
+ # For object, use to_hash. Otherwise, just return the value
199
+ # @param [Object] value Any valid value
200
+ # @return [Hash] Returns the value in the form of hash
201
+ def _to_hash(value)
202
+ if value.is_a?(Array)
203
+ value.compact.map { |v| _to_hash(v) }
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.each { |k, v| hash[k] = _to_hash(v) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash
210
+ else
211
+ value
212
+ end
213
+ end
214
+ end
215
+ end