mastercard_api_core 1.4.9 → 1.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d555cebaef1f94a88fa6df626a6dbcca63983c0c
4
- data.tar.gz: 71d691fc5a87c36f577e82f529c287a6b05e5d65
3
+ metadata.gz: ba4ef82e5a66548c284157b22017c5f57603c58c
4
+ data.tar.gz: 45f5a2e615b2f625fe939f08eb8325e042df329d
5
5
  SHA512:
6
- metadata.gz: 0748beead2212ef88e95ebe497c11cfa67a5c618a5c197cc51984f913fdfc6bb92a3d4f2e0b6fdb94f36e4d59c1ddee5a555bbfd9669f589708b9bd260b0b020
7
- data.tar.gz: 50af187dca0729cd4503f2b487b71340084a11be6669c768b89f2100e7e9e7715c0daa6ad16d0c43bd90e884f138dee96efbd41153940f0a6852c29328f4f944
6
+ metadata.gz: f9a69507894185d86619736e7a9aadf93a7090a59440e9614ee0aae8f1701fbd4653588a3a158483ee333e974c55d4ea710176b00765714a63dae3a1d37ca34a
7
+ data.tar.gz: 0bc2fff8981a2dd327abcb30934d6707180b34df15374eb011286b8595448942865026b01010ea81569a9dcfd1b44aab4b34f2aff86be7e690a67af16de7a0e5
@@ -36,6 +36,8 @@ module MasterCard
36
36
  ################################################################################
37
37
  class APIException < StandardError
38
38
  include MasterCard::Core::Model
39
+
40
+ @@mapping = {100 => "Continue", 101 => "Switching Protocols", 102 => "Processing", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information", 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 207 => "Multi-Status", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 306 => "(Unused)", 307 => "Temporary Redirect", 308 => "Permanent Redirect", 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 407 => "Proxy Authentication Required", 408 => "Request Timeout", 409 => "Conflict", 410 => "Gone", 411 => "Length Required", 412 => "Precondition Failed", 413 => "Request Entity Too Large", 414 => "Request-URI Too Long", 415 => "Unsupported Media Type", 416 => "Requested Range Not Satisfiable", 417 => "Expectation Failed", 418 => "I'm a teapot", 419 => "Authentication Timeout", 420 => "Enhance Your Calm", 422 => "Unprocessable Entity", 423 => "Locked", 424 => "Failed Dependency", 425 => "Unordered Collection", 426 => "Upgrade Required", 428 => "Precondition Required", 429 => "Too Many Requests", 431 => "Request Header Fields Too Large", 444 => "No Response", 449 => "Retry With", 450 => "Blocked by Windows Parental Controls", 451 => "Unavailable For Legal Reasons", 494 => "Request Header Too Large", 495 => "Cert Error", 496 => "No Cert", 497 => "HTTP to HTTPS", 499 => "Client Closed Request", 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported", 506 => "Variant Also Negotiates", 507 => "Insufficient Storage", 508 => "Loop Detected", 509 => "Bandwidth Limit Exceeded", 510 => "Not Extended", 511 => "Network Authentication Required", 598 => "Network read timeout error", 599 => "Network connect timeout error"}
39
41
  #
40
42
  # Base Class for all the API exceptions
41
43
  def initialize(message,http_status=nil, error_data=nil)
@@ -44,44 +46,42 @@ module MasterCard
44
46
 
45
47
  @message = message
46
48
  @http_status = http_status
47
- @raw_error_data = error_data
49
+ @message = message
50
+ unless http_status.nil?
51
+ @message = @@mapping[http_status]
52
+ end
53
+
54
+ @message = message
55
+
56
+ @description = nil
48
57
  @reason_code = nil
49
58
  @source = nil
50
- @description = nil
51
-
52
- #If error_data is not nil set the appropriate message
53
- unless error_data.nil?
54
59
 
55
- @raw_error_data = SmartMap.new
56
- @raw_error_data.setAll(error_data);
60
+ @raw_error_data = nil
61
+ @error = nil
62
+ @errors = []
57
63
 
58
- error_data_case_insensitive = parseMap(error_data)
59
-
60
- # If error_data is of type hash and has Key 'Errors' which has a key 'Error'
61
- if error_data_case_insensitive.key?("errors")
64
+
65
+ parseRawErrorData(error_data)
66
+ parseErrors(error_data)
67
+ parseError(0)
68
+ end
69
+
62
70
 
63
- error_hash = error_data_case_insensitive["errors"]
64
- if (error_hash.is_a?(Hash) && error_hash.key?("error"))
65
- error_hash = error_hash["error"]
66
- end
67
-
68
- if error_hash.is_a?(Array)
69
- error_hash = error_hash[0]
70
- end
71
71
 
72
+ def parseError(index)
73
+ if @errors.any? && index >= 0 && index < getErrorSize()
74
+ @error = @errors[index]
75
+ parseErrorFromMap()
76
+ end
77
+ end
72
78
 
73
- #Case of multiple errors take the first one
74
- if error_hash.is_a?(Hash)
75
- initDataFromHash(error_hash)
79
+ def getError()
80
+ return @error
81
+ end
76
82
 
77
- #If error Data is of Type Array
78
- elsif error_hash.is_a?(Array)
79
- #Take the first error
80
- error_hash = error_hash[0]
81
- initDataFromHash(error_hash)
82
- end
83
- end
84
- end
83
+ def getErrorSize()
84
+ return @errors.size
85
85
  end
86
86
 
87
87
  def getMessage()
@@ -129,40 +129,71 @@ module MasterCard
129
129
 
130
130
  private
131
131
 
132
- def initDataFromHash(error_hash)
133
- @reason_code = error_hash.fetch("reasoncode",nil)
134
- @description = error_hash.fetch("description",@message)
135
- @source = error_hash.fetch("source",nil)
132
+ def parseErrorFromMap()
133
+ if @error.containsKeys("reasoncode")
134
+ @reason_code = @error.get("reasoncode")
135
+ end
136
+ if @error.containsKeys("description")
137
+ @description = @error.get("description")
138
+ end
139
+ if @error.containsKeys("source")
140
+ @source = @error.get("source")
141
+ end
142
+
136
143
  end
137
144
 
138
- def parseMap(map)
139
- parsedMap = {}
140
- map.each do |k, v|
141
- if v.is_a?(Array)
142
- parsedMap[k.to_s.downcase] = parseList(v)
143
- elsif v.is_a?(Hash)
144
- parsedMap[k.to_s.downcase] = parseMap(v)
145
- else
146
- parsedMap[k.to_s.downcase] = v
145
+ def parseRawErrorData(error_data)
146
+ unless error_data.nil?
147
+ if error_data.is_a?(::Array) && error_data.size > 0
148
+ smartMap = CaseInsensitiveMap.new
149
+ smartMap.setAll(error_data[0]);
150
+ @raw_error_data = smartMap;
151
+ elsif error_data.is_a?(::Hash)
152
+ smartMap = CaseInsensitiveMap.new
153
+ smartMap.setAll(error_data);
154
+ @raw_error_data = smartMap;
147
155
  end
148
156
  end
149
- return parsedMap
150
157
  end
151
158
 
152
- def parseList(l)
153
- parsedList = []
154
- l.each do |v|
155
- if v.is_a?(Array)
156
- parsedList << parseList(v)
157
- elsif v.is_a?(Hash)
158
- parsedList << parseMap(v)
159
- else
160
- parsedList << v
159
+ def parseErrors(error_data)
160
+ unless error_data.nil?
161
+ errors = []
162
+ if error_data.is_a?(::Array) && error_data.size > 0
163
+ errors = (errors << error_data).flatten
164
+ elsif error_data.is_a?(::Hash)
165
+ errors << error_data
166
+ end
167
+
168
+ errors.each do |error|
169
+ smartMap = CaseInsensitiveMap.new
170
+ smartMap.setAll(error);
171
+ if smartMap.containsKeys("errors.error.reasoncode")
172
+ addErrors(smartMap.get("errors.error"))
173
+ elsif smartMap.containsKeys("errors.error[0].reasoncode")
174
+ addErrors(smartMap.get("errors.error"))
175
+ elsif smartMap.containsKeys("errors[0].reasoncode")
176
+ addErrors(smartMap.get("errors"))
177
+ elsif smartMap.containsKeys("reasoncode")
178
+ addErrors(smartMap.getObject())
179
+ end
161
180
  end
162
181
  end
163
- return parsedList
164
182
  end
165
183
 
184
+ def addErrors(error)
185
+ if error.is_a?(::Array)
186
+ error.each do |item|
187
+ smartMap = CaseInsensitiveMap.new
188
+ smartMap.setAll(item);
189
+ @errors << smartMap
190
+ end
191
+ elsif error.is_a?(::Hash)
192
+ smartMap = CaseInsensitiveMap.new
193
+ smartMap.setAll(error)
194
+ @errors << smartMap
195
+ end
196
+ end
166
197
  end
167
198
  end
168
199
  end
@@ -31,7 +31,7 @@ Gem::Specification.new do |gem|
31
31
  gem.summary = %q{MasterCard core SDK}
32
32
  gem.description = %q{This is the MasterCard OpenAPI core SDK. This provides the base functionality for all MasterCard APIs}
33
33
  gem.homepage = "https://developer.mastercard.com"
34
- gem.version = "1.4.9"
34
+ gem.version = "1.4.10"
35
35
  gem.license = "BSD-2-Clause"
36
36
 
37
37
  gem.files = Dir["{bin,spec,lib}/**/*"]+ Dir["data/*"] + ["mastercard_api_core.gemspec"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastercard_api_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - MasterCard Worldwide
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov