mastercard_core_sdk 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +24 -0
  3. data/README.md +66 -0
  4. data/lib/mastercard_core_sdk/api/access_token_api.rb +31 -0
  5. data/lib/mastercard_core_sdk/api/request_token_api.rb +30 -0
  6. data/lib/mastercard_core_sdk/client/api_client.rb +192 -0
  7. data/lib/mastercard_core_sdk/constants/constants.rb +95 -0
  8. data/lib/mastercard_core_sdk/converters/encoded_url_converter.rb +55 -0
  9. data/lib/mastercard_core_sdk/converters/json_converter.rb +107 -0
  10. data/lib/mastercard_core_sdk/converters/sdk_converter_factory.rb +57 -0
  11. data/lib/mastercard_core_sdk/converters/xml_converter.rb +52 -0
  12. data/lib/mastercard_core_sdk/core/api_config.rb +18 -0
  13. data/lib/mastercard_core_sdk/core/api_config_builder.rb +48 -0
  14. data/lib/mastercard_core_sdk/core/configuration.rb +81 -0
  15. data/lib/mastercard_core_sdk/core/mastercard_api_configuration.rb +100 -0
  16. data/lib/mastercard_core_sdk/core/mastercard_authenticator.rb +25 -0
  17. data/lib/mastercard_core_sdk/core/query_params.rb +23 -0
  18. data/lib/mastercard_core_sdk/core/request_response_logger.rb +101 -0
  19. data/lib/mastercard_core_sdk/core/service_request.rb +24 -0
  20. data/lib/mastercard_core_sdk/exceptions/error_handler.rb +130 -0
  21. data/lib/mastercard_core_sdk/exceptions/sdk_base_error.rb +28 -0
  22. data/lib/mastercard_core_sdk/exceptions/sdk_conversion_error.rb +18 -0
  23. data/lib/mastercard_core_sdk/exceptions/sdk_oauth_error.rb +16 -0
  24. data/lib/mastercard_core_sdk/exceptions/sdk_response_error.rb +17 -0
  25. data/lib/mastercard_core_sdk/exceptions/sdk_validation_error.rb +16 -0
  26. data/lib/mastercard_core_sdk/interceptors/api_tracker_builder.rb +44 -0
  27. data/lib/mastercard_core_sdk/interceptors/logger_builder.rb +22 -0
  28. data/lib/mastercard_core_sdk/interceptors/signature_builder.rb +18 -0
  29. data/lib/mastercard_core_sdk/models/access_token_response.rb +150 -0
  30. data/lib/mastercard_core_sdk/models/detail.rb +165 -0
  31. data/lib/mastercard_core_sdk/models/details.rb +159 -0
  32. data/lib/mastercard_core_sdk/models/error.rb +212 -0
  33. data/lib/mastercard_core_sdk/models/error_response.rb +14 -0
  34. data/lib/mastercard_core_sdk/models/errors.rb +167 -0
  35. data/lib/mastercard_core_sdk/models/extension_point.rb +153 -0
  36. data/lib/mastercard_core_sdk/models/request_token_response.rb +169 -0
  37. data/lib/mastercard_core_sdk/oauth/oauth_parameters.rb +20 -0
  38. data/lib/mastercard_core_sdk/oauth/oauth_util.rb +205 -0
  39. data/lib/mastercard_core_sdk/tracker/api_tracker.rb +20 -0
  40. data/lib/mastercard_core_sdk/tracker/token_api_tracker.rb +52 -0
  41. data/lib/mastercard_core_sdk/version.rb +3 -0
  42. data/lib/mastercard_core_sdk.rb +65 -0
  43. metadata +208 -0
@@ -0,0 +1,212 @@
1
+ require 'date'
2
+ require 'roxml'
3
+
4
+ require_relative '../models/details'
5
+ require_relative '../models/extension_point'
6
+
7
+ module MastercardCoreSdk
8
+ # Defines attributes require for error handling.
9
+ class Error
10
+ include ROXML
11
+
12
+ xml_name "Error"
13
+
14
+ # @!attribute description
15
+ # @return [String] the error description.
16
+ xml_accessor :description, :from => "Description"
17
+
18
+ # @!attribute reason_code
19
+ # @return [String] the error reason code.
20
+ xml_accessor :reason_code, :from => "ReasonCode"
21
+
22
+ # @!attribute recoverable
23
+ # @return [BOOLEAN] the error recoverable info.
24
+ xml_accessor :recoverable, :from => "Recoverable"
25
+
26
+ # @!attribute source
27
+ # @return [String] the source of error.
28
+ xml_accessor :source, :from => "Source"
29
+
30
+ # @!attribute details
31
+ # @return [Details] the error details.
32
+ xml_accessor :details, :from => "Details", :as => Details
33
+
34
+ # @!attribute extension_point
35
+ # @return [ExtensionPoint] the ExtensionPoint for future enhancement.
36
+ xml_accessor :extension_point, :from => "ExtensionPoint", :as => ExtensionPoint
37
+
38
+ # Attribute mapping from ruby-style variable name to JSON key.
39
+ def self.attribute_map
40
+ {
41
+ :'description' => :'Description',
42
+ :'reason_code' => :'ReasonCode',
43
+ :'recoverable' => :'Recoverable',
44
+ :'source' => :'Source',
45
+ :'details' => :'Details',
46
+ :'extension_point' => :'ExtensionPoint'
47
+ }
48
+ end
49
+
50
+ # Attribute type mapping.
51
+ def self.swagger_types
52
+ {
53
+ :'description' => :'String',
54
+ :'reason_code' => :'String',
55
+ :'recoverable' => :'BOOLEAN',
56
+ :'source' => :'String',
57
+ :'details' => :'Details',
58
+ :'extension_point' => :'ExtensionPoint'
59
+ }
60
+ end
61
+
62
+ def initialize(attributes = {})
63
+ return unless attributes.is_a?(Hash)
64
+
65
+ # convert string to symbol for hash key
66
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
67
+
68
+ if attributes.has_key?(:Description) || attributes.has_key?(:description)
69
+ self.description = attributes[:Description] || attributes[:description]
70
+ end
71
+
72
+ if attributes.has_key?(:ReasonCode) || attributes.has_key?(:reason_code)
73
+ self.reason_code = attributes[:ReasonCode] || attributes[:reason_code]
74
+ end
75
+
76
+ if attributes.has_key?(:Recoverable) || attributes.has_key?(:recoverable)
77
+ self.recoverable = attributes[:Recoverable] || attributes[:recoverable]
78
+ end
79
+
80
+ if attributes.has_key?(:Source) || attributes.has_key?(:source)
81
+ self.source = attributes[:Source] || attributes[:source]
82
+ end
83
+
84
+ if attributes.has_key?(:Details) || attributes.has_key?(:details)
85
+ self.details = attributes[:Details] || attributes[:details]
86
+ end
87
+
88
+ if attributes.has_key?(:ExtensionPoint) || attributes.has_key?(:extension_point)
89
+ self.extension_point = attributes[:ExtensionPoint] || attributes[:extension_point]
90
+ end
91
+ end
92
+
93
+ # Check equality by comparing each attribute.
94
+ def ==(o)
95
+ return true if self.equal?(o)
96
+ self.class == o.class &&
97
+ description == o.description &&
98
+ reason_code == o.reason_code &&
99
+ recoverable == o.recoverable &&
100
+ source == o.source &&
101
+ details == o.details &&
102
+ extension_point == o.extension_point
103
+ end
104
+
105
+ # @see the `==` method
106
+ def eql?(o)
107
+ self == o
108
+ end
109
+
110
+ # Calculate hash code according to all attributes.
111
+ def hash
112
+ [description, reason_code, recoverable, source, details, extension_point].hash
113
+ end
114
+
115
+ # build the object from hash
116
+ def build_from_hash(attributes)
117
+ return nil unless attributes.is_a?(Hash)
118
+ self.class.swagger_types.each_pair do |key, type|
119
+ if type =~ /^Array<(.*)>/i
120
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
121
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
122
+ else
123
+ #TODO show warning in debug mode
124
+ end
125
+ elsif !attributes[self.class.attribute_map[key]].nil?
126
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
127
+ else
128
+ # data not found in attributes(hash), not an issue as the data can be optional
129
+ end
130
+ end
131
+
132
+ self
133
+ end
134
+
135
+ def _deserialize(type, value)
136
+ case type.to_sym
137
+ when :DateTime
138
+ DateTime.parse(value)
139
+ when :Date
140
+ Date.parse(value)
141
+ when :String
142
+ value.to_s
143
+ when :Integer
144
+ value.to_i
145
+ when :Float
146
+ value.to_f
147
+ when :BOOLEAN
148
+ if value =~ /^(true|t|yes|y|1)$/i
149
+ true
150
+ else
151
+ false
152
+ end
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
+ _model = Mpass.const_get(type).new
166
+ _model.build_from_hash(value)
167
+ end
168
+ end
169
+
170
+ def to_s
171
+ to_hash.to_s
172
+ end
173
+
174
+ # to_body is an alias to to_body (backward compatibility))
175
+ def to_body
176
+ to_hash
177
+ end
178
+
179
+ # return the object in the form of hash
180
+ def to_hash
181
+ hash = {}
182
+ self.class.attribute_map.each_pair do |attr, param|
183
+ value = self.send(attr)
184
+ next if value.nil?
185
+ hash[param] = _to_hash(value)
186
+ end
187
+ hash
188
+ end
189
+
190
+ # Method to output non-array value in the form of hash
191
+ # For object, use to_hash. Otherwise, just return the value
192
+ def _to_hash(value)
193
+ if value.is_a?(Array)
194
+ value.compact.map{ |v| _to_hash(v) }
195
+ elsif value.is_a?(Hash)
196
+ {}.tap do |hash|
197
+ value.each { |k, v| hash[k] = _to_hash(v) }
198
+ end
199
+ elsif value.respond_to? :to_hash
200
+ value.to_hash
201
+ else
202
+ value
203
+ end
204
+ end
205
+
206
+ private
207
+
208
+ def after_parse
209
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,14 @@
1
+ module MastercardCoreSdk
2
+ # Defines attributes for details of error response.
3
+ class ErrorResponse
4
+
5
+ attr_accessor :response, :response_code, :message, :error_source
6
+
7
+ def initialize(args)
8
+ args.each do |k,v|
9
+ instance_variable_set("@#{k}",v) unless v.nil?
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,167 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../models/error'
4
+
5
+ module MastercardCoreSdk
6
+ # Defines attributes require for error handling.
7
+ class Errors
8
+ include ROXML
9
+
10
+ xml_name "Errors"
11
+
12
+ # @!attribute detail
13
+ # @return [Array<Error>] the error.
14
+ xml_accessor :error, :from => "Error", :as =>[Error]
15
+
16
+ # Attribute mapping from ruby-style variable name to JSON key.
17
+ def self.attribute_map
18
+ {
19
+ :'error' => :'Error'
20
+ }
21
+ end
22
+
23
+ # Attribute type mapping.
24
+ def self.swagger_types
25
+ {
26
+ :'error' => :'Array<Error>'
27
+ }
28
+ end
29
+
30
+ def initialize(attributes = {})
31
+ return unless attributes.is_a?(Hash)
32
+
33
+ # convert string to symbol for hash key
34
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
35
+
36
+ if attributes.has_key?(:Error) || attributes.has_key?(:error)
37
+ self.error = attributes[:Error] || attributes[:error]
38
+ end
39
+ end
40
+
41
+ # Overriding setter method error
42
+ # @param value
43
+ def error=(value)
44
+ if (value.is_a?(Array))
45
+ @error = value
46
+ else
47
+ @error = [] if !@error
48
+ @error.push value
49
+ end
50
+ end
51
+
52
+ # Check equality by comparing each attribute.
53
+ def ==(o)
54
+ return true if self.equal?(o)
55
+ self.class == o.class &&
56
+ error == o.error
57
+ end
58
+
59
+ # @see the `==` method
60
+ def eql?(o)
61
+ self == o
62
+ end
63
+
64
+ # Calculate hash code according to all attributes.
65
+ def hash
66
+ [error].hash
67
+ end
68
+
69
+ # build the object from hash
70
+ def build_from_hash(attributes)
71
+ return nil unless attributes.is_a?(Hash)
72
+ self.class.swagger_types.each_pair do |key, type|
73
+ if type =~ /^Array<(.*)>/i
74
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
75
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
76
+ else
77
+ #TODO show warning in debug mode
78
+ end
79
+ elsif !attributes[self.class.attribute_map[key]].nil?
80
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
81
+ else
82
+ # data not found in attributes(hash), not an issue as the data can be optional
83
+ end
84
+ end
85
+
86
+ self
87
+ end
88
+
89
+ def _deserialize(type, value)
90
+ case type.to_sym
91
+ when :DateTime
92
+ DateTime.parse(value)
93
+ when :Date
94
+ Date.parse(value)
95
+ when :String
96
+ value.to_s
97
+ when :Integer
98
+ value.to_i
99
+ when :Float
100
+ value.to_f
101
+ when :BOOLEAN
102
+ if value =~ /^(true|t|yes|y|1)$/i
103
+ true
104
+ else
105
+ false
106
+ end
107
+ when /\AArray<(?<inner_type>.+)>\z/
108
+ inner_type = Regexp.last_match[:inner_type]
109
+ value.map { |v| _deserialize(inner_type, v) }
110
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
111
+ k_type = Regexp.last_match[:k_type]
112
+ v_type = Regexp.last_match[:v_type]
113
+ {}.tap do |hash|
114
+ value.each do |k, v|
115
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
116
+ end
117
+ end
118
+ else # model
119
+ _model = MastercardCoreSdk.const_get(type).new
120
+ _model.build_from_hash(value)
121
+ end
122
+ end
123
+
124
+ def to_s
125
+ to_hash.to_s
126
+ end
127
+
128
+ # to_body is an alias to to_body (backward compatibility))
129
+ def to_body
130
+ to_hash
131
+ end
132
+
133
+ # return the object in the form of hash
134
+ def to_hash
135
+ hash = {}
136
+ self.class.attribute_map.each_pair do |attr, param|
137
+ value = self.send(attr)
138
+ next if value.nil?
139
+ hash[param] = _to_hash(value)
140
+ end
141
+ hash
142
+ end
143
+
144
+ # Method to output non-array value in the form of hash
145
+ # For object, use to_hash. Otherwise, just return the value
146
+ def _to_hash(value)
147
+ if value.is_a?(Array)
148
+ value.compact.map{ |v| _to_hash(v) }
149
+ elsif value.is_a?(Hash)
150
+ {}.tap do |hash|
151
+ value.each { |k, v| hash[k] = _to_hash(v) }
152
+ end
153
+ elsif value.respond_to? :to_hash
154
+ value.to_hash
155
+ else
156
+ value
157
+ end
158
+ end
159
+
160
+ private
161
+
162
+ def after_parse
163
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
164
+ end
165
+
166
+ end
167
+ end
@@ -0,0 +1,153 @@
1
+ require 'date'
2
+ require 'roxml'
3
+
4
+ module MastercardCoreSdk
5
+ # Defines attributes required to set additional details.
6
+ class ExtensionPoint
7
+ include ROXML
8
+
9
+ xml_name "ExtensionPoint"
10
+
11
+ xml_accessor :any, :from => "any"
12
+ # Attribute mapping from ruby-style variable name to JSON key.
13
+ def self.attribute_map
14
+ {
15
+ :'any' => :'any'
16
+ }
17
+ end
18
+
19
+ # Attribute type mapping.
20
+ def self.swagger_types
21
+ {
22
+ :'any' => :'Object'
23
+ }
24
+ end
25
+
26
+ def initialize(attributes = {})
27
+ return unless attributes.is_a?(Hash)
28
+
29
+ # convert string to symbol for hash key
30
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
31
+
32
+ if attributes.has_key?(:any)
33
+ self.any = attributes[:any]
34
+ end
35
+
36
+ end
37
+
38
+ # Check equality by comparing each attribute.
39
+ def ==(o)
40
+ return true if self.equal?(o)
41
+ self.class == o.class &&
42
+ any == o.any
43
+ end
44
+
45
+ # @see the `==` method
46
+ def eql?(o)
47
+ self == o
48
+ end
49
+
50
+ # Calculate hash code according to all attributes.
51
+ def hash
52
+ [any].hash
53
+ end
54
+
55
+ # build the object from hash
56
+ def build_from_hash(attributes)
57
+ return nil unless attributes.is_a?(Hash)
58
+ self.class.swagger_types.each_pair do |key, type|
59
+ if type =~ /^Array<(.*)>/i
60
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
61
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
62
+ else
63
+ #TODO show warning in debug mode
64
+ end
65
+ elsif !attributes[self.class.attribute_map[key]].nil?
66
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
67
+ else
68
+ # data not found in attributes(hash), not an issue as the data can be optional
69
+ end
70
+ end
71
+
72
+ self
73
+ end
74
+
75
+ def _deserialize(type, value)
76
+ case type.to_sym
77
+ when :DateTime
78
+ DateTime.parse(value)
79
+ when :Date
80
+ Date.parse(value)
81
+ when :String
82
+ value.to_s
83
+ when :Integer
84
+ value.to_i
85
+ when :Float
86
+ value.to_f
87
+ when :BOOLEAN
88
+ if value =~ /^(true|t|yes|y|1)$/i
89
+ true
90
+ else
91
+ false
92
+ end
93
+ when /\AArray<(?<inner_type>.+)>\z/
94
+ inner_type = Regexp.last_match[:inner_type]
95
+ value.map { |v| _deserialize(inner_type, v) }
96
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
97
+ k_type = Regexp.last_match[:k_type]
98
+ v_type = Regexp.last_match[:v_type]
99
+ {}.tap do |hash|
100
+ value.each do |k, v|
101
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
102
+ end
103
+ end
104
+ else # model
105
+ _model = Mpass.const_get(type).new
106
+ _model.build_from_hash(value)
107
+ end
108
+ end
109
+
110
+ def to_s
111
+ to_hash.to_s
112
+ end
113
+
114
+ # to_body is an alias to to_body (backward compatibility))
115
+ def to_body
116
+ to_hash
117
+ end
118
+
119
+ # return the object in the form of hash
120
+ def to_hash
121
+ hash = {}
122
+ self.class.attribute_map.each_pair do |attr, param|
123
+ value = self.send(attr)
124
+ next if value.nil?
125
+ hash[param] = _to_hash(value)
126
+ end
127
+ hash
128
+ end
129
+
130
+ # Method to output non-array value in the form of hash
131
+ # For object, use to_hash. Otherwise, just return the value
132
+ def _to_hash(value)
133
+ if value.is_a?(Array)
134
+ value.compact.map{ |v| _to_hash(v) }
135
+ elsif value.is_a?(Hash)
136
+ {}.tap do |hash|
137
+ value.each { |k, v| hash[k] = _to_hash(v) }
138
+ end
139
+ elsif value.respond_to? :to_hash
140
+ value.to_hash
141
+ else
142
+ value
143
+ end
144
+ end
145
+
146
+ private
147
+
148
+ def after_parse
149
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
150
+ end
151
+
152
+ end
153
+ end
@@ -0,0 +1,169 @@
1
+ require 'uri'
2
+
3
+ module MastercardCoreSdk
4
+
5
+ # Defines attributes for request token response.
6
+ class RequestTokenResponse
7
+
8
+ # @!attribute xoauth_request_auth_url
9
+ # @return [String]
10
+ attr_accessor :xoauth_request_auth_url
11
+
12
+ # @!attribute oauth_token
13
+ # @return [String]
14
+ attr_accessor :oauth_token
15
+
16
+ # @!attribute oauth_token_secret
17
+ # @return [String]
18
+ attr_accessor :oauth_token_secret
19
+
20
+ # @!attribute oauth_expires_in
21
+ # @return [Integer] no. of seconds after which oauth_token expires
22
+ attr_accessor :oauth_expires_in
23
+
24
+ # @!attribute oauth_callback_confirmed
25
+ # @return [Boolean]
26
+ attr_accessor :oauth_callback_confirmed
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :xoauth_request_auth_url => :XoauthRequestAuthUrl,
32
+ :oauth_token => :OauthToken,
33
+ :oauth_token_secret => :OauthTokenSecret,
34
+ :oauth_expires_in => :OauthExpiresIn,
35
+ :oauth_callback_confirmed => :OauthCallbackConfirmed
36
+ }
37
+ end
38
+
39
+ #Initializing object attributes with response parameters
40
+ def initialize(attributes = {})
41
+ return unless attributes.is_a?(Hash)
42
+ # convert string to symbol for hash key
43
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
44
+ self.class.datatype_map.each_pair do |key, type|
45
+ if attributes.has_key?(key)
46
+ send "#{key}=", (key.to_s == "xoauth_request_auth_url") ? URI.decode(_deserialize(type, attributes[key])) : _deserialize(type, attributes[key])
47
+ end
48
+ end
49
+ end
50
+
51
+ # Check equality by comparing each attribute.
52
+ def ==(o)
53
+ return true if self.equal?(o)
54
+ self.class == o.class &&
55
+ currency_code == o.currency_code &&
56
+ subtotal == o.subtotal &&
57
+ shopping_cart_item == o.shopping_cart_item &&
58
+ extension_point == o.extension_point
59
+ end
60
+
61
+ # @see the `==` method
62
+ def eql?(o)
63
+ self == o
64
+ end
65
+
66
+ # Calculate hash code according to all attributes.
67
+ def hash
68
+ [currency_code, subtotal, shopping_cart_item, extension_point].hash
69
+ end
70
+
71
+ # build the object from hash
72
+ def build_from_hash(attributes)
73
+ return nil unless attributes.is_a?(Hash)
74
+ self.class.datatype_map.each_pair do |key, type|
75
+ if type =~ /^Array<(.*)>/i
76
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
77
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
78
+ else
79
+ #TODO show warning in debug mode
80
+ end
81
+ elsif !attributes[self.class.attribute_map[key]].nil?
82
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
83
+ else
84
+ # data not found in attributes(hash), not an issue as the data can be optional
85
+ end
86
+ end
87
+ self
88
+ end
89
+
90
+ def _deserialize(type, value)
91
+ case type.to_sym
92
+ when :DateTime
93
+ DateTime.parse(value)
94
+ when :Date
95
+ Date.parse(value)
96
+ when :String
97
+ value.to_s
98
+ when :Integer
99
+ value.to_i
100
+ when :Float
101
+ value.to_f
102
+ when :BOOLEAN
103
+ !!(value.to_s =~ /^(true|t|yes|y|1)$/i)
104
+ when /\AArray<(?<inner_type>.+)>\z/
105
+ inner_type = Regexp.last_match[:inner_type]
106
+ value.map { |v| _deserialize(inner_type, v) }
107
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
108
+ k_type = Regexp.last_match[:k_type]
109
+ v_type = Regexp.last_match[:v_type]
110
+ {}.tap do |hash|
111
+ value.each do |k, v|
112
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
113
+ end
114
+ end
115
+ else # model
116
+ _model = MastercardCoreSdk.const_get(type).new
117
+ _model.build_from_hash(value)
118
+ end
119
+ end
120
+
121
+ def to_s
122
+ to_hash.to_s
123
+ end
124
+
125
+ # to_body is an alias to to_body (backward compatibility))
126
+ def to_body
127
+ to_hash
128
+ end
129
+
130
+ # return the object in the form of hash
131
+ def to_hash
132
+ hash = {}
133
+ self.class.attribute_map.each_pair do |attr, param|
134
+ value = self.send(attr)
135
+ next if value.nil?
136
+ hash[param] = _to_hash(value)
137
+ end
138
+ hash
139
+ end
140
+
141
+ # Method to output non-array value in the form of hash
142
+ # For object, use to_hash. Otherwise, just return the value
143
+ def _to_hash(value)
144
+ if value.is_a?(Array)
145
+ value.compact.map{ |v| _to_hash(v) }
146
+ elsif value.is_a?(Hash)
147
+ {}.tap do |hash|
148
+ value.each { |k, v| hash[k] = _to_hash(v) }
149
+ end
150
+ elsif value.respond_to? :to_hash
151
+ value.to_hash
152
+ else
153
+ value
154
+ end
155
+ end
156
+
157
+ private
158
+ # Attribute to datatype mapping.
159
+ def self.datatype_map
160
+ {
161
+ :xoauth_request_auth_url => 'String',
162
+ :oauth_token => 'String',
163
+ :oauth_token_secret => 'String',
164
+ :oauth_expires_in => 'Integer',
165
+ :oauth_callback_confirmed => 'BOOLEAN'
166
+ }
167
+ end
168
+ end
169
+ end