Sha256: e26bb22b58fbb706e2e676a244cda405049ee01f6906d60bfe8b4dca1e1e67e7
Contents?: true
Size: 773 Bytes
Versions: 5
Compression:
Stored size: 773 Bytes
Contents
require 'uri' require 'net/http' class Sender attr_accessor :url, :datafield_name, :additional_fields def initialize(url) @url = URI.parse(url) @failed = nil @datafield_name = "data" end def post(message) begin params = {@datafield_name => message} if not @additional_fields.nil? params.merge!(@additional_fields) end http = Net::HTTP.new(@url.host, @url.port) http.read_timeout = 6000 request = Net::HTTP::Post.new(@url.request_uri) request.set_form_data(params) response = http.request(request) @failed = !response.code.to_s.start_with?("2") rescue => error_message response = Net::HTTPResponse.new "ERROR", "400", error_message @failed = true end response end def failed? @failed end end
Version data entries
5 entries across 5 versions & 1 rubygems