lib/capistrano/ghostinspector/api.rb in capistrano-ghostinspector-0.4.0 vs lib/capistrano/ghostinspector/api.rb in capistrano-ghostinspector-1.0.0

- old
+ new

@@ -3,15 +3,15 @@ module Capistrano module Ghostinspector class Api - def initialize(gi_api_key, domain, rollback, ga_property) + def initialize(gi_api_key, domain, rollback, ga_enabled) @apiKey = gi_api_key @domain = domain @rollback = rollback - @ga_property = ga_property + @ga_enabled = ga_enabled # Determine if we should get results to # check for any failed tests @immediate = includeResults() end @@ -21,16 +21,16 @@ # Default all tests pass passing = true # ------ TESTING ONLY ------ - # results = JSON.parse(File.read("gitestresults.json")) + 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) + # results = sendRequest(type, test) # Check the data returned for failed tests if (@rollback == true) passing = getPassing(type, results) end @@ -47,22 +47,25 @@ def includeResults() # Determine if we should get results to # check for any failed tests - if (@rollback == false && @ga_property == "") + if (@rollback == false && @ga_enabled == false) immediate = "&immediate=1" else immediate = "" puts "* * * Gathering results. This could take a few minutes. * * *" end return immediate end def sendRequest(type, test) + uri = URI("https://api.ghostinspector.com/v1/#{type}/#{test}/execute/?apiKey=#{@apiKey}#{@immediate}") - uri = URI("https://api.ghostinspector.com/v1/#{type}/#{test}/execute/?apiKey=#{@apiKey}&startUrl=http://#{@domain}/#{@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