mastercard_core_sdk 1.1.3
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.
- checksums.yaml +7 -0
- data/LICENSE.txt +24 -0
- data/README.md +66 -0
- data/lib/mastercard_core_sdk/api/access_token_api.rb +31 -0
- data/lib/mastercard_core_sdk/api/request_token_api.rb +30 -0
- data/lib/mastercard_core_sdk/client/api_client.rb +192 -0
- data/lib/mastercard_core_sdk/constants/constants.rb +95 -0
- data/lib/mastercard_core_sdk/converters/encoded_url_converter.rb +55 -0
- data/lib/mastercard_core_sdk/converters/json_converter.rb +107 -0
- data/lib/mastercard_core_sdk/converters/sdk_converter_factory.rb +57 -0
- data/lib/mastercard_core_sdk/converters/xml_converter.rb +52 -0
- data/lib/mastercard_core_sdk/core/api_config.rb +18 -0
- data/lib/mastercard_core_sdk/core/api_config_builder.rb +48 -0
- data/lib/mastercard_core_sdk/core/configuration.rb +81 -0
- data/lib/mastercard_core_sdk/core/mastercard_api_configuration.rb +100 -0
- data/lib/mastercard_core_sdk/core/mastercard_authenticator.rb +25 -0
- data/lib/mastercard_core_sdk/core/query_params.rb +23 -0
- data/lib/mastercard_core_sdk/core/request_response_logger.rb +101 -0
- data/lib/mastercard_core_sdk/core/service_request.rb +24 -0
- data/lib/mastercard_core_sdk/exceptions/error_handler.rb +130 -0
- data/lib/mastercard_core_sdk/exceptions/sdk_base_error.rb +28 -0
- data/lib/mastercard_core_sdk/exceptions/sdk_conversion_error.rb +18 -0
- data/lib/mastercard_core_sdk/exceptions/sdk_oauth_error.rb +16 -0
- data/lib/mastercard_core_sdk/exceptions/sdk_response_error.rb +17 -0
- data/lib/mastercard_core_sdk/exceptions/sdk_validation_error.rb +16 -0
- data/lib/mastercard_core_sdk/interceptors/api_tracker_builder.rb +44 -0
- data/lib/mastercard_core_sdk/interceptors/logger_builder.rb +22 -0
- data/lib/mastercard_core_sdk/interceptors/signature_builder.rb +18 -0
- data/lib/mastercard_core_sdk/models/access_token_response.rb +150 -0
- data/lib/mastercard_core_sdk/models/detail.rb +165 -0
- data/lib/mastercard_core_sdk/models/details.rb +159 -0
- data/lib/mastercard_core_sdk/models/error.rb +212 -0
- data/lib/mastercard_core_sdk/models/error_response.rb +14 -0
- data/lib/mastercard_core_sdk/models/errors.rb +167 -0
- data/lib/mastercard_core_sdk/models/extension_point.rb +153 -0
- data/lib/mastercard_core_sdk/models/request_token_response.rb +169 -0
- data/lib/mastercard_core_sdk/oauth/oauth_parameters.rb +20 -0
- data/lib/mastercard_core_sdk/oauth/oauth_util.rb +205 -0
- data/lib/mastercard_core_sdk/tracker/api_tracker.rb +20 -0
- data/lib/mastercard_core_sdk/tracker/token_api_tracker.rb +52 -0
- data/lib/mastercard_core_sdk/version.rb +3 -0
- data/lib/mastercard_core_sdk.rb +65 -0
- metadata +208 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../exceptions/sdk_base_error'
|
2
|
+
|
3
|
+
module MastercardCoreSdk
|
4
|
+
module Exceptions
|
5
|
+
# Defines errors to be raised on validation failure.
|
6
|
+
class SDKValidationError < SDKBaseError
|
7
|
+
attr_accessor :error_message
|
8
|
+
|
9
|
+
def initialize(error_message)
|
10
|
+
@error_message = error_message
|
11
|
+
super(error_message)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'logging'
|
2
|
+
require_relative '../exceptions/sdk_validation_error'
|
3
|
+
|
4
|
+
module MastercardCoreSdk
|
5
|
+
module Interceptors
|
6
|
+
# Intercepts request for modifying headers for API calls tracking
|
7
|
+
class ApiTrackerBuilder
|
8
|
+
include MastercardCoreSdk::Core, MastercardCoreSdk::Exceptions
|
9
|
+
|
10
|
+
@@logger = Logging.logger[self]
|
11
|
+
def initialize(api_tracker, request)
|
12
|
+
@base_sdk_version = VERSION
|
13
|
+
@api_tracker = api_tracker
|
14
|
+
validate_tracker(request)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def validate_tracker(request)
|
20
|
+
if(@api_tracker)
|
21
|
+
if(!@api_tracker.tracking_info.empty? && !@api_tracker.user_agent_info.empty?)
|
22
|
+
build(request)
|
23
|
+
else
|
24
|
+
@@logger.error ERR_MSG_NULL_HEADER
|
25
|
+
raise SDKValidationError.new(ERR_MSG_NULL_HEADER)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
@@logger.error ERR_MSG_NULL_SERVICE
|
29
|
+
raise SDKValidationError.new(ERR_MSG_NULL_SERVICE)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Method to build API call tracking header
|
34
|
+
def build(request)
|
35
|
+
api_tracker_string = BASE_SDK_VERSION + @base_sdk_version + SEPERATOR
|
36
|
+
api_tracker_string += @api_tracker.tracking_info
|
37
|
+
|
38
|
+
request.options[:headers].merge!({ API_TRACKER_HEADER => api_tracker_string })
|
39
|
+
request.options[:headers].merge!({ USER_AGENT_HEADER => @api_tracker.user_agent_info })
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require_relative '../core/request_response_logger'
|
3
|
+
|
4
|
+
module MastercardCoreSdk
|
5
|
+
module Interceptors
|
6
|
+
# Interceptor to log request/response.
|
7
|
+
class LoggerBuilder
|
8
|
+
include MastercardCoreSdk::Core
|
9
|
+
|
10
|
+
# Interceptor for logging request and response
|
11
|
+
# @param request
|
12
|
+
# return [Typhoeus::Request]
|
13
|
+
def self.log(request)
|
14
|
+
RequestResponseLogger.log_request(request)
|
15
|
+
request.on_complete do |response|
|
16
|
+
RequestResponseLogger.log_response(response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../oauth/oauth_util'
|
2
|
+
|
3
|
+
module MastercardCoreSdk
|
4
|
+
module Interceptors
|
5
|
+
|
6
|
+
# Interceptor to add authorization OAuth signature to request header
|
7
|
+
class SignatureBuilder
|
8
|
+
include MastercardCoreSdk::OAuth
|
9
|
+
# Interceptor to add Authorization header to request
|
10
|
+
# @param request
|
11
|
+
def self.build(request)
|
12
|
+
request = OAuthUtil.build_request_header(request)
|
13
|
+
return request
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module MastercardCoreSdk
|
2
|
+
|
3
|
+
# Defines attributes for access token response.
|
4
|
+
class AccessTokenResponse
|
5
|
+
|
6
|
+
# @!attribute oauth_token_secret
|
7
|
+
# @return [String]
|
8
|
+
attr_accessor :oauth_token_secret
|
9
|
+
|
10
|
+
# @!attribute oauth_token
|
11
|
+
# @return [String]
|
12
|
+
attr_accessor :oauth_token
|
13
|
+
|
14
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
+
def self.attribute_map
|
16
|
+
{
|
17
|
+
:oauth_token => :OauthToken,
|
18
|
+
:oauth_token_secret => :OauthTokenSecret
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
#Initializing object attributes with response parameters
|
23
|
+
def initialize(attributes = {})
|
24
|
+
return unless attributes.is_a?(Hash)
|
25
|
+
# convert string to symbol for hash key
|
26
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
27
|
+
self.class.datatype_map.each_pair do |key, type|
|
28
|
+
if attributes.has_key?(key)
|
29
|
+
send "#{key}=", _deserialize(type, attributes[key])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Check equality by comparing each attribute.
|
35
|
+
def ==(o)
|
36
|
+
return true if self.equal?(o)
|
37
|
+
self.class == o.class &&
|
38
|
+
currency_code == o.currency_code &&
|
39
|
+
subtotal == o.subtotal &&
|
40
|
+
shopping_cart_item == o.shopping_cart_item &&
|
41
|
+
extension_point == o.extension_point
|
42
|
+
end
|
43
|
+
|
44
|
+
# @see the `==` method
|
45
|
+
def eql?(o)
|
46
|
+
self == o
|
47
|
+
end
|
48
|
+
|
49
|
+
# Calculate hash code according to all attributes.
|
50
|
+
def hash
|
51
|
+
[currency_code, subtotal, shopping_cart_item, extension_point].hash
|
52
|
+
end
|
53
|
+
|
54
|
+
# build the object from hash
|
55
|
+
def build_from_hash(attributes)
|
56
|
+
return nil unless attributes.is_a?(Hash)
|
57
|
+
self.class.datatype_map.each_pair do |key, type|
|
58
|
+
if type =~ /^Array<(.*)>/i
|
59
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
60
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
61
|
+
else
|
62
|
+
#TODO show warning in debug mode
|
63
|
+
end
|
64
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
65
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
66
|
+
else
|
67
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
68
|
+
end
|
69
|
+
end
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
def _deserialize(type, value)
|
74
|
+
case type.to_sym
|
75
|
+
when :DateTime
|
76
|
+
DateTime.parse(value)
|
77
|
+
when :Date
|
78
|
+
Date.parse(value)
|
79
|
+
when :String
|
80
|
+
value.to_s
|
81
|
+
when :Integer
|
82
|
+
value.to_i
|
83
|
+
when :Float
|
84
|
+
value.to_f
|
85
|
+
when :BOOLEAN
|
86
|
+
!!(value.to_s =~ /^(true|t|yes|y|1)$/i)
|
87
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
88
|
+
inner_type = Regexp.last_match[:inner_type]
|
89
|
+
value.map { |v| _deserialize(inner_type, v) }
|
90
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
91
|
+
k_type = Regexp.last_match[:k_type]
|
92
|
+
v_type = Regexp.last_match[:v_type]
|
93
|
+
{}.tap do |hash|
|
94
|
+
value.each do |k, v|
|
95
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
else # model
|
99
|
+
_model = MastercardCoreSdk.const_get(type).new
|
100
|
+
_model.build_from_hash(value)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
to_hash.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
# to_body is an alias to to_body (backward compatibility))
|
109
|
+
def to_body
|
110
|
+
to_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
# return the object in the form of hash
|
114
|
+
def to_hash
|
115
|
+
hash = {}
|
116
|
+
self.class.attribute_map.each_pair do |attr, param|
|
117
|
+
value = self.send(attr)
|
118
|
+
next if value.nil?
|
119
|
+
hash[param] = _to_hash(value)
|
120
|
+
end
|
121
|
+
hash
|
122
|
+
end
|
123
|
+
|
124
|
+
# Method to output non-array value in the form of hash
|
125
|
+
# For object, use to_hash. Otherwise, just return the value
|
126
|
+
def _to_hash(value)
|
127
|
+
if value.is_a?(Array)
|
128
|
+
value.compact.map{ |v| _to_hash(v) }
|
129
|
+
elsif value.is_a?(Hash)
|
130
|
+
{}.tap do |hash|
|
131
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
132
|
+
end
|
133
|
+
elsif value.respond_to? :to_hash
|
134
|
+
value.to_hash
|
135
|
+
else
|
136
|
+
value
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
# Attribute to datatype mapping.
|
142
|
+
def self.datatype_map
|
143
|
+
{
|
144
|
+
:oauth_token => 'String',
|
145
|
+
:oauth_token_secret => 'String'
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
module MastercardCoreSdk
|
5
|
+
# Defines attributes for error detail.
|
6
|
+
class Detail
|
7
|
+
include ROXML
|
8
|
+
|
9
|
+
xml_name "Detail"
|
10
|
+
|
11
|
+
# @!attribute name
|
12
|
+
# @return [String] the error detail name.
|
13
|
+
xml_accessor :name, :from => "Name"
|
14
|
+
|
15
|
+
# @!attribute value
|
16
|
+
# @return [String] the error detail name.
|
17
|
+
xml_accessor :value, :from => "Value"
|
18
|
+
|
19
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
20
|
+
def self.attribute_map
|
21
|
+
{
|
22
|
+
:'name' => :'Name',
|
23
|
+
:'value' => :'Value'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Attribute type mapping.
|
28
|
+
def self.swagger_types
|
29
|
+
{
|
30
|
+
:'name' => :'String',
|
31
|
+
:'value' => :'String'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(attributes = {})
|
36
|
+
return unless attributes.is_a?(Hash)
|
37
|
+
|
38
|
+
# convert string to symbol for hash key
|
39
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
40
|
+
|
41
|
+
if attributes.has_key?(:Name) || attributes.has_key?(:name)
|
42
|
+
self.name = attributes[:Name] || attributes[:name]
|
43
|
+
end
|
44
|
+
|
45
|
+
if attributes.has_key?(:Value) || attributes.has_key?(:value)
|
46
|
+
self.value = attributes[:Value] || attributes[:value]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Check equality by comparing each attribute.
|
51
|
+
def ==(o)
|
52
|
+
return true if self.equal?(o)
|
53
|
+
self.class == o.class &&
|
54
|
+
name == o.name &&
|
55
|
+
value == o.value
|
56
|
+
end
|
57
|
+
|
58
|
+
# @see the `==` method
|
59
|
+
def eql?(o)
|
60
|
+
self == o
|
61
|
+
end
|
62
|
+
|
63
|
+
# Calculate hash code according to all attributes.
|
64
|
+
def hash
|
65
|
+
[name, value].hash
|
66
|
+
end
|
67
|
+
|
68
|
+
# build the object from hash
|
69
|
+
def build_from_hash(attributes)
|
70
|
+
return nil unless attributes.is_a?(Hash)
|
71
|
+
self.class.swagger_types.each_pair do |key, type|
|
72
|
+
if type =~ /^Array<(.*)>/i
|
73
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
74
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
75
|
+
else
|
76
|
+
#TODO show warning in debug mode
|
77
|
+
end
|
78
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
79
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
80
|
+
else
|
81
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def _deserialize(type, value)
|
89
|
+
case type.to_sym
|
90
|
+
when :DateTime
|
91
|
+
DateTime.parse(value)
|
92
|
+
when :Date
|
93
|
+
Date.parse(value)
|
94
|
+
when :String
|
95
|
+
value.to_s
|
96
|
+
when :Integer
|
97
|
+
value.to_i
|
98
|
+
when :Float
|
99
|
+
value.to_f
|
100
|
+
when :BOOLEAN
|
101
|
+
if value =~ /^(true|t|yes|y|1)$/i
|
102
|
+
true
|
103
|
+
else
|
104
|
+
false
|
105
|
+
end
|
106
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
107
|
+
inner_type = Regexp.last_match[:inner_type]
|
108
|
+
value.map { |v| _deserialize(inner_type, v) }
|
109
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
110
|
+
k_type = Regexp.last_match[:k_type]
|
111
|
+
v_type = Regexp.last_match[:v_type]
|
112
|
+
{}.tap do |hash|
|
113
|
+
value.each do |k, v|
|
114
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
else # model
|
118
|
+
_model = MastercardCoreSdk.const_get(type).new
|
119
|
+
_model.build_from_hash(value)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_s
|
124
|
+
to_hash.to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
# to_body is an alias to to_body (backward compatibility))
|
128
|
+
def to_body
|
129
|
+
to_hash
|
130
|
+
end
|
131
|
+
|
132
|
+
# return the object in the form of hash
|
133
|
+
def to_hash
|
134
|
+
hash = {}
|
135
|
+
self.class.attribute_map.each_pair do |attr, param|
|
136
|
+
value = self.send(attr)
|
137
|
+
next if value.nil?
|
138
|
+
hash[param] = _to_hash(value)
|
139
|
+
end
|
140
|
+
hash
|
141
|
+
end
|
142
|
+
|
143
|
+
# Method to output non-array value in the form of hash
|
144
|
+
# For object, use to_hash. Otherwise, just return the value
|
145
|
+
def _to_hash(value)
|
146
|
+
if value.is_a?(Array)
|
147
|
+
value.compact.map{ |v| _to_hash(v) }
|
148
|
+
elsif value.is_a?(Hash)
|
149
|
+
{}.tap do |hash|
|
150
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
151
|
+
end
|
152
|
+
elsif value.respond_to? :to_hash
|
153
|
+
value.to_hash
|
154
|
+
else
|
155
|
+
value
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def after_parse
|
162
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'roxml'
|
3
|
+
|
4
|
+
require_relative '../models/detail'
|
5
|
+
|
6
|
+
module MastercardCoreSdk
|
7
|
+
# Defines attributes for error details.
|
8
|
+
class Details
|
9
|
+
include ROXML
|
10
|
+
|
11
|
+
xml_name "Details"
|
12
|
+
|
13
|
+
# @!attribute detail
|
14
|
+
# @return [Array<Detail>] the error detail.
|
15
|
+
xml_accessor :detail, :from => "Detail", :as =>[Detail]
|
16
|
+
|
17
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
18
|
+
def self.attribute_map
|
19
|
+
{
|
20
|
+
:'detail' => :'Detail'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Attribute type mapping.
|
25
|
+
def self.swagger_types
|
26
|
+
{
|
27
|
+
:'detail' => :'Array<Detail>'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(attributes = {})
|
32
|
+
return unless attributes.is_a?(Hash)
|
33
|
+
|
34
|
+
# convert string to symbol for hash key
|
35
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
36
|
+
|
37
|
+
if attributes.has_key?(:Detail) || attributes.has_key?(:detail)
|
38
|
+
if (value = attributes[:Detail] || attributes[:detail]).is_a?(Array)
|
39
|
+
self.detail = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Check equality by comparing each attribute.
|
45
|
+
def ==(o)
|
46
|
+
return true if self.equal?(o)
|
47
|
+
self.class == o.class &&
|
48
|
+
detail == o.detail
|
49
|
+
end
|
50
|
+
|
51
|
+
# @see the `==` method
|
52
|
+
def eql?(o)
|
53
|
+
self == o
|
54
|
+
end
|
55
|
+
|
56
|
+
# Calculate hash code according to all attributes.
|
57
|
+
def hash
|
58
|
+
[detail].hash
|
59
|
+
end
|
60
|
+
|
61
|
+
# build the object from hash
|
62
|
+
def build_from_hash(attributes)
|
63
|
+
return nil unless attributes.is_a?(Hash)
|
64
|
+
self.class.swagger_types.each_pair do |key, type|
|
65
|
+
if type =~ /^Array<(.*)>/i
|
66
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
67
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
68
|
+
else
|
69
|
+
#TODO show warning in debug mode
|
70
|
+
end
|
71
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
72
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
73
|
+
else
|
74
|
+
# data not found in attributes(hash), not an issue as the data can be optional
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
def _deserialize(type, value)
|
82
|
+
case type.to_sym
|
83
|
+
when :DateTime
|
84
|
+
DateTime.parse(value)
|
85
|
+
when :Date
|
86
|
+
Date.parse(value)
|
87
|
+
when :String
|
88
|
+
value.to_s
|
89
|
+
when :Integer
|
90
|
+
value.to_i
|
91
|
+
when :Float
|
92
|
+
value.to_f
|
93
|
+
when :BOOLEAN
|
94
|
+
if value =~ /^(true|t|yes|y|1)$/i
|
95
|
+
true
|
96
|
+
else
|
97
|
+
false
|
98
|
+
end
|
99
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
100
|
+
inner_type = Regexp.last_match[:inner_type]
|
101
|
+
value.map { |v| _deserialize(inner_type, v) }
|
102
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
103
|
+
k_type = Regexp.last_match[:k_type]
|
104
|
+
v_type = Regexp.last_match[:v_type]
|
105
|
+
{}.tap do |hash|
|
106
|
+
value.each do |k, v|
|
107
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
else # model
|
111
|
+
_model = Mpass.const_get(type).new
|
112
|
+
_model.build_from_hash(value)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_s
|
117
|
+
to_hash.to_s
|
118
|
+
end
|
119
|
+
|
120
|
+
# to_body is an alias to to_body (backward compatibility))
|
121
|
+
def to_body
|
122
|
+
to_hash
|
123
|
+
end
|
124
|
+
|
125
|
+
# return the object in the form of hash
|
126
|
+
def to_hash
|
127
|
+
hash = {}
|
128
|
+
self.class.attribute_map.each_pair do |attr, param|
|
129
|
+
value = self.send(attr)
|
130
|
+
next if value.nil?
|
131
|
+
hash[param] = _to_hash(value)
|
132
|
+
end
|
133
|
+
hash
|
134
|
+
end
|
135
|
+
|
136
|
+
# Method to output non-array value in the form of hash
|
137
|
+
# For object, use to_hash. Otherwise, just return the value
|
138
|
+
def _to_hash(value)
|
139
|
+
if value.is_a?(Array)
|
140
|
+
value.compact.map{ |v| _to_hash(v) }
|
141
|
+
elsif value.is_a?(Hash)
|
142
|
+
{}.tap do |hash|
|
143
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
144
|
+
end
|
145
|
+
elsif value.respond_to? :to_hash
|
146
|
+
value.to_hash
|
147
|
+
else
|
148
|
+
value
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def after_parse
|
155
|
+
self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|