Class: SauceWhisk::Jobs

Inherits:
Object
  • Object
show all
Extended by:
RestRequestBuilder
Defined in:
lib/sauce_whisk/jobs.rb

Class Method Summary collapse

Methods included from RestRequestBuilder

auth_details, delete, fully_qualified_resource, get, make_request, post, put, request_from_rest_client

Class Method Details

.allObject



13
14
15
16
# File 'lib/sauce_whisk/jobs.rb', line 13

def self.all
  all_jobs = JSON.parse get
  all_jobs.map {|job| Job.new(job)}
end

.change_status(job_id, status) ⇒ Object



18
19
20
21
22
# File 'lib/sauce_whisk/jobs.rb', line 18

def self.change_status(job_id, status)
  put job_id, {"passed" => status}.to_json
rescue StandardError => e
  SauceWhisk.logger.error "Unable to change_status for #{job_id} to #{status}\nReason: #{e.to_s}"
end

.delete_job(job_id) ⇒ Object



60
61
62
# File 'lib/sauce_whisk/jobs.rb', line 60

def self.delete_job(job_id)
  delete "#{job_id}"
end

.fail_job(job_id) ⇒ Object



28
29
30
# File 'lib/sauce_whisk/jobs.rb', line 28

def self.fail_job(job_id)
  change_status(job_id, false)
end

.fetch(job_id) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/sauce_whisk/jobs.rb', line 39

def self.fetch(job_id)
  job_hash = JSON.parse(get job_id)
  assets = job_assets job_id
  job_hash.merge! assets
rescue SauceWhisk::JobNotComplete
  # Always succeed
ensure
  return Job.new(job_hash)
end

.fetch!(job_id) ⇒ Object



49
50
51
52
53
54
# File 'lib/sauce_whisk/jobs.rb', line 49

def self.fetch!(job_id)
  job_hash = JSON.parse(get job_id)
  assets = job_assets job_id
  job_hash.merge! assets
  Job.new job_hash
end

.fetch_asset(job_id, asset) ⇒ Object



64
65
66
# File 'lib/sauce_whisk/jobs.rb', line 64

def self.fetch_asset(job_id, asset)
  asset = get "#{job_id}/assets/#{asset}"
end

.job_assets(job_id) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/sauce_whisk/jobs.rb', line 68

def self.job_assets(job_id)
  assets = JSON.parse get "#{job_id}/assets"
  screenshots = assets["screenshots"]

  {"screenshot_urls" => screenshots}
rescue RestClient::BadRequest
  raise SauceWhisk::JobNotComplete
end

.pass_job(job_id) ⇒ Object



24
25
26
# File 'lib/sauce_whisk/jobs.rb', line 24

def self.pass_job(job_id)
  change_status(job_id, true)
end

.resourceObject



9
10
11
# File 'lib/sauce_whisk/jobs.rb', line 9

def self.resource
  "#{SauceWhisk.username}/jobs"
end

.save(job) ⇒ Object



32
33
34
35
36
37
# File 'lib/sauce_whisk/jobs.rb', line 32

def self.save(job)
  fields_to_save = job.updated_fields.each_with_object(Hash.new) do |field, hsh|
    hsh[field] = job.send(field.to_s)
  end
  put job.id, fields_to_save.to_json
end

.stop(job_id) ⇒ Object



56
57
58
# File 'lib/sauce_whisk/jobs.rb', line 56

def self.stop(job_id)
  put "#{job_id}/stop", {}
end