mastercard_api_core 1.1.0 → 1.2.0

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: c4b966df966d30e4f49eae6cf492856a4e90dd81
4
- data.tar.gz: ca58164761fc78ebe20ab58cf22fba834461e619
3
+ metadata.gz: f5f763aebe0c1c4a9a63b42140714f3855315cb2
4
+ data.tar.gz: 5052018374598d3ce2f0e696db496582fb4d7371
5
5
  SHA512:
6
- metadata.gz: 66b6ae06797faaefe099d07a4e7784e51adc81267c43a4123489c9a38abda57ee2112fcd157c77f9845db7248d7eb9cc7219a1fad28006557a254391b5feedb3
7
- data.tar.gz: 5bc5ebb68ae3752c945f05821eda32a7257bf0b68a1c0aea86b46ff0ca8a83bad5a785399df594251f38e7d3af49a6c6933761191e089e99cf2c48168c6765da
6
+ metadata.gz: d69f38d00443e4458f114226a422bce782f65949b68babafe2b0488a4bc2b73a3e27ba360d646bbedaacb5e730c35ecc87b3ab6313190902e881f157977b5b56
7
+ data.tar.gz: da1d578e23a34fb2083890bc37ef250711f400eec3083fbeb00b33224314957fd6474e58fe86ecff6fa8a228d9924b8f4ef663db60f13461d0b11931912bf9eb
@@ -70,14 +70,11 @@ module MasterCard
70
70
  end
71
71
 
72
72
  def self.getAPIBaseURL
73
-
74
- if @@localhost
75
- return Constants::API_BASE_LOCALHOST_URL
76
- elsif @@sandbox
73
+ if @@sandbox
77
74
  return Constants::API_BASE_SANDBOX_URL
75
+ else
76
+ return Constants::API_BASE_LIVE_URL
78
77
  end
79
-
80
- return Constants::API_BASE_LIVE_URL
81
78
  end
82
79
  end
83
80
  end
@@ -27,8 +27,6 @@
27
27
  module MasterCard
28
28
  module Core
29
29
  module Constants
30
- VERSION = "1.0.0"
31
- API_BASE_LOCALHOST_URL = "http://localhost:8080"
32
30
  API_BASE_LIVE_URL = "https://api.mastercard.com"
33
31
  API_BASE_SANDBOX_URL = "https://sandbox.api.mastercard.com"
34
32
  end
@@ -56,10 +56,10 @@ module MasterCard
56
56
  JSON_STR = "JSON"
57
57
 
58
58
 
59
- def initialize(version=nil)
59
+ def initialize()
60
60
  #Set the parameters
61
61
  @baseURL = Config.getAPIBaseURL()
62
-
62
+
63
63
  @baseURL = removeForwardSlashFromTail(@baseURL)
64
64
 
65
65
  #Verify if the URL is correct
@@ -67,47 +67,17 @@ module MasterCard
67
67
  raise APIException.new "URL: '" + @baseURL + "' is not a valid url"
68
68
  end
69
69
 
70
- #Set the version
71
- unless version.nil?
72
- @version = version
73
- else
74
- @version = Constants::VERSION
75
- end
76
-
77
70
  end
78
71
 
79
- def execute(action,resourcePath,headerKey,queryKey,input)
80
-
72
+ def execute(config,metadata,input)
73
+
81
74
  #Check preconditions for execute
82
75
  preCheck()
83
-
84
- #Separate the headers from the inputMap
85
- headers = Util.subMap(input,headerKey)
86
-
87
- #Separate the query from the inputMap
88
- queryParams = Util.subMap(input,queryKey)
89
-
90
- #Get the resourcePath containing values from input
91
- resourcePath = getFullResourcePath(action,resourcePath,input)
92
-
93
- #Get the path parameters
94
- pathParams = getPathParams(action,queryParams,input)
95
- #Get the body
96
- body = getBody(action,input)
97
-
76
+
98
77
  #Get the request Object
99
- request = getRequestObject(resourcePath,action,pathParams,body)
100
-
101
- #Add headers to request
102
- headers.each do |key,value|
103
- request.add_field(key,value)
104
- end
105
-
106
- fullUrl = @baseURL+resourcePath
107
- #Sign and get back the request
108
- request = Config.getAuthentication().signRequest(fullUrl,request,request.method,body,pathParams)
109
-
110
- uri = URI.parse(@baseURL)
78
+ request = getRequestObject(config,metadata,input)
79
+
80
+ uri = URI.parse(request.path)
111
81
  #Get the http object
112
82
  http = getHTTPObject(uri)
113
83
 
@@ -115,7 +85,7 @@ module MasterCard
115
85
  puts "---- Request ----"
116
86
  puts ""
117
87
  puts "URL"
118
- puts @baseURL+request.path
88
+ puts request.path
119
89
  puts ""
120
90
  puts "Headers"
121
91
  request.each_header do |header_name, header_value|
@@ -217,10 +187,11 @@ module MasterCard
217
187
  end
218
188
 
219
189
  def getHTTPObject(uri)
190
+
220
191
  #Returns the HTTP Object
221
192
  http = Net::HTTP.new(uri.host,uri.port)
222
-
223
- unless Config.isLocal()
193
+
194
+ if uri.scheme == "https"
224
195
  http.use_ssl = true
225
196
  end
226
197
 
@@ -234,9 +205,35 @@ module MasterCard
234
205
  [path, encoded].join("?")
235
206
  end
236
207
 
237
- def getRequestObject(path,action,pathParams,body)
208
+ def getRequestObject(config,metadata,input)
209
+
210
+ #action,resourcePath,headerKey,queryKey,input
211
+
212
+ #Separate the headers from the inputMap
213
+ headers = Util.subMap(input,config.getHeaderParams())
214
+
215
+ #Separate the query from the inputMap
216
+ queryParams = Util.subMap(input,config.getQueryParams())
217
+
218
+ #We need to resolve the host
219
+ resolvedHost = @baseURL
220
+ unless metadata.getHost().nil?
221
+ resolvedHost = metadata.getHost()
222
+ end
223
+
224
+ fullUrl = resolvedHost + config.getResoucePath()
225
+
226
+ #Get the resourcePath containing values from input
227
+ fullUrl = getFullResourcePath(config.getAction(),fullUrl,input)
228
+
229
+ #Get the path parameters
230
+ pathParams = getPathParams(config.getAction(),queryParams,input)
231
+ #Get the body
232
+ body = getBody(config.getAction(),input)
233
+
234
+
238
235
  #Retuns the request object based on action
239
- case action.upcase
236
+ case config.getAction().upcase
240
237
  when ACTION_LIST, ACTION_READ, ACTION_QUERY
241
238
  verb = Net::HTTP::Get
242
239
 
@@ -249,26 +246,34 @@ module MasterCard
249
246
  when ACTION_UPDATE
250
247
  verb = Net::HTTP::Put
251
248
  else
252
- raise APIException.new "Invalid action #{action}"
249
+ raise APIException.new "Invalid action #{config.getAction()}"
253
250
  end
254
251
 
255
252
  #add url parameters to path
256
- path = encode_path_params(path,pathParams)
253
+ fullUrl = encode_path_params(fullUrl,pathParams)
257
254
 
258
- req = verb.new(path)
255
+ request = verb.new(fullUrl)
259
256
 
260
257
  #Add default headers
261
- req.add_field(KEY_ACCEPT,APPLICATION_JSON)
262
- req.add_field(KEY_CONTENT_TYPE,APPLICATION_JSON)
263
- req.add_field(KEY_USER_AGENT,RUBY_SDK+"/"+@version)
258
+ request.add_field(KEY_ACCEPT,APPLICATION_JSON)
259
+ request.add_field(KEY_CONTENT_TYPE,APPLICATION_JSON)
260
+ request.add_field(KEY_USER_AGENT,RUBY_SDK+"/"+metadata.getVersion())
264
261
 
265
262
  #Add body
266
263
 
267
264
  unless body.nil?
268
- req.body = body.to_json
265
+ request.body = body.to_json
266
+ end
267
+
268
+ #Add headers to request
269
+ headers.each do |key,value|
270
+ request.add_field(key,value)
269
271
  end
270
272
 
271
- return req
273
+ #Sign and get back the request
274
+ request = Config.getAuthentication().signRequest(fullUrl,request,request.method,body,pathParams)
275
+
276
+ return request
272
277
 
273
278
 
274
279
  end
@@ -340,7 +340,59 @@ module MasterCard
340
340
 
341
341
 
342
342
  end
343
+
344
+ ################################################################################
345
+ # OperationMetadata
346
+ ################################################################################
343
347
 
348
+ class OperationMetadata
349
+
350
+ def initialize(version, host)
351
+ @version = version
352
+ @host = host
353
+ end
354
+
355
+ def getVersion()
356
+ return @version
357
+ end
358
+
359
+ def getHost()
360
+ return @host
361
+ end
362
+
363
+ end
364
+
365
+
366
+ ################################################################################
367
+ # OperationConfig
368
+ ################################################################################
369
+
370
+ class OperationConfig
371
+
372
+ def initialize(resourcePath, action, headerParams, queryParams)
373
+ @resourcePath = resourcePath
374
+ @action = action
375
+ @headerParams = headerParams
376
+ @queryParams = queryParams
377
+ end
378
+
379
+ def getResoucePath()
380
+ return @resourcePath
381
+ end
382
+
383
+ def getAction()
384
+ return @action
385
+ end
386
+
387
+ def getHeaderParams()
388
+ return @headerParams
389
+ end
390
+
391
+ def getQueryParams()
392
+ return @queryParams
393
+ end
394
+
395
+ end
344
396
 
345
397
  ################################################################################
346
398
  # BaseObject
@@ -361,67 +413,26 @@ module MasterCard
361
413
  end
362
414
 
363
415
 
364
- def getResourcePath(action)
365
- raise NotImplementedError.new("Child class must define getResourcePath method to use this class")
366
- end
367
-
368
- def getHeaderParams(action)
369
- raise NotImplementedError.new("Child class must define getHeaderParams method to use this class")
416
+ protected
417
+
418
+ def self.getOperationConfig(uuid)
419
+ raise NotImplementedError.new("Child class must define getOperationConfig method to use this class")
370
420
  end
371
421
 
372
- def getQueryParams(action)
373
- raise NotImplementedError.new("Child class must define getQueryParams method to use this class")
422
+ def self.getOperationMetadata()
423
+ raise NotImplementedError.new("Child class must define getOperationMetadata method to use this class")
374
424
  end
375
-
376
- def self.getApiVersion()
377
- raise NotImplementedError.new("Child class must define getApiVersion method to use this class")
378
- end
379
-
380
- def self.readObject(inputObject,criteria=nil)
381
-
382
- unless criteria.nil?
383
-
384
- if criteria.is_a?(RequestMap)
385
- inputObject.setAll(criteria.getObject())
386
- else
387
- inputObject.setAll(criteria)
388
- end
389
-
390
- end
391
-
392
- return self.execute(APIController::ACTION_READ,inputObject)
393
-
394
- end
395
-
396
- def self.listObjects(inputObject)
397
- return self.execute(APIController::ACTION_LIST,inputObject)
398
- end
399
-
400
- def self.createObject(inputObject)
401
- return self.execute(APIController::ACTION_CREATE,inputObject)
402
- end
403
-
404
- def self.queryObject(inputObject)
405
- return self.execute(APIController::ACTION_QUERY,inputObject)
406
- end
407
-
408
- def self.deleteObject(inputObject)
409
- return self.execute(APIController::ACTION_DELETE,inputObject)
410
- end
411
-
412
- def self.updateObject(inputObject)
413
- return self.execute(APIController::ACTION_UPDATE,inputObject)
414
- end
415
-
416
- private
417
-
418
- def self.execute(action,inputObject)
419
-
420
- controller = APIController.new(self.getApiVersion)
421
- response = controller.execute(action,inputObject.getResourcePath(action),inputObject.getHeaderParams(action),inputObject.getQueryParams(action),inputObject.getObject())
425
+
426
+ def self.execute(operationUUID,inputObject)
427
+
428
+
429
+ config = inputObject.class.getOperationConfig(operationUUID)
430
+ metadata = inputObject.class.getOperationMetadata()
431
+
432
+ response = APIController.new.execute(config,metadata,inputObject.getObject())
422
433
  returnObjClass = inputObject.class
423
434
 
424
- if action == APIController::ACTION_LIST
435
+ if config.getAction().upcase == APIController::ACTION_LIST
425
436
  returnObj = []
426
437
 
427
438
  if response.is_a?(Hash) && response.key?(RequestMap::KEY_LIST)
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MasterCard Worldwide
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov