class TestRescueAgent::TestRescueClient
Public Class Methods
new(options={})
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 13 def initialize(options={}) @endpoint = options[:endpoint] @repository_id = options[:repository_id] @api_key = options[:api_key] @secret = options[:secret] end
Public Instance Methods
claim_file_run(suite_run_id, container_id)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 39 def claim_file_run(suite_run_id, container_id) response = post("/suite_runs/#{suite_run_id}/file_runs/claim", container_id: container_id) json = JSON.parse(response.body) TestRescueClient::FileRun.new(self, json) if json end
complete_file_run(suite_run_id, file_run_id)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 45 def complete_file_run(suite_run_id, file_run_id) update_file_run(suite_run_id, file_run_id, {completed_at: Time.now.iso8601}) end
create_file_run(suite_run_id, attributes)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 29 def create_file_run(suite_run_id, attributes) response = post("/suite_runs/#{suite_run_id}/file_runs", file_run: attributes) TestRescueClient::FileRun.new(self, JSON.parse(response.body)) end
create_file_run_exception(suite_run_id, file_run_id, attributes)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 34 def create_file_run_exception(suite_run_id, file_run_id, attributes) response = post("/suite_runs/#{suite_run_id}/file_runs/#{file_run_id}/exceptions", file_run_exception: attributes) TestRescueClient::FileRunException.new(self, JSON.parse(response.body)) end
create_suite_run(sha:)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 20 def create_suite_run(sha:) response = post('/suite_runs', suite_run: { head_branch: 'master', sha: sha, title: 'Collect Pull Request Title from GitHub' }) TestRescueClient::SuiteRun.new(self, JSON.parse(response.body)) end
create_test_run(suite_run_id, file_run_id, attributes)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 53 def create_test_run(suite_run_id, file_run_id, attributes) response = post("/suite_runs/#{suite_run_id}/file_runs/#{file_run_id}/test_runs", test_run: attributes) TestRescueClient::TestRun.new(self, JSON.parse(response.body)) end
update_file_run(suite_run_id, file_run_id, attributes)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 49 def update_file_run(suite_run_id, file_run_id, attributes) patch("/suite_runs/#{suite_run_id}/file_runs/#{file_run_id}", file_run: attributes) end
Private Instance Methods
handle_webmock()
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 69 def handle_webmock instance = WebMock::Config.instance if instance.allow.nil? instance.allow = 'www.testrescue.com' elsif instance.allow.is_a?(Array) instance.allow.push('www.testrescue.com') unless instance.allow.include?('www.testrescue.com') else WebMock::Config.instance.allow = [WebMock::Config.instance.allow, 'www.testrescue.com'] end rescue NameError # no problem. webmock not being resident means this code wasn't needed anyway rescue # TODO: report this to sentry, but still try to move on end
headers()
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 60 def headers { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Api-Key' => @api_key, 'X-Api-Secret' => @secret } end
patch(path, body)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 90 def patch(path, body) handle_webmock url = "#{@endpoint}/repositories/#{@repository_id}#{path}" HTTParty.patch(url, body: body.to_json, headers: headers) end
post(path, body)
click to toggle source
# File lib/test_rescue_agent/test_rescue_client.rb, line 84 def post(path, body) handle_webmock url = "#{@endpoint}/repositories/#{@repository_id}#{path}" HTTParty.post(url, body: body.to_json, headers: headers) end