lib/job.rb in sauce-0.4.3 vs lib/job.rb in sauce-0.5.0

- old
+ new

@@ -47,11 +47,14 @@ end # Misnomer: Gets the most recent 100 jobs # TODO: Allow/automate paging def self.all(options={}) - responses = JSON.parse @@client["jobs/full"].get + 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 def self.destroy self.all.each { |tunnel| tunnel.destroy } @@ -63,32 +66,39 @@ elsif options.class == Hash id = options[:id] end #puts "GET-URL: #{@@client.url}jobs/#{id}" - Sauce::Job.new JSON.parse(@@client["jobs/#{id}"].get) + 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) end # Retrieves the latest information on this job from the Sauce Labs' server def refresh! - response = JSON.parse @@client["jobs/#{@id}"].get + response = JSON.parse @@client["jobs/#{@id}"].get.body #puts "\tjob refresh with: #{response}" build! response self end # Save/update the current information for the job def save - response = JSON.parse(@@client["jobs/#{@id}"]. self.to_json, :content_type => :json, :accept => :json) + #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 - def self.to_json(options={}) + def to_json(options={}) json = { :id => @id, :owner => @owner, :status => @status, :error => @error, @@ -106,20 +116,24 @@ } options[:except].each { |key| json.delete(key) } if options[:except] json = json.select { |key,value| options[:only].include? key } if options[:only] - return json + return json.to_json end def delete raise CannonDeleteJobError("Cannot delete jobs via Sauce Labs' REST API currently") end 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"] @status = options["status"] @error = options["error"] @name = options["name"]