Class: InformantRails::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/informant-rails/client.rb

Class Method Summary collapse

Class Method Details

.processObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/informant-rails/client.rb', line 24

def self.process
  if Config.api_token.present? && request && request.models.any?
    Typhoeus::Request.new(
      api_url,
      method: :post,
      body: { payload: request }.to_json,
      headers: {
        "Authorization" => ActionController::HttpAuthentication::Token.encode_credentials(InformantRails::Config.api_token),
        "Content-Type" => "application/json"
      }
    ).run
  end
ensure
  remove_request
end

.record(env) ⇒ Object



7
8
9
10
11
# File 'lib/informant-rails/client.rb', line 7

def self.record(env)
  unless env['REQUEST_METHOD'] == 'GET'
    new_request.request_url = env['HTTP_REFERER']
  end
end

.record_action(controller_name, action) ⇒ Object



13
14
15
16
17
18
# File 'lib/informant-rails/client.rb', line 13

def self.record_action(controller_name, action)
  if request
    request.filename = controller_name
    request.action = action
  end
end

.record_validated_model(model) ⇒ Object



20
21
22
# File 'lib/informant-rails/client.rb', line 20

def self.record_validated_model(model)
  request.process_model(model) if request && include_model?(model)
end

.requestObject



40
41
42
# File 'lib/informant-rails/client.rb', line 40

def self.request
  @requests[request_id]
end