Skip to content

Commit 3249229

Browse files
committed
Mid-May 2020 Release (Fixes)
1 parent daba962 commit 3249229

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

generator/cybersource-ruby-template/api_client.mustache

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ module {{moduleName}}
2020
attr_accessor :default_headers
2121

2222
# Defines the client ID for the SDK
23-
attr_accessor :client_id
23+
attr_accessor :client_id
24+
25+
# Defines the user-defined Accept Header Type
26+
attr_accessor :accept_header
2427

2528
# Initializes the ApiClient
2629
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
@@ -35,6 +38,10 @@ module {{moduleName}}
3538
@client_id = 'cybs-rest-sdk-ruby-' + Gem.loaded_specs["cybersource_rest_client"].version.to_s
3639
end
3740

41+
def set_user_defined_accept_header(accept_type)
42+
@accept_header = accept_type
43+
end
44+
3845
def self.default
3946
@@default ||= ApiClient.new
4047
end
@@ -44,17 +51,23 @@ module {{moduleName}}
4451
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
4552
# the data deserialized from response body (could be nil), response status code and response headers.
4653
def call_api(http_method, path, opts = {})
54+
unless @accept_header.nil? || @accept_header.empty?
55+
default_accept_header = ',' + (opts[:header_params])['Accept']
56+
default_accept_header = @accept_header + default_accept_header.sub(',' + @accept_header, '')
57+
opts[:header_params]['Accept'] = default_accept_header
58+
end
59+
4760
request = build_request(http_method, path, opts)
4861
response = request.run
4962

5063
if @config.debugging
51-
begin
52-
raise
53-
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
54-
rescue
55-
puts 'Cannot write to log'
56-
end
57-
end
64+
begin
65+
raise
66+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
67+
rescue
68+
puts 'Cannot write to log'
69+
end
70+
end
5871

5972
unless response.success?
6073
if response.timed_out?
@@ -91,7 +104,7 @@ module {{moduleName}}
91104
url = build_request_url(path)
92105
body_params = opts[:body] || {}
93106
query_params = opts[:query_params] || {}
94-
if !query_params.empty?
107+
if !query_params.empty?
95108
query_params = URI.encode_www_form(query_params)
96109
end
97110
headers = CallAuthenticationHeader(http_method, path, body_params, opts[:header_params], query_params)
@@ -126,26 +139,26 @@ module {{moduleName}}
126139
req_body = build_request_body(header_params, form_params, opts[:body])
127140
req_opts.update :body => req_body
128141
if @config.debugging
129-
begin
130-
raise
131-
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
132-
rescue
133-
puts 'Cannot write to log'
134-
end
135-
end
142+
begin
143+
raise
144+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
145+
rescue
146+
puts 'Cannot write to log'
147+
end
148+
end
136149
end
137150

138151
request = Typhoeus::Request.new(url, req_opts)
139152
download_file(request) if opts[:return_type] == 'File'
140153
request
141154
end
142-
# set merchantConfig
143-
def set_configuration(config)
144-
require_relative '../AuthenticationSDK/core/MerchantConfig.rb'
145-
$merchantconfig_obj = Merchantconfig.new(config)
146-
@config.host = $merchantconfig_obj.requestHost
147-
end
148-
# Calling Authentication
155+
# set merchantConfig
156+
def set_configuration(config)
157+
require_relative '../AuthenticationSDK/core/MerchantConfig.rb'
158+
$merchantconfig_obj = Merchantconfig.new(config)
159+
@config.host = $merchantconfig_obj.requestHost
160+
end
161+
# Calling Authentication
149162
def CallAuthenticationHeader(http_method, path, body_params, header_params, query_params)
150163
require_relative '../AuthenticationSDK/core/Authorization.rb'
151164
require_relative '../AuthenticationSDK/authentication/payloadDigest/digest.rb'
@@ -204,7 +217,7 @@ module {{moduleName}}
204217
end
205218
request_target
206219
end
207-
220+
208221
# Check if the given MIME is a JSON MIME.
209222
# JSON MIME examples:
210223
# application/json

0 commit comments

Comments
 (0)