Class: GenericSender

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

Direct Known Subclasses

GitReport::BatchSender, GitReport::Sender

Class Method Summary collapse

Class Method Details

.communicate(exception, response) ⇒ Object

logs and puts the error according to its conditions and configuration TODO refactor me!



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generic_sender.rb', line 5

def self.communicate exception, response
  both, cmd, log = [], [], []
  if exception.is_a?(GitReport::ServerError)
    @error_type = "server error"
    message = JSON.parse(response.body)["message"] rescue response.body
    error = JSON.parse(response.body)["error"] rescue nil
    @details = message ? "#{message} - #{error}" : error
  else
    @error_type = "client error"
    @details = exception.backtrace
  end
  both << "A #{@error_type} occured during data transfer."
  both << "Exception: #{exception}"
  if GitReport.global_opts[:trace]
    cmd << @details
  else
    cmd << "Run with --trace to get more info."
  end
  log << @details
  puts (both + cmd).join("\n")
  (both + log).each{ |line| grlog(0, "send_data! #{line}")}
end

.configurationObject

returns configuration object



34
35
36
# File 'lib/generic_sender.rb', line 34

def self.configuration
  @@configuration ||= GitReport.configuration
end

.headers(request) ⇒ Object

returns the default headers



39
40
41
42
43
44
# File 'lib/generic_sender.rb', line 39

def self.headers request
  request['User-Agent']              = 'gitreport-client-ruby'
  request['Content-Type']            = 'application/json'
  request['Accept']                  = 'application/json'
  request['X-gitreport-Auth-Token']  = configuration.auth_token
end

.storageObject

returns local storage



29
30
31
# File 'lib/generic_sender.rb', line 29

def self.storage
  @@storage ||= GitReport::Storage.new(ENV['HOME'], '.gitreport_storage')
end