Class: GenericSender
- Inherits:
-
Object
- Object
- GenericSender
- Defined in:
- lib/generic_sender.rb
Direct Known Subclasses
Class Method Summary collapse
-
.communicate(exception, response) ⇒ Object
logs and puts the error according to its conditions and configuration TODO refactor me!.
-
.configuration ⇒ Object
returns configuration object.
-
.headers(request) ⇒ Object
returns the default headers.
-
.storage ⇒ Object
returns local storage.
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" = JSON.parse(response.body)["message"] rescue response.body error = JSON.parse(response.body)["error"] rescue nil @details = ? "#{} - #{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 |
.configuration ⇒ Object
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 |