class InformantCommon::Client

Constants

SUPPORTED_REQUEST_METHODS

Public Class Methods

current_transaction() click to toggle source
# File lib/informant-common/client.rb, line 26
def self.current_transaction
  Thread.current[:informant_transaction] ||= InformantCommon::Event::MockFormSubmission.new
end
disable!() click to toggle source
# File lib/informant-common/client.rb, line 9
def self.disable!
  @enabled = false
end
enable!() click to toggle source
# File lib/informant-common/client.rb, line 13
def self.enable!
  @enabled = true
end
enabled?() click to toggle source
# File lib/informant-common/client.rb, line 5
def self.enabled?
  @enabled
end
process() click to toggle source
# File lib/informant-common/client.rb, line 34
def self.process
  if current_transaction.valid?
    this_transaction = current_transaction
    transmit(this_transaction)
  end
ensure
  reset_transaction!
end
reset_transaction!() click to toggle source
# File lib/informant-common/client.rb, line 30
def self.reset_transaction!
  Thread.current[:informant_transaction] = nil
end
start_transaction!(request_method) click to toggle source
# File lib/informant-common/client.rb, line 18
def self.start_transaction!(request_method)
  if enabled? && SUPPORTED_REQUEST_METHODS.include?(request_method)
    Thread.current[:informant_transaction] = InformantCommon::Event::FormSubmission.new
  else
    reset_transaction!
  end
end
transmit(event) click to toggle source
# File lib/informant-common/client.rb, line 43
def self.transmit(event)
  Thread.new(Client) do |client_class|
    Net::HTTP.start(*event.net_http_start_arguments) do |http|
      response = http.request(event.post_request)
      client_class.disable! if response.code == '401'
      response
    end
  end
end