Class Hookout::Utils
In: lib/hookout/reversehttp_connector.rb
Parent: Object

Methods

abort   execute_request   get   new   post_data   post_form  

Classes and Modules

Class Hookout::Utils::ConnectorAbortException

Public Class methods

[Source]

# File lib/hookout/reversehttp_connector.rb, line 177
    def initialize
      @current_http = nil
      @current_thread = nil
    end

[Source]

# File lib/hookout/reversehttp_connector.rb, line 215
    def self.post_data(url, data)
      parts = URI.parse(url)
      req = Net::HTTP::Post.new(parts.path)
      req.body = data
      req.content_type = 'message/http'
      Net::HTTP.start(parts.host, parts.port) {|http|
        http.request(req)
      }
    end

Public Instance methods

[Source]

# File lib/hookout/reversehttp_connector.rb, line 195
    def abort
      @current_http.finish if @current_http
      @current_thread.raise ConnectorAbortException.new if @current_thread
    end

[Source]

# File lib/hookout/reversehttp_connector.rb, line 200
    def execute_request(parts, req)
      begin
        Net::HTTP.start(parts.host, parts.port) {|http|
          @current_http = http
          @current_thread = Thread.current
          http.request(req)
        }
      rescue ConnectorAbortException
        return nil
      ensure
        @current_http = nil
        @current_thread = nil
      end
    end

[Source]

# File lib/hookout/reversehttp_connector.rb, line 182
    def get(url)
      parts = URI.parse(url)
      req = Net::HTTP::Get.new(parts.path)
      execute_request(parts, req)
    end

[Source]

# File lib/hookout/reversehttp_connector.rb, line 188
    def post_form(url, params)
      parts = URI.parse(url)
      req = Net::HTTP::Post.new(parts.path)
      req.set_form_data(params)
      execute_request(parts, req)
    end

[Validate]