Sha256: a1c1a77b16668cf161a7a12b1df56ed969ae74dacfb3b4fb6ce8c2a7b0c265fc

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

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

module Benchmark
  module IPS
    class Share
      DEFAULT_URL = "https://ips.fastruby.io"
      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

9 entries across 9 versions & 1 rubygems

Version Path
benchmark-ips-2.14.0 lib/benchmark/ips/share.rb
benchmark-ips-2.13.0 lib/benchmark/ips/share.rb
benchmark-ips-2.12.0 lib/benchmark/ips/share.rb
benchmark-ips-2.11.0 lib/benchmark/ips/share.rb
benchmark-ips-2.10.0 lib/benchmark/ips/share.rb
benchmark-ips-2.9.3 lib/benchmark/ips/share.rb
benchmark-ips-2.9.2 lib/benchmark/ips/share.rb
benchmark-ips-2.9.1 lib/benchmark/ips/share.rb
benchmark-ips-2.9.0 lib/benchmark/ips/share.rb