pig-ci-rails 0.2.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/pig_ci/api.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'httparty'
2
-
3
- class PigCI::Api
4
- include HTTParty
5
-
6
- def headers
7
- {
8
- 'Content-Type': 'application/json',
9
- 'X-ApiKey': PigCI.api_key
10
- }
11
- end
12
- end
13
-
14
- require 'pig_ci/api/reports'
@@ -1,43 +0,0 @@
1
- class PigCI::Api::Reports < PigCI::Api
2
- def initialize(reports: [])
3
- @reports = reports
4
- end
5
-
6
- def share!
7
- response = post_payload
8
- if response.success?
9
- puts I18n.t('pig_ci.api.reports.success')
10
- return
11
- end
12
-
13
- puts I18n.t('pig_ci.api.reports.error', error: JSON.parse(response.parsed_response || '{}')['error'])
14
- rescue JSON::ParserError => _e
15
- puts I18n.t('pig_ci.api.reports.api_error')
16
- rescue SocketError => e
17
- puts I18n.t('pig_ci.api.reports.error', error: e)
18
- rescue Net::OpenTimeout => e
19
- puts I18n.t('pig_ci.api.reports.error', error: e.inspect)
20
- end
21
-
22
- private
23
-
24
- def post_payload
25
- self.class.post(
26
- '/v1/reports',
27
- base_uri: PigCI.api_base_uri,
28
- verify: PigCI.api_verify_ssl?,
29
- body: payload,
30
- headers: headers
31
- )
32
- end
33
-
34
- def payload
35
- {
36
- library: 'pig-ci-rails',
37
- library_version: PigCI::VERSION,
38
- commit_sha1: PigCI.commit_sha1,
39
- head_branch: PigCI.head_branch,
40
- reports: @reports.collect { |report| report.to_payload_for(PigCI.run_timestamp) }
41
- }.to_json
42
- end
43
- end