lib/sauce/job.rb in sauce-1.0.2 vs lib/sauce/job.rb in sauce-2.0.0
- old
+ new
@@ -1,23 +1,25 @@
+require 'sauce/client'
+
module Sauce
# Interact with a Sauce Labs selenium jobs as if it were a ruby object
class Job
class CannotDeleteJobError < StandardError; end #:nodoc
attr_accessor :id, :owner, :status, :error
attr_accessor :name, :browser, :browser_version, :os
attr_accessor :creation_time, :start_time, :end_time
attr_accessor :public, :video_url, :log_url, :tags
- attr_accessor :passed
+ attr_accessor :passed, :custom_data
# Get the class @@client.
# TODO: Consider metaprogramming this away
def self.client
@@client
end
-
+
# Set the class @@client.
# TODO: Consider metaprogramming this away
def self.client=(client)
@@client = client
end
@@ -62,21 +64,22 @@
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
# Creates an instance representing a job.
def initialize(options)
build!(options)
+ @client = Sauce::Client.new
end
# Retrieves the latest information on this job from the Sauce Labs' server
def refresh!
response = JSON.parse @@client["jobs/#{@id}"].get.body
@@ -86,19 +89,20 @@
end
# Save/update the current information for the job
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,
+ response = @client["jobs/#{@id}"].put(self.to_json,
{:content_type => :json,
:accept => :json}).body
JSON.parse(response)
end
def to_json(options={})
json = {
:id => @id,
+ :'custom-data' => @custom_data,
:owner => @owner,
:status => @status,
:error => @error,
:name => @name,
:browser => @browser,
@@ -114,11 +118,11 @@
: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
def delete
raise CannonDeleteJobError("Cannot delete jobs via Sauce Labs' REST API currently")
@@ -126,11 +130,10 @@
protected
# Sets all internal variables from a hash
def build!(options)
- #puts "\tBuild with: #{options.inspect}"
# Massage JSON
options.each { |key,value| options[key] = false if options[key] == "false" }
@id = options["id"]
@owner = options["owner"]
@@ -146,9 +149,10 @@
@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
end
end