Sha256: 6681125fea0f19241b089dc518407cbddb8d41cdc894c0b5e69b0974ddf0cf40

Contents?: true

Size: 1021 Bytes

Versions: 8

Compression:

Stored size: 1021 Bytes

Contents

require 'net/http'
require 'net/https'
require 'json'

module Benchmark
  module IPS
    class Share
      DEFAULT_URL = "https://benchmark.fyi"
      def initialize(report, job)
        @report = report
        @job = job
      end

      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
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
benchmark-ips-2.8.4 lib/benchmark/ips/share.rb
benchmark-ips-2.8.3 lib/benchmark/ips/share.rb
benchmark-ips-2.8.2 lib/benchmark/ips/share.rb
benchmark-ips-2.8.0 lib/benchmark/ips/share.rb
benchmark-ips-2.7.2 lib/benchmark/ips/share.rb
benchmark-ips-2.7.1 lib/benchmark/ips/share.rb
benchmark-ips-2.7.0 lib/benchmark/ips/share.rb
benchmark-ips-2.6.1 lib/benchmark/ips/share.rb