Class: Benchmark::IPS::Share
- Inherits:
-
Object
- Object
- Benchmark::IPS::Share
- Defined in:
- lib/benchmark/ips/share.rb
Constant Summary collapse
- DEFAULT_URL =
"https://benchmark.fyi"
Instance Method Summary collapse
-
#initialize(report, job) ⇒ Share
constructor
A new instance of Share.
- #share ⇒ Object
Constructor Details
#initialize(report, job) ⇒ Share
Returns a new instance of Share.
9 10 11 12 |
# File 'lib/benchmark/ips/share.rb', line 9 def initialize(report, job) @report = report @job = job end |
Instance Method Details
#share ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/benchmark/ips/share.rb', line 14 def share base = (ENV['SHARE_URL'] || DEFAULT_URL) url = URI(File.join(base, "reports")) req = Net::HTTP::Post.new(url) data = { "entries" => @report.data, "options" => { "compare" => @job.compare? } } req.body = JSON.generate(data) http = Net::HTTP.new(url.hostname, url.port) if url.scheme == "https" http.use_ssl = true http.ssl_version = :TLSv1_2 end res = http.start do |h| h.request req end if Net::HTTPOK === res data = JSON.parse res.body puts "Shared at: #{File.join(base, data["id"])}" else puts "Error sharing report" end end |