class Netting
A wrapper around Net::HTTP::Post and Get methods.
Public Class Methods
new(url)
click to toggle source
A full URL has to be given, starting with http:, ending in the port (if port is not the default)
# File lib/netting.rb, line 13 def initialize url @url = url end
Public Instance Methods
get(*stuff)
click to toggle source
Sends HTTP GET and returns the answer
# File lib/netting.rb, line 25 def get *stuff send_req Net::HTTP::Get, *stuff end
post(*stuff)
click to toggle source
Sends HTTP POST, data as json
# File lib/netting.rb, line 19 def post *stuff send_req Net::HTTP::Post, *stuff end
Private Instance Methods
send_req(req_type, action, data=nil)
click to toggle source
Sends either a POST or a GET http message.
# File lib/netting.rb, line 32 def send_req(req_type, action, data=nil) uri = URI(@url + action) req = req_type.new(uri, 'Content-Type' => 'application/json') req.body = data begin response = Net::HTTP.start(uri.hostname, uri.port, {open_timeout: @@Timeout}) { |http| http.request(req) } response rescue Exception => e puts " *** #{e.message}" end end