Class: Lushka::Pods

Inherits:
Object
  • Object
show all
Defined in:
lib/lushka/pods.rb

Overview

Sources for data extractions class

Instance Method Summary collapse

Constructor Details

#initializePods

Returns a new instance of Pods.



10
# File 'lib/lushka/pods.rb', line 10

def initialize; end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lushka/pods.rb', line 12

def call(env)
  query = Rack::Request.new(env)
  if query.post?
    request = JSON.parse(query.body.read)
    response = log_request(request)
  else
    response = show_log
  end

  body = [response]
  status  = 200
  headers = { "content-type" => "application/json" }

  [status, headers, body]
end

#log_request(request) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/lushka/pods.rb', line 28

def log_request(request)
  uuid = SecureRandom.uuid
  File.open("#{Lushka.logs}/pods.log", "a") do |log_file|
    log_file.puts "Request ##{uuid} — BODY: #{request.to_s}"
  end
  { request_uuid: uuid }.to_json
end

#show_logObject



36
37
38
39
40
41
42
# File 'lib/lushka/pods.rb', line 36

def show_log
  result = []
  File.readlines("#{Lushka.logs}/pods.log").each do |line|
    result.prepend(line)
  end
  result.join(" ")
end