Send HTTP requests to all servers in the local manifest Params:
endpoint
The REST endpoint you'd like to send a request to
args
Any specific configuration data to send along with the request
# File lib/client/helper/apicommunication.rb, line 41 def send_to_all(endpoint, args = {}) @config.get(:servers).each do |server| send_to_one(server[:name], endpoint, args) if server[:name] end end
Send an HTTP request to one server Params:
input
The server you want to connect to
endpoint
The REST endpoint you'd like to send a request to
args
Any specific configuration data to send along with the request
# File lib/client/helper/apicommunication.rb, line 9 def send_to_one(input, endpoint, args = {}) server, endpoint = setup(input, endpoint, args) begin resp = @network.post(endpoint.to_s, server[:key]) Notify.spit(endpoint.to_s) if DEBUG Notify.spit(resp.body) if DEBUG # generic failure for invalid response type raise Errno::ECONNREFUSED if resp["Content-Type"] != "application/json" # handle JSON response response_data = @format.symbolize(JSON.parse(resp.body)) if response_data[:_code] == 200 Notify.success("#{server[:name]} (#{server[:address]}) update succeeded") elsif !response_data[:message].nil? # work around a messaging issue with vermillion-server Notify.warning("Error: #{response_data[:message]}") else Notify.warning("#{response_data[:_title]}: #{response_data[:_message]}") end rescue Errno::ECONNREFUSED Notify.warning("Request failed for #{server[:name]} (#{server[:address]})") end end