Service Drivers
Sending a Request
# Example usage:
def query_position
# Get request will look like:
# http://domain.or.ip/api/status_of?coordinates=detailed
get('/api/status_of', {
query: {
coordinates: :detailed
}
}) do |data, resolve, command|
check_response(data) do |resp|
# Update status (made available to interfaces)
self[:position] = resp['coords']
end
end
end
def check_response(data)
# Check response status
# (might have been 500 or 404, depends on what you are expecting)
if data.status == 200
begin
# We're assuming a JSON response and we are passing that data
# back to the calling function and assuming success at this point
yield ::JSON.parse(data.body) if block_given?
return :success
rescue => e
logger.print_error e
end
end
# Fail if there are any issues
# Obviously this behaviour depends on the service etc
:abort
endRequest Options
Basic Authentication
Handling a Response
Cookies
Proxy Support
Last updated