Class: MasterCard::Core::Controller::APIController
- Inherits:
-
Object
- Object
- MasterCard::Core::Controller::APIController
- Includes:
- MasterCard::Core, Exceptions, Security
- Defined in:
- lib/mastercard/core/controller.rb
Constant Summary collapse
- ACTION_CREATE =
"CREATE"- ACTION_DELETE =
"DELETE"- ACTION_UPDATE =
"UPDATE"- ACTION_READ =
"READ"- ACTION_LIST =
"LIST"- ACTION_QUERY =
"QUERY"- KEY_ID =
"id"- KEY_FORMAT =
"Format"- KEY_ACCEPT =
"Accept"- KEY_USER_AGENT =
"User-Agent"- KEY_CONTENT_TYPE =
"Content-Type"- APPLICATION_JSON =
"application/json"- RUBY_SDK =
"Ruby_SDK"- JSON_STR =
"JSON"
Instance Method Summary collapse
- #execute(config, metadata, input) ⇒ Object
-
#initialize ⇒ APIController
constructor
A new instance of APIController.
Constructor Details
#initialize ⇒ APIController
Returns a new instance of APIController.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mastercard/core/controller.rb', line 59 def initialize() #Set the parameters @baseURL = Config.getAPIBaseURL() @baseURL = removeForwardSlashFromTail(@baseURL) #Verify if the URL is correct unless Util.validateURL(@baseURL) raise APIException.new "URL: '" + @baseURL + "' is not a valid url" end end |
Instance Method Details
#execute(config, metadata, input) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/mastercard/core/controller.rb', line 72 def execute(config,,input) #Check preconditions for execute preCheck() resolvedHost = @baseURL unless .getHost().nil? resolvedHost = .getHost() end uri = URI.parse(resolvedHost) #Get the http object http = getHTTPObject(uri) #Get the request Object request = getRequestObject(config,,input) if Config.isDebug puts "---- Request ----" puts "" puts "URL" puts request.path puts "" puts "Headers" request.each_header do |header_name, header_value| puts "#{header_name} : #{header_value}" end puts "" puts "Body" puts request.body end begin response = http.request(request) if Config.isDebug puts "---- Response ----" puts "" puts "Status Code" puts response.code puts "" puts "Headers" response.each_header do |header_name, header_value| puts "#{header_name} : #{header_value}" end puts "" puts "Body" puts response.body end return handleResponse(response,response.body) rescue Errno::ECONNREFUSED raise APIException.new ("Connection to server could not be established.") end end |