class Sender

Attributes

additional_fields[RW]
datafield_name[RW]
url[RW]

Public Class Methods

new(url) click to toggle source
# File lib/filentory/sender.rb, line 7
def initialize(url)
  @url = URI.parse(url)
  @failed = nil
  @datafield_name = "data"
end

Public Instance Methods

failed?() click to toggle source
# File lib/filentory/sender.rb, line 35
def failed?
        @failed
end
post(message) click to toggle source
# File lib/filentory/sender.rb, line 13
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