Class: OverridesTracker::Api
- Inherits:
-
Object
- Object
- OverridesTracker::Api
- Defined in:
- lib/overrides_tracker/api.rb
Constant Summary collapse
- API_HOST =
ENV['OVERRIDES_TRACKER_DEVELOPMENT'] ? "localhost:3000" : "overrides.io"
- API_PROTOCOL =
ENV['OVERRIDES_TRACKER_DEVELOPMENT'] ? "http" : "https"
- API_DOMAIN =
"#{API_PROTOCOL}://#{API_HOST}"
- API_BASE =
"#{API_DOMAIN}/api/v1"
Class Method Summary collapse
- .build_client(uri) ⇒ Object
- .report_build(api_token, branch_name, last_commit_id, last_commit_name, file_path) ⇒ Object
Class Method Details
.build_client(uri) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/overrides_tracker/api.rb', line 37 def self.build_client(uri) client = Net::HTTP.new(uri.host, uri.port) client.use_ssl = true if uri.port == 443 client.verify_mode = OpenSSL::SSL::VERIFY_NONE client end |
.report_build(api_token, branch_name, last_commit_id, last_commit_name, file_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/overrides_tracker/api.rb', line 12 def self.report_build(api_token, branch_name, last_commit_id, last_commit_name, file_path) disable_net_blockers! uri = URI(API_DOMAIN) client = build_client(uri) request = Net::HTTP::Post.new('/api/v1/builds') form_data = [['api_token',api_token], ['branch_name', branch_name],['build_provider_id', last_commit_id], ['build_name', last_commit_name], ['result_file', File.open(file_path)]] request.set_form form_data, 'multipart/form-data' puts ' ' puts '===========' puts 'Sending report to Overrides.io...' begin response = client.request(request) response_hash = JSON.load(response.body.to_str) puts 'Success.'.green rescue SocketError => each puts 'Failed to report to the Overrides API.'.red end end |