Class: Coveralls::API

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

Constant Summary collapse

API_HOST =
ENV['COVERALLS_DEVELOPMENT'] ? "localhost:3000" : "coveralls.io"
API_DOMAIN =
"#{API_PROTOCOL}://#{API_HOST}"
API_PROTOCOL =
ENV['COVERALLS_DEVELOPMENT'] ? "http" : "https"
API_BASE =
"#{API_DOMAIN}/api/v1"

Class Method Summary collapse

Class Method Details

.post_json(endpoint, hash) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/coveralls/api.rb', line 18

def self.post_json(endpoint, hash)
  disable_net_blockers!

  Coveralls::Output.puts("#{ JSON.pretty_generate(hash) }", :color => "green") if ENV['COVERALLS_DEBUG']
  Coveralls::Output.puts("[Coveralls] Submitting to #{API_BASE}", :color => "cyan")

  url = endpoint_to_url(endpoint)
  hash = apified_hash(hash)

  response = HTTParty.post(
    url,
    body: {
      json_file: hash_to_file(hash),
    },
  )

  if response['message']
    Coveralls::Output.puts("[Coveralls] #{ response['message'] }", :color => "cyan")
  end

  if response['url']
    Coveralls::Output.puts("[Coveralls] #{ Coveralls::Output.format(response['url'], :color => "underline") }", :color => "cyan")
  end

  if response['error']
    Coveralls::Output.puts("[Coveralls] Error: #{ Coveralls::Output.format(response['error'], :color => "underline") }", :color => "red")
  end

  case response
  when Net::HTTPServiceUnavailable
    Coveralls::Output.puts("[Coveralls] API timeout occured, but data should still be processed", :color => "red")
  when Net::HTTPInternalServerError
    Coveralls::Output.puts("[Coveralls] API internal error occured, we're on it!", :color => "red")
  end
end