mastercard_api_core 1.4.6 → 1.4.7

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: 1c81e9e0b949bc4849f068a97925747473497cc7
4
- data.tar.gz: 92b0018476825ea191e14cec91396c3e113f640a
3
+ metadata.gz: 296da60bdee286979c6ca87713a51d0948f8f076
4
+ data.tar.gz: c2c7df86096d2ea0e8b7caf525f745864b1924c5
5
5
  SHA512:
6
- metadata.gz: 8ff1f3ed215d237fc2a21088f98bb56bf4b7915089b05bcabb93a8cae85eabf31ad71d46347f6c72a113707a40332a7d2352ebb796d1bcc5579981f370e47ac9
7
- data.tar.gz: 63436f4dba15ffa787b997d9e102c57d39c97f8f3f66c6e1222765f6585c4deac0b0f132655013a93f4f5e527e91c1c08760f50a590e5e0ab7b74c027430b4d8
6
+ metadata.gz: 3818063fe52ea1acd907190a5b5661984de49fa75d1e7839463ba6e5710ab71e825617dcc61a666abf9792296a00dafa8e02eb2d2e688ab2296b3c3973c79160
7
+ data.tar.gz: b0f2e048f0fcb5676f559f1784d866651762e57da000d3a900eeb61081e8c3f65a03ae0dce3b5606bf033b33a4832763d1dccc7184b107c320908aa66aac4641
@@ -36,6 +36,12 @@ module MasterCard
36
36
  @@authentication = nil;
37
37
  @@registeredInstances = {}
38
38
 
39
+ @@proxy = nil
40
+ @@connection_timeout = 5
41
+ @@read_timeout = 30
42
+
43
+
44
+
39
45
  public
40
46
  def self.setDebug(debug)
41
47
  @@debug = debug
@@ -58,6 +64,43 @@ module MasterCard
58
64
  return @@environment == Environment::SANDBOX
59
65
  end
60
66
 
67
+ def self.setProxy(proxy)
68
+ if (proxy.nil? == false)
69
+ @@proxy = proxy
70
+ else
71
+ @@proxy = nil
72
+ end
73
+ end
74
+
75
+ def self.getProxy()
76
+ return @@proxy
77
+ end
78
+
79
+
80
+ def self.setConnectionTimeout(timeout)
81
+ if (timeout.nil? == false && timeout.is_a?(Numeric))
82
+ @@connection_timeout = timeout
83
+ else
84
+ @@connection_timeout = 5
85
+ end
86
+ end
87
+
88
+
89
+ def self.setReadTimeout(timeout)
90
+ if (timeout.nil? == false && timeout.is_a?(Numeric))
91
+ @@read_timeout = timeout
92
+ else
93
+ @@read_timeout = 30
94
+ end
95
+ end
96
+
97
+ def self.getConnectionTimeout()
98
+ return @@connection_timeout
99
+ end
100
+
101
+ def self.getReadTimeout()
102
+ return @@read_timeout
103
+ end
61
104
 
62
105
  def self.getEnvironment
63
106
  return @@environment
@@ -24,11 +24,19 @@
24
24
  # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
25
  # SUCH DAMAGE.
26
26
  #
27
+
28
+
29
+
27
30
  module MasterCard
28
31
  module Core
29
- module Constants
30
- API_BASE_LIVE_URL = "https://api.mastercard.com"
31
- API_BASE_SANDBOX_URL = "https://sandbox.api.mastercard.com"
32
+ module Constants
33
+ spec = Gem::Specification::load(File.join( File.dirname(__FILE__), '../../../mastercard_api_core.gemspec' ))
34
+ SDK = "mastercard_api_core(ruby)"
35
+ VERSION = spec.version.to_s()
36
+
37
+ def self.getCoreVersion
38
+ return SDK+":"+VERSION
39
+ end
32
40
  end
33
41
 
34
42
  module Environment
@@ -36,6 +36,7 @@ module MasterCard
36
36
  module Controller
37
37
  class APIController
38
38
  include MasterCard::Core
39
+ include MasterCard::Core::Constants
39
40
  include MasterCard::Core::Exceptions
40
41
  include MasterCard::Security
41
42
 
@@ -51,8 +52,7 @@ module MasterCard
51
52
  KEY_ACCEPT = "Accept"
52
53
  KEY_USER_AGENT = "User-Agent"
53
54
  KEY_CONTENT_TYPE = "Content-Type"
54
- APPLICATION_JSON = "application/json"
55
- RUBY_SDK = "Ruby_SDK"
55
+ APPLICATION_JSON = "application/json; charset=UTF-8"
56
56
  JSON_STR = "JSON"
57
57
 
58
58
 
@@ -155,26 +155,36 @@ module MasterCard
155
155
  return body
156
156
  end
157
157
 
158
- def getPathParams(action,queryParams,input)
158
+ def getQueryParams(action,queryParams,isJsonNative,input)
159
159
  #Returns the path params based on action
160
- pathParams = {KEY_FORMAT => JSON_STR}
160
+ params = {}
161
+ if isJsonNative == false
162
+ params = {KEY_FORMAT => JSON_STR}
163
+ end
164
+
161
165
  case action.upcase
162
166
  when ACTION_LIST, ACTION_READ, ACTION_QUERY, ACTION_DELETE
163
167
  unless input.nil?
164
- pathParams = pathParams.merge(input)
168
+ params = params.merge(input)
165
169
  end
166
170
  end
167
171
 
168
172
  #merge the queryParams
169
- pathParams = pathParams.merge(queryParams)
173
+ params = params.merge(queryParams)
170
174
 
171
- return pathParams
175
+ return params
172
176
  end
173
177
 
174
178
  def getHTTPObject(uri)
179
+
180
+ proxy = Config.getProxy()
181
+ proxyHost = proxy.nil? == false ? proxy.key?(:host) ? proxy[:host] : nil : nil
182
+ proxyPort = proxy.nil? == false ? proxy.key?(:port) ? proxy[:port] : nil : nil
175
183
 
176
184
  #Returns the HTTP Object
177
- http = Net::HTTP.new(uri.host,uri.port)
185
+ http = Net::HTTP.new(uri.host,uri.port, proxyHost, proxyPort)
186
+ http.read_timeout = Config.getReadTimeout()
187
+ http.open_timeout = Config.getConnectionTimeout()
178
188
 
179
189
  if uri.scheme == "https"
180
190
  http.use_ssl = true
@@ -184,7 +194,7 @@ module MasterCard
184
194
 
185
195
  end
186
196
 
187
- def encode_path_params(path, params)
197
+ def encode_query_params(path, params)
188
198
  #Encode and join the params
189
199
  encoded = URI.encode_www_form(params)
190
200
  [path, encoded].join("?")
@@ -217,16 +227,18 @@ module MasterCard
217
227
 
218
228
  fullUrl = resolvedHost + resourcePath
219
229
 
220
- #Get the resourcePath containing values from input
230
+ #Get the resourcePath containing path parameters
221
231
  fullUrl = getFullResourcePath(config.getAction(),fullUrl,input)
222
232
 
223
233
  #Get the path parameters
224
- pathParams = getPathParams(config.getAction(),queryParams,input)
234
+ params = getQueryParams(config.getAction(),queryParams,metadata.isJsonNative(),input)
225
235
  #Get the body
226
236
  body = getBody(config.getAction(),input)
227
237
 
228
238
  #add url parameters to path
229
- fullUrl = encode_path_params(fullUrl,pathParams)
239
+ if params.any?
240
+ fullUrl = encode_query_params(fullUrl,params)
241
+ end
230
242
 
231
243
  uri = URI(fullUrl)
232
244
 
@@ -250,13 +262,12 @@ module MasterCard
250
262
 
251
263
 
252
264
  #Add default headers
253
- request.add_field(KEY_ACCEPT,APPLICATION_JSON)
254
- request.add_field(KEY_CONTENT_TYPE,APPLICATION_JSON)
255
- request.add_field(KEY_USER_AGENT,RUBY_SDK+"/"+metadata.getVersion())
265
+ request[KEY_ACCEPT] = APPLICATION_JSON
266
+ request[KEY_USER_AGENT] =Constants::getCoreVersion()+"/"+metadata.getVersion()
256
267
 
257
268
  #Add body
258
-
259
269
  unless body.nil?
270
+ request[KEY_CONTENT_TYPE] = APPLICATION_JSON
260
271
  request.body = body.to_json
261
272
  end
262
273
 
@@ -266,7 +277,7 @@ module MasterCard
266
277
  end
267
278
 
268
279
  #Sign and get back the request
269
- request = Config.getAuthentication().signRequest(fullUrl,request,request.method,body,pathParams)
280
+ request = Config.getAuthentication().signRequest(request,params)
270
281
 
271
282
  return request
272
283
 
@@ -337,6 +337,75 @@ module MasterCard
337
337
 
338
338
 
339
339
 
340
+ end
341
+
342
+ ################################################################################
343
+ # CaseInsensitiveMap
344
+ ################################################################################
345
+
346
+ class CaseInsensitiveMap < SmartMap
347
+ def initialize
348
+ #call the base class constructor
349
+ super()
350
+ end
351
+
352
+ def containsKeys(key)
353
+ return super(key.to_s.downcase)
354
+ end
355
+
356
+ def get(key)
357
+ return super(key.to_s.downcase)
358
+ end
359
+
360
+ def set(key,value)
361
+ super(key.to_s.downcase, value)
362
+ end
363
+
364
+ def setAll(map)
365
+ properties = parseMap(map)
366
+ super(map)
367
+ end
368
+
369
+ private
370
+ def parseMap(map)
371
+ parsedMap = {}
372
+ map.each do |k, v|
373
+ if v.is_a?(Array)
374
+ parsedMap[k.to_s.downcase] = parseList(v)
375
+ elsif v.is_a?(Hash)
376
+ parsedMap[k.to_s.downcase] = parseMap(v)
377
+ else
378
+ parsedMap[k.to_s.downcase] = v
379
+ end
380
+ end
381
+ return parsedMap
382
+ end
383
+
384
+ def parseList(list)
385
+ parsedList = []
386
+ list.each do |v|
387
+ if v.is_a?(Array)
388
+ parsedList << parseList(v)
389
+ elsif v.is_a?(Hash)
390
+ parsedList << parseMap(v)
391
+ else
392
+ parsedList << v
393
+ end
394
+ end
395
+ return parsedList
396
+ end
397
+
398
+ end
399
+
400
+ ################################################################################
401
+ # RequestMap
402
+ ################################################################################
403
+
404
+ class RequestMap < SmartMap
405
+ def initialize
406
+ #call the base class constructor
407
+ super()
408
+ end
340
409
  end
341
410
 
342
411
  ################################################################################
@@ -345,10 +414,11 @@ module MasterCard
345
414
 
346
415
  class OperationMetadata
347
416
 
348
- def initialize(version, host, context = nil)
417
+ def initialize(version, host, context = nil, jsonNative = false)
349
418
  @version = version
350
419
  @host = host
351
420
  @context = context
421
+ @jsonNative = jsonNative
352
422
  end
353
423
 
354
424
  def getVersion()
@@ -362,6 +432,10 @@ module MasterCard
362
432
  def getContext()
363
433
  return @context
364
434
  end
435
+
436
+ def isJsonNative()
437
+ return @jsonNative
438
+ end
365
439
 
366
440
  end
367
441
 
@@ -397,16 +471,7 @@ module MasterCard
397
471
 
398
472
  end
399
473
 
400
- ################################################################################
401
- # RequestMap
402
- ################################################################################
403
474
 
404
- class RequestMap < SmartMap
405
- def initialize
406
- #call the base class constructor
407
- super()
408
- end
409
- end
410
475
 
411
476
 
412
477
 
@@ -28,7 +28,7 @@ module MasterCard
28
28
  module Security
29
29
  class Authentication
30
30
 
31
- def signRequest(uri,request)
31
+ def signRequest(request,params)
32
32
  raise NotImplementedError.new("This method should be overridden by the class")
33
33
  end
34
34
  end
@@ -62,20 +62,13 @@ module MasterCard
62
62
  oAuthParameters.setOAuthSignatureMethod("RSA-SHA256")
63
63
  oAuthParameters.setOAuthVersion("1.0")
64
64
 
65
- if body.nil?
66
- body = ""
65
+ unless body.nil?
66
+ encodedHash = sha256Base64Encode(body)
67
+ oAuthParameters.setOAuthBodyHash(encodedHash)
67
68
  end
68
69
 
69
- begin
70
- body = body.to_json
71
- rescue
72
- #Do nothing and hope for the best
73
- end
74
-
75
- encodedHash = sha256Base64Encode(body)
76
- oAuthParameters.setOAuthBodyHash(encodedHash)
77
-
78
70
  return oAuthParameters
71
+
79
72
  end
80
73
 
81
74
  def getBaseString(url,method,params,oAuthParams)
@@ -94,9 +87,9 @@ module MasterCard
94
87
  end
95
88
 
96
89
 
97
- def signRequest(url,request,method,data,params)
90
+ def signRequest(request,params)
98
91
 
99
- oauth_key = getOAuthKey(url,method,data,params)
92
+ oauth_key = getOAuthKey(request.uri.to_s,request.method,request.body,params)
100
93
  request.add_field(OAuthParameters::AUTHORIZATION,oauth_key)
101
94
  return request
102
95
 
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-#
2
+ # Copyright (c) 2016 MasterCard International Incorporated
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification, are
6
+ # permitted provided that the following conditions are met:
7
+ #
8
+ # Redistributions of source code must retain the above copyright notice, this list of
9
+ # conditions and the following disclaimer.
10
+ # Redistributions in binary form must reproduce the above copyright notice, this list of
11
+ # conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ # Neither the name of the MasterCard International Incorporated nor the names of its
14
+ # contributors may be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
+ # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19
+ # SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ # SUCH DAMAGE.
26
+ #
27
+ Gem::Specification.new do |gem|
28
+ gem.name = "mastercard_api_core"
29
+ gem.authors = ["MasterCard Worldwide"]
30
+ gem.email = ["APISupport@mastercard.com"]
31
+ gem.summary = %q{MasterCard core SDK}
32
+ gem.description = %q{This is the MasterCard OpenAPI core SDK. This provides the base functionality for all MasterCard APIs}
33
+ gem.homepage = "https://developer.mastercard.com"
34
+ gem.version = "1.4.7"
35
+ gem.license = "BSD-2-Clause"
36
+
37
+ gem.files = Dir["{bin,spec,lib}/**/*"]+ Dir["data/*"] + ["mastercard_api_core.gemspec"]
38
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
39
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
40
+ gem.require_paths = ["lib"]
41
+ gem.add_development_dependency 'simplecov', '~> 0'
42
+ gem.add_development_dependency 'ci_reporter_minitest', '~> 0'
43
+ end
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.6
4
+ version: 1.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - MasterCard Worldwide
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -57,6 +57,7 @@ files:
57
57
  - lib/mastercard/security/oauth.rb
58
58
  - lib/mastercard/security/util.rb
59
59
  - lib/mastercard_api_core.rb
60
+ - mastercard_api_core.gemspec
60
61
  homepage: https://developer.mastercard.com
61
62
  licenses:
62
63
  - BSD-2-Clause