class Capistrano::Ghostinspector::Api

Public Class Methods

new(gi_api_key, domain, rollback, ga_enabled) click to toggle source
# File lib/capistrano/ghostinspector/api.rb, line 8
def initialize(gi_api_key, domain, rollback, ga_enabled)
  @apiKey = gi_api_key
  @domain = domain
  @rollback = rollback
  @ga_enabled = ga_enabled

  # Determine if we should get results to
  # check for any failed tests
  @immediate = includeResults()
end

Public Instance Methods

executeApi(type, test) click to toggle source
# File lib/capistrano/ghostinspector/api.rb, line 20
def executeApi(type, test)

  # Default all tests pass
  passing = true

  # ------ TESTING ONLY ------
  # results = JSON.parse(File.read("gitestresults.json"))
  # results = JSON.parse(File.read("suiteresults.json"))
  # ------ TESTING ONLY ------

  # # Perform the API request and get the results
  results = sendRequest(type, test)

  # Check the data returned for failed tests
  if (@rollback == true)
    passing = getPassing(type, results)
  end

  data = Array.new
  data << passing
  data << results

  return data

end
shouldWaitForResults() click to toggle source
# File lib/capistrano/ghostinspector/api.rb, line 46
def shouldWaitForResults()
  return @rollback == false && @ga_enabled == false;
end

Private Instance Methods

getPassing(type, results) click to toggle source
# File lib/capistrano/ghostinspector/api.rb, line 85
def getPassing(type, results)

  if (type == "suites")
    results["data"].each do |testItem|
      passing = testItem["passing"]
    end
  else
    passing = results["data"]["passing"]
  end

  return passing

end
includeResults() click to toggle source
# File lib/capistrano/ghostinspector/api.rb, line 52
def includeResults()

  # Determine if we should get results to
  # check for any failed tests
  if (shouldWaitForResults())
    immediate = "&immediate=1"
  else
    immediate = ""
    puts "* * * Gathering results. This could take a few minutes. * * *"
  end

  return immediate
end
sendRequest(type, test) click to toggle source
# File lib/capistrano/ghostinspector/api.rb, line 66
def sendRequest(type, test)
  uri = URI("https://api.ghostinspector.com/v1/#{type}/#{test}/execute/?apiKey=#{@apiKey}#{@immediate}")

  if (@domain != nil)
      uri.query = [uri.query, "startUrl=http://#{@domain}/"].compact.join('&')
  end

  Net::HTTP.start(uri.host, uri.port,
  :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Get.new uri
    http.read_timeout = 600
    @response = http.request request
  end

  results = JSON.parse(@response.body)

  return results
end