Sha256: cd3d01f5e17605cca7833a0b882716d1d1e0c962e192081fd97f8b9cb62ed8c7

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'json'
require 'net/http'

require_relative "worker/version"
require_relative "worker/rspec" if defined? RSpec

module AppVeyor::Worker
  def self.skip?
    !api
  end

  def self.message msg, details=nil
    x = api or return
    body = JSON.generate category: 'info',
      message: msg,
      details: details
    x.post '/api/build/messages',
      body,
      'Content-Length'=>body.length.to_s,
      'Content-Type'=>'application/json'
  end

  def self.test info
    x = api or return
    body = JSON.generate info
    x.post '/api/tests',
      body,
      'Content-Length'=>body.length.to_s,
      'Content-Type'=>'application/json'
  end

  def self.env envs
    x = api or return
    envs.each do |k, v|
      body = JSON.generate name: k, value: v
      x.post '/api/build/variables',
        body,
        'Content-Length'=>body.length.to_s,
        'Content-Type'=>'application/json'
    end
  end

  private

  def self.api
    return if false===@http
    return @http if @http
    unless z = ENV['APPVEYOR_API_URL']
      @http = false
      return
    end
    z = URI z
    @http = x = Net::HTTP.start z.host, z.port
    x.use_ssl='https'==z.scheme
    x
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appveyor-worker-0.2.0 lib/appveyor/worker.rb