Class: Instapusher2::JobSubmission

Inherits:
Object
  • Object
show all
Defined in:
lib/instapusher2/job_submission.rb

Constant Summary collapse

DEFAULT_HOSTNAME =
'instapusher.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug, options) ⇒ JobSubmission

Returns a new instance of JobSubmission.



8
9
10
11
# File 'lib/instapusher2/job_submission.rb', line 8

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

Instance Attribute Details

#debugObject (readonly)

Returns the value of attribute debug.



4
5
6
# File 'lib/instapusher2/job_submission.rb', line 4

def debug
  @debug
end

#job_status_urlObject (readonly)

Returns the value of attribute job_status_url.



4
5
6
# File 'lib/instapusher2/job_submission.rb', line 4

def job_status_url
  @job_status_url
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/instapusher2/job_submission.rb', line 4

def options
  @options
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



4
5
6
# File 'lib/instapusher2/job_submission.rb', line 4

def response_body
  @response_body
end

Instance Method Details

#error_messageObject



30
31
32
# File 'lib/instapusher2/job_submission.rb', line 30

def error_message
  response_body['error']
end

#feedback_to_userObject



23
24
25
26
27
28
# File 'lib/instapusher2/job_submission.rb', line 23

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

#pre_submission_feedback_to_userObject



17
18
19
20
21
# File 'lib/instapusher2/job_submission.rb', line 17

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

#submit_the_jobObject



34
35
36
37
38
39
40
41
# File 'lib/instapusher2/job_submission.rb', line 34

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

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/instapusher2/job_submission.rb', line 13

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

#url_to_submit_jobObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/instapusher2/job_submission.rb', line 43

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