Class: Benchmark::IPS::Share
- Inherits:
-
Object
- Object
- Benchmark::IPS::Share
- Defined in:
- lib/benchmark/ips/share.rb
Constant Summary collapse
- DEFAULT_URL =
"https://ips.fastruby.io"
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.
11 12 13 14 |
# File 'lib/benchmark/ips/share.rb', line 11 def initialize(report, job) @report = report @job = job end |
Instance Method Details
#share ⇒ Object
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 46 47 |
# File 'lib/benchmark/ips/share.rb', line 16 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 |