class Spectator::Http
Helper for HTTP requests
Public Class Methods
new(registry)
click to toggle source
Create a new instance using the given registry to record stats for the requests performed
# File lib/spectator/http.rb, line 9 def initialize(registry) @registry = registry end
Public Instance Methods
post_json(endpoint, payload)
click to toggle source
Send a JSON payload to a given endpoing
# File lib/spectator/http.rb, line 14 def post_json(endpoint, payload) s = payload.to_json uri = URI(endpoint) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json') req.body = s begin res = http.request(req) rescue StandardError => e Spectator.logger.info("Cause #{e.cause} - msg=#{e.message}") return 400 end res.value end