Sha256: 31c80bd1bdf1dfc2d283c66e20d0327f17c6fae89aa8d4803af244e2c65b9f57

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

module Instapusher2
  class JobSubmission

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

    DEFAULT_HOSTNAME = 'instapusher.net'

    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 application 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}/api/v1/jobs.json"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
instapusher2-0.0.4 lib/instapusher2/job_submission.rb
instapusher2-0.0.3 lib/instapusher2/job_submission.rb