# class Benchmark::IPS::Share

### Constants

DEFAULT_URL

### Public Class Methods

new(report, job) click to toggle source

    # File lib/benchmark/ips/share.rb, line 11
    def initialize(report, job)
      @report = report
      @job = job
    end

### Public Instance Methods

share() click to toggle source

    # 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, initheader = {'Content-Type' =>'application/json'})

      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