lib/hubspot/discovery/base_api_client.rb in hubspot-api-client-14.2.0 vs lib/hubspot/discovery/base_api_client.rb in hubspot-api-client-14.3.0
- old
+ new
@@ -1,5 +1,7 @@
+require_rel '../helpers/camel_case'
+
module Hubspot
module Discovery
module BaseApiClient
attr_reader :base_params
@@ -15,11 +17,11 @@
def config
@config ||= new_config
end
def api_client
- @api_client ||= Kernel.const_get("#{self.class.name.gsub('Discovery::', '').gsub(/(.*)::.*/, '\1')}::ApiClient").new(config)
+ @api_client ||= Kernel.const_get("#{codegen_module_name}::ApiClient").new(config)
end
def api
@api ||= Kernel.const_get(codegen_api_class).new(api_client)
end
@@ -40,10 +42,14 @@
def codegen_api_class
self.class.name.gsub('Discovery::', '')
end
+ def codegen_module_name
+ codegen_api_class.gsub(/(.*)::.*/, '\1')
+ end
+
def define_methods
define_api_methods
end
def define_api_methods
@@ -63,14 +69,18 @@
signature_params = api.method(api_method).parameters
signature_param_names = signature_params.map { |_, param| param }
params_with_defaults.each do |param_name, param_value|
- params_with_defaults[:opts][param_name] = param_value unless signature_param_names.include?(param_name)
+ params_with_defaults[:opts][param_name] = param_value if !signature_param_names.include?(param_name) && param_name != :body
end
params_to_pass = signature_params.map do |req, param|
+ model_name = Hubspot::Helpers::CamelCase.new.format(param.to_s)
+ Kernel.const_get("#{codegen_module_name}::#{model_name}").build_from_hash(params_with_defaults[:body])
+ rescue NameError
raise "Param #{param} is required for #{api.class}\##{api_method} method" if req == :req && params_with_defaults[param].nil?
+
params_with_defaults[param]
end
api.public_send(api_method, *params_to_pass)
end