Sha256: f38d4360e80e1810d9a153e89e9b24c9c86280984008ac78d1e653afefa0b7b8

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

module Instapusher
  class JobSubmission

    attr_reader :options, :debug, :job_status_url, :response_body

    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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
instapusher-0.0.34 lib/instapusher/job_submission.rb
instapusher-0.0.33 lib/instapusher/job_submission.rb
instapusher-0.0.32 lib/instapusher/job_submission.rb
instapusher-0.0.31 lib/instapusher/job_submission.rb