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 18 |
# 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 uri = URI.parse(base_url) @http_client = Net::HTTP.new(uri.host, uri.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
34 35 36 37 38 |
# File 'lib/agent99/registry_client.rb', line 34 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
41 42 43 44 |
# File 'lib/agent99/registry_client.rb', line 41 def fetch_all_agents request = create_request(:get, "/") response = send_request(request) end |
#register(info:) ⇒ Object
20 21 22 23 24 |
# File 'lib/agent99/registry_client.rb', line 20 def register(info:) payload = info request = create_request(:post, "/register", payload) @id = send_request(request) end |
#withdraw(id) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/agent99/registry_client.rb', line 26 def withdraw(id) return logger.warn("Agent not registered") unless id request = create_request(:delete, "/withdraw/#{id}") send_request(request) end |