Class: MasterCard::Core::Controller::APIController
- Inherits:
-
Object
- Object
- MasterCard::Core::Controller::APIController
- Includes:
- MasterCard::Core, MasterCard::Core::Constants, 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; charset=UTF-8"- JSON_STR =
"JSON"
Constants included from MasterCard::Core::Constants
MasterCard::Core::Constants::SDK, MasterCard::Core::Constants::VERSION
Instance Method Summary collapse
Methods included from MasterCard::Core::Constants
Instance Method Details
#execute(config, metadata, input) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 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 |
# File 'lib/mastercard/core/controller.rb', line 59 def execute(config,,input) #Check preconditions for execute preCheck() resolvedHost = .getHost() if resolvedHost != nil && resolvedHost != 0 unless Util.validateURL(resolvedHost) raise APIException.new "URL: '" + resolvedHost + "' is not a valid url" end else raise APIException.new "URL: '' is not a valid url" 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 |