Module: Legate::Tools::Base::HttpClient

Included in:
CatFacts, HttpRequest, ReadWebpage, WebhookTool
Defined in:
lib/legate/tools/base/http_client.rb

Overview

Mixin module providing standardized, reusable HTTP client capabilities for Legate tools, built upon the Excon gem.

Include this module in your Tool class and call ‘setup_http_client` in your `initialize` method.

It offers helper methods (http_get, http_head, http_post, etc.) for common requests, handles base URL joining, JSON encoding/decoding (optional), logging, and wraps Excon errors into standardized Legate::ToolError subclasses.

Defined Under Namespace

Classes: QuietInstrumentor

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#http_base_urlObject (readonly)

Returns the value of attribute http_base_url.



33
34
35
# File 'lib/legate/tools/base/http_client.rb', line 33

def http_base_url
  @http_base_url
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



33
34
35
# File 'lib/legate/tools/base/http_client.rb', line 33

def http_client
  @http_client
end

Instance Method Details

#http_delete(path, query: {}, headers: {}, options: {}) ⇒ Object



53
54
55
# File 'lib/legate/tools/base/http_client.rb', line 53

def http_delete(path, query: {}, headers: {}, options: {})
  make_request(:delete, path, query: query, headers: headers, options: options)
end

#http_get(path, query: {}, headers: {}, options: {}) ⇒ Object

Make request helpers public API for tools including this module



37
38
39
# File 'lib/legate/tools/base/http_client.rb', line 37

def http_get(path, query: {}, headers: {}, options: {})
  make_request(:get, path, query: query, headers: headers, options: options)
end

#http_head(path, query: {}, headers: {}, options: {}) ⇒ Object



41
42
43
# File 'lib/legate/tools/base/http_client.rb', line 41

def http_head(path, query: {}, headers: {}, options: {})
  make_request(:head, path, query: query, headers: headers, options: options)
end

#http_post(path, body: nil, query: {}, headers: {}, options: {}) ⇒ Object



45
46
47
# File 'lib/legate/tools/base/http_client.rb', line 45

def http_post(path, body: nil, query: {}, headers: {}, options: {})
  make_request(:post, path, body: body, query: query, headers: headers, options: options)
end

#http_put(path, body: nil, query: {}, headers: {}, options: {}) ⇒ Object



49
50
51
# File 'lib/legate/tools/base/http_client.rb', line 49

def http_put(path, body: nil, query: {}, headers: {}, options: {})
  make_request(:put, path, body: body, query: query, headers: headers, options: options)
end