Class: Imperium::AgentListServicesResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/imperium/agent_list_services_response.rb

Overview

Note:

This class doesn’t really make sense to be instantiated outside of Imperium::Agent#list_services

AgentListServiceResponse is a wrapper for the raw HTTP::Message response

from the API

We’ve included Enumerable and implemented #each so it can be treated as an array of Service objects.

Instance Method Summary collapse

Methods inherited from Response

#coerced_body, #index, #initialize, #known_leader?, #last_contact, #not_found?, #translate_addresses?

Constructor Details

This class inherits a constructor from Imperium::Response

Instance Method Details

#each(&block) ⇒ Object



16
17
18
# File 'lib/imperium/agent_list_services_response.rb', line 16

def each(&block)
  services.each(&block)
end

#servicesArray<Service>

Build an array of Service objects from the response

Returns:

  • (Array<Service>)

    This array will be empty when the response is not a success



24
25
26
# File 'lib/imperium/agent_list_services_response.rb', line 24

def services
  @services ||= services_hash.values
end

#services_hashHash<String => Service>

Build a hash of Service object from the response

The keys are the service’s id from the API response.

Returns:



32
33
34
# File 'lib/imperium/agent_list_services_response.rb', line 32

def services_hash
  @services_hash ||= (ok? ? coerced_body : {})
end