Sha256: a2ce699424905459f171f72e2e05e7cf69a39563f1a236364faa5f28d14f1caa
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require 'uri' require 'json' require 'rest-client' require File.expand_path("../exceptions", File.dirname(__FILE__)) require File.expand_path("../request_success", File.dirname(__FILE__)) module Heracles module Wrapper module Request end end end class Heracles::Wrapper::Request::CreateJob attr_reader( :config, :workflow_name, :parent_job_id, :parameters, :url ) def initialize(config, options = {}) @config = config @workflow_name = options.fetch(:workflow_name) @parent_job_id = options.fetch(:parent_job_id, nil) @parameters = options.fetch(:parameters, {}) @url = URI.parse(File.join(config.heracles_base_url, 'jobs')) end def as_json { :api_key => config.api_key, :job => { :workflow_name => workflow_name, :parameters => parameters } }.tap {|hash| hash[:job][:parent_job_id] = parent_job_id if parent_job_id } end # Need to accept a self-signed cert. # Hits a given URL # Syncrhonously waits for response. def call request_decorator.call(make_request) rescue RestClient::Exception => e raise Heracles::Wrapper::RequestFailure.new(e.response) end protected def make_request RestClient.post( url.to_s, as_json, { :content_type => :json, :accept => :json, :verify_ssl => OpenSSL::SSL::VERIFY_NONE } ) end def request_decorator Heracles::Wrapper::RequestSuccess.method(:new) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
heracles-wrapper-0.0.3 | lib/heracles-wrapper/request/create_job.rb |