class Sauce::Job
Interact with a Sauce
Labs selenium jobs as if it were a ruby object
Attributes
browser[RW]
browser_version[RW]
creation_time[RW]
custom_data[RW]
end_time[RW]
error[RW]
id[RW]
log_url[RW]
name[RW]
os[RW]
owner[RW]
passed[RW]
public[RW]
start_time[RW]
status[RW]
video_url[RW]
Public Class Methods
account()
click to toggle source
Get the class @@client. TODO: Consider metaprogramming this away
# File lib/sauce/job.rb, line 29 def self.account @@account end
account=(account)
click to toggle source
Set the class @@client. TODO: Consider metaprogramming this away
# File lib/sauce/job.rb, line 35 def self.account=(account) @@account = account end
all(options={})
click to toggle source
Misnomer: Gets the most recent 100 jobs TODO: Allow/automate paging
# File lib/sauce/job.rb, line 49 def self.all(options={}) url = "jobs" url += "?full=true" if options[: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()
click to toggle source
Get the class @@client. TODO: Consider metaprogramming this away
# File lib/sauce/job.rb, line 17 def self.client @@client end
client=(client)
click to toggle source
Set the class @@client. TODO: Consider metaprogramming this away
# File lib/sauce/job.rb, line 23 def self.client=(client) @@client = client end
destroy()
click to toggle source
# File lib/sauce/job.rb, line 57 def self.destroy self.all.each { |tunnel| tunnel.destroy } end
find(options={})
click to toggle source
# File lib/sauce/job.rb, line 61 def self.find(options={}) if options.class == String id = options elsif options.class == Hash id = options[: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()
click to toggle source
# File lib/sauce/job.rb, line 39 def self.first self.all.first end
last()
click to toggle source
# File lib/sauce/job.rb, line 43 def self.last self.all.last end
new(options)
click to toggle source
Creates an instance representing a job.
# File lib/sauce/job.rb, line 78 def initialize(options) build!(options) @client = Sauce::Client.new end
Public Instance Methods
delete()
click to toggle source
# File lib/sauce/job.rb, line 127 def delete raise CannonDeleteJobError("Cannot delete jobs via Sauce Labs' REST API currently") end
refresh!()
click to toggle source
Retrieves the latest information on this job from the Sauce
Labs' server
# 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()
click to toggle source
Save/update the current information for the job
# 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={})
click to toggle source
# File lib/sauce/job.rb, line 100 def to_json(options={}) 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 } options[:except].each { |key| json.delete(key) } if options[:except] json = json.select { |key,value| options[:only].include? key } if options[:only] return json.to_json end
Protected Instance Methods
build!(options)
click to toggle source
Sets all internal variables from a hash
# File lib/sauce/job.rb, line 134 def build!(options) # Massage JSON options.each { |key,value| options[key] = false if options[key] == "false" } @id = options["id"] @owner = options["owner"] @status = options["status"] @error = options["error"] @name = options["name"] @browser = options["browser"] @browser_version = options["browser_version"] @os = options["os"] @creation_time = options["creation_time"].to_i @start_time = options["start_time"].to_i @end_time = options["end_time"].to_i @video_url = options["video_url"] @log_url = options["log_url"] @public = options["public"] @tags = options["tags"] @passed = options["passed"] @custom_data = options['custom-data'] raise NoIDError if @id.nil? or @id.empty? end