Class: Sauce::Job
- Inherits:
-
Object
- Object
- Sauce::Job
- Defined in:
- lib/sauce/job.rb
Overview
Interact with a Sauce Labs selenium jobs as if it were a ruby object
Defined Under Namespace
Classes: CannotDeleteJobError
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
-
#browser_version ⇒ Object
Returns the value of attribute browser_version.
-
#creation_time ⇒ Object
Returns the value of attribute creation_time.
-
#custom_data ⇒ Object
Returns the value of attribute custom_data.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#error ⇒ Object
Returns the value of attribute error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#log_url ⇒ Object
Returns the value of attribute log_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#os ⇒ Object
Returns the value of attribute os.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#passed ⇒ Object
Returns the value of attribute passed.
-
#public ⇒ Object
Returns the value of attribute public.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#video_url ⇒ Object
Returns the value of attribute video_url.
Class Method Summary collapse
-
.account ⇒ Object
Get the class @@client.
-
.account=(account) ⇒ Object
Set the class @@client.
-
.all(options = {}) ⇒ Object
Misnomer: Gets the most recent 100 jobs TODO: Allow/automate paging.
-
.client ⇒ Object
Get the class @@client.
-
.client=(client) ⇒ Object
Set the class @@client.
- .destroy ⇒ Object
- .find(options = {}) ⇒ Object
- .first ⇒ Object
- .last ⇒ Object
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(options) ⇒ Job
constructor
Creates an instance representing a job.
-
#refresh! ⇒ Object
Retrieves the latest information on this job from the Sauce Labs’ server.
-
#save ⇒ Object
Save/update the current information for the job.
- #to_json(options = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
10 11 12 |
# File 'lib/sauce/job.rb', line 10 def browser @browser end |
#browser_version ⇒ Object
Returns the value of attribute browser_version.
10 11 12 |
# File 'lib/sauce/job.rb', line 10 def browser_version @browser_version end |
#creation_time ⇒ Object
Returns the value of attribute creation_time.
11 12 13 |
# File 'lib/sauce/job.rb', line 11 def creation_time @creation_time end |
#custom_data ⇒ Object
Returns the value of attribute custom_data.
13 14 15 |
# File 'lib/sauce/job.rb', line 13 def custom_data @custom_data end |
#end_time ⇒ Object
Returns the value of attribute end_time.
11 12 13 |
# File 'lib/sauce/job.rb', line 11 def end_time @end_time end |
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/sauce/job.rb', line 9 def error @error end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/sauce/job.rb', line 9 def id @id end |
#log_url ⇒ Object
Returns the value of attribute log_url.
12 13 14 |
# File 'lib/sauce/job.rb', line 12 def log_url @log_url end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/sauce/job.rb', line 10 def name @name end |
#os ⇒ Object
Returns the value of attribute os.
10 11 12 |
# File 'lib/sauce/job.rb', line 10 def os @os end |
#owner ⇒ Object
Returns the value of attribute owner.
9 10 11 |
# File 'lib/sauce/job.rb', line 9 def owner @owner end |
#passed ⇒ Object
Returns the value of attribute passed.
13 14 15 |
# File 'lib/sauce/job.rb', line 13 def passed @passed end |
#public ⇒ Object
Returns the value of attribute public.
12 13 14 |
# File 'lib/sauce/job.rb', line 12 def public @public end |
#start_time ⇒ Object
Returns the value of attribute start_time.
11 12 13 |
# File 'lib/sauce/job.rb', line 11 def start_time @start_time end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/sauce/job.rb', line 9 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
12 13 14 |
# File 'lib/sauce/job.rb', line 12 def @tags end |
#video_url ⇒ Object
Returns the value of attribute video_url.
12 13 14 |
# File 'lib/sauce/job.rb', line 12 def video_url @video_url end |
Class Method Details
.account ⇒ Object
Get the class @@client. TODO: Consider metaprogramming this away
29 30 31 |
# File 'lib/sauce/job.rb', line 29 def self.account @@account end |
.account=(account) ⇒ Object
Set the class @@client. TODO: Consider metaprogramming this away
35 36 37 |
# File 'lib/sauce/job.rb', line 35 def self.account=(account) @@account = account end |
.all(options = {}) ⇒ Object
Misnomer: Gets the most recent 100 jobs TODO: Allow/automate paging
49 50 51 52 53 54 55 |
# File 'lib/sauce/job.rb', line 49 def self.all(={}) url = "jobs" url += "?full=true" if [:full] #unless options[:id_only] responses = @@client[url].get responses = JSON.parse responses.to_s return responses.collect{|response| Sauce::Job.new(response)} end |
.client ⇒ Object
Get the class @@client. TODO: Consider metaprogramming this away
17 18 19 |
# File 'lib/sauce/job.rb', line 17 def self.client @@client end |
.client=(client) ⇒ Object
Set the class @@client. TODO: Consider metaprogramming this away
23 24 25 |
# File 'lib/sauce/job.rb', line 23 def self.client=(client) @@client = client end |
.destroy ⇒ Object
57 58 59 |
# File 'lib/sauce/job.rb', line 57 def self.destroy self.all.each { |tunnel| tunnel.destroy } end |
.find(options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sauce/job.rb', line 61 def self.find(={}) if .class == String id = elsif .class == Hash id = [:id] end @@client ||= Sauce::Client.new #puts "GET-URL: #{@@client.url}jobs/#{id}" response = @@client["jobs/#{id}"].get # TODO: Return nil if bad response Sauce::Job.new JSON.parse(response.to_s) end |
.first ⇒ Object
39 40 41 |
# File 'lib/sauce/job.rb', line 39 def self.first self.all.first end |
.last ⇒ Object
43 44 45 |
# File 'lib/sauce/job.rb', line 43 def self.last self.all.last end |
Instance Method Details
#delete ⇒ Object
127 128 129 |
# File 'lib/sauce/job.rb', line 127 def delete raise CannonDeleteJobError("Cannot delete jobs via Sauce Labs' REST API currently") end |
#refresh! ⇒ Object
Retrieves the latest information on this job from the Sauce Labs’ server
84 85 86 87 88 89 |
# File 'lib/sauce/job.rb', line 84 def refresh! response = JSON.parse @@client["jobs/#{@id}"].get.body #puts "\tjob refresh with: #{response}" build! response self end |
#save ⇒ Object
Save/update the current information for the job
92 93 94 95 96 97 98 |
# File 'lib/sauce/job.rb', line 92 def save #puts "Saving job:\n -X PUT #{@@client['jobs']}/#{@id} -H 'Content-Type: application/json' -d '#{self.to_json}'" response = @client["jobs/#{@id}"].put(self.to_json, {:content_type => :json, :accept => :json}).body JSON.parse(response) end |
#to_json(options = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/sauce/job.rb', line 100 def to_json(={}) json = { :id => @id, :'custom-data' => @custom_data, :owner => @owner, :status => @status, :error => @error, :name => @name, :browser => @browser, :browser_version => @browser_version, :os => @os, :creation_time => @creation_time, :start_time => @start_time, :end_time => @end_time, :video_url => @video_url, :log_url => @log_url, :public => @public, :tags => @tags, :passed => @passed } [:except].each { |key| json.delete(key) } if [:except] json = json.select { |key,value| [:only].include? key } if [:only] return json.to_json end |