Module: ClashOfClansApi::EndpointMethods::ClassMethods

Defined in:
lib/clash_of_clans_api/endpoint_methods.rb

Instance Method Summary collapse

Instance Method Details

#define_endpoint(name, method:, endpoint:, body: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/clash_of_clans_api/endpoint_methods.rb', line 52

def define_endpoint(name, method:, endpoint:, body: nil)
	define_method(name) do |*args, **kwargs|
		uri          = endpoint.respond_to?(:call) ? ClashOfClansApi::Utils.call_proc_without_unknown_keywords(endpoint, *args, **kwargs) : endpoint
		request_body = body    .respond_to?(:call) ? ClashOfClansApi::Utils.call_proc_without_unknown_keywords(body,     *args, **kwargs) : body
		
		perform_request(method, uri, body: request_body, query: kwargs.dig(:query), headers: kwargs.dig(:headers)).then do |response|
			if !kwargs.key?(:plain_response) || !kwargs.fetch(:plain_response)
				transform_response(response)
			else
				response
			end
		end
	end
end