Class: SwaggerMCPTool::ApiClient

Inherits:
Object
  • Object
show all
Includes:
Helpers::Request, Logging
Defined in:
lib/swagger_mcp_tool/api_client.rb

Overview

The SwaggerMCPTool module provides tools and utilities for interacting with APIs using Swagger/OpenAPI specifications. It includes classes and helpers for making HTTP requests, handling responses, logging, and managing configuration.

This module is intended to be used as part of the swagger_mcp_tool library, facilitating API client operations with robust error handling and logging.

Example usage:

client = SwaggerMCPTool::ApiClient.new("https://api.example.com")
response = client.make_request(:get, "/v1/resource", { id: 123 })

Instance Method Summary collapse

Methods included from Logging

#log_and_raise_error, #log_message, #log_request_details, #log_request_execution, #log_server_initialization

Methods included from Helpers::Request

#add_authorization_header, #add_headers_to_request, #body_required?, #build_request_context, #build_request_uri, #create_http_request, #process_path_parameters, #request_methods, #set_json_body

Constructor Details

#initialize(base_url) ⇒ ApiClient

Returns a new instance of ApiClient.



31
32
33
34
# File 'lib/swagger_mcp_tool/api_client.rb', line 31

def initialize(base_url)
  @base_url = base_url.chomp('/')
  @config = Config.instance
end

Instance Method Details

#make_request(method, path, params = {}, headers = {}, server_context = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/swagger_mcp_tool/api_client.rb', line 36

def make_request(method, path, params = {}, headers = {}, server_context = {})
  request_context = build_request_context(method, path, params, headers, server_context)

  log_request_details(request_context)

  response = execute_http_request(request_context)
  process_response(response)
rescue StandardError => e
  handle_request_error(e)
end