Sha256: e49750497cc51675813f509f70d0a9f1a0a145439b911a87f33d7d63db264532

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

class JobSubmission

  attr_reader :options, :debug, :job_status_url

  DEFAULT_HOSTNAME = 'instapusher.com'

  def initialize debug, options
    @debug = debug
    @options = options
  end

  def success?
    job_status_url && job_status_url != ""
  end

  def pre_submission_feedback_to_user
    puts "url to hit: #{url_to_submit_job.inspect}"
    puts "options being passed to the url: #{options.inspect}"
    puts "connecting to #{url_to_submit_job} to send data"
  end

  def feedback_to_user
    puts 'The appliction will be deployed to: ' + response_body['heroku_url']
    puts 'Monitor the job status at: ' + job_status_url
    cmd = "open #{job_status_url}"
    `#{cmd}`
  end

  def error_message
    response_body['error']
  end

  def submit_the_job
    pre_submission_feedback_to_user if debug

    response = Net::HTTP.post_form URI.parse(url_to_submit_job), options
    @response_body  = ::JSON.parse(response.body)
    puts "response_body: #{response_body.inspect}" if debug
    @job_status_url = response_body['status'] || response_body['job_status_url']
  end

  def url_to_submit_job
    @url ||= begin
        hostname =  if options[:local]
                      "localhost:3000" 
                    else
                      ENV['INSTAPUSHER_HOST'] || DEFAULT_HOSTNAME
                    end
        "http://#{hostname}/heroku.json"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
instapusher-0.0.29 lib/instapusher/job_submission.rb
instapusher-0.0.28 lib/instapusher/job_submission.rb
instapusher-0.0.27 lib/instapusher/job_submission.rb