Class: Agent99::RegistryClient
- Inherits:
-
Object
- Object
- Agent99::RegistryClient
- Defined in:
- lib/agent99/registry_client.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #discover(capability:) ⇒ Object
- #fetch_all_agents ⇒ Object
-
#initialize(base_url: ENV.fetch('AGENT99_REGISTRY_URL', 'http://localhost:4567'), logger: Logger.new($stdout)) ⇒ RegistryClient
constructor
A new instance of RegistryClient.
- #register(info:) ⇒ Object
- #withdraw(id) ⇒ Object
Constructor Details
#initialize(base_url: ENV.fetch('AGENT99_REGISTRY_URL', 'http://localhost:4567'), logger: Logger.new($stdout)) ⇒ RegistryClient
Returns a new instance of RegistryClient.
10 11 12 13 14 15 16 17 |
# File 'lib/agent99/registry_client.rb', line 10 def initialize( base_url: ENV.fetch('AGENT99_REGISTRY_URL', 'http://localhost:4567'), logger: Logger.new($stdout) ) @base_url = base_url @logger = logger @http_client = Net::HTTP.new(URI.parse(base_url).host, URI.parse(base_url).port) end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/agent99/registry_client.rb', line 8 def logger @logger end |
Instance Method Details
#discover(capability:) ⇒ Object
33 34 35 36 37 |
# File 'lib/agent99/registry_client.rb', line 33 def discover(capability:) encoded_capability = URI.encode_www_form_component(capability) request = create_request(:get, "/discover?capability=#{encoded_capability}") send_request(request) end |
#fetch_all_agents ⇒ Object
40 41 42 43 |
# File 'lib/agent99/registry_client.rb', line 40 def fetch_all_agents request = create_request(:get, "/") response = send_request(request) end |
#register(info:) ⇒ Object
19 20 21 22 23 |
# File 'lib/agent99/registry_client.rb', line 19 def register(info:) payload = info request = create_request(:post, "/register", payload) @id = send_request(request) end |
#withdraw(id) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/agent99/registry_client.rb', line 25 def withdraw(id) return logger.warn("Agent not registered") unless id request = create_request(:delete, "/withdraw/#{id}") send_request(request) end |