<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,27 +1,29 @@
 module Simplificator
-  module Webthumb 
+  module Webthumb
     class Job &lt; Base
-      
+
       attr_reader :duration_estimate, :submission_datetime, :cost, :job_id, :url
-      
+
       # Constant for the status attribute when job is beeing processed
       STATUS_PROCESSING = 100
       # Constant for the status attribute when job is done
       STATUS_PICKUP = 200
-    
+
       # Factory method to build a Job object from a REXML xml element
       def self.from_thumbnail_xml(api_key, xml)
         job_element = REXML::XPath.first(xml, '/webthumb/jobs/job')
+        return nil if job_element.nil?
+
         submission_datetime = self.parse_webthumb_datetime(job_element.attributes['time'])
         Job.new(api_key, job_element.text, job_element.attributes['url'], submission_datetime, job_element.attributes['estimate'].to_i, job_element.attributes['cost'].to_i)
-      end 
+      end
       # Factory method to create a Job object from a status XML.
       # this does not set all attributes of the Job (url, duration_estimate, cost) since the API of webthumb does not
       # return the same information on job creation and status requests.
       def self.from_status_xml(api_key, xml)
         status_element = REXML::XPath.first(xml, '/webthumb/jobStatus/status')
         submission_datetime = self.parse_webthumb_datetime(status_element.attributes['submissionTime'])
-        job = Job.new(api_key, status_element.attributes['id'], nil, submission_datetime, 5, nil, 
+        job = Job.new(api_key, status_element.attributes['id'], nil, submission_datetime, 5, nil,
           status_element.text == 'Complete' ? STATUS_PICKUP : STATUS_PROCESSING)
       end
       # Constructor.
@@ -42,7 +44,7 @@ module Simplificator
         @status = status
         @cache = {}
       end
-    
+
       # Checks the status of the job on webthumb server.
       # Returns one of the STATUS_XXX constants from Base.
       # A call to this method updates the @status attribute.
@@ -54,7 +56,7 @@ module Simplificator
         end
         @status
       end
-      
+
       def fetch_when_complete(size = :small)
         while not pickup?
           sleep @duration_estimate
@@ -62,7 +64,7 @@ module Simplificator
         end
         fetch(size)
       end
-      
+
       # Fetch an image from the webthumb server.
       # If the job has not yet finished then the server will return an error so check status first or use fetch_when_complete()
       # Images are cached in the context of this Job so consequent calls are not requested from server again.
@@ -74,7 +76,7 @@ module Simplificator
         end
         @cache[size]
       end
-      
+
       # Write the data to disk.
       # *data: the bytes of the image as returned by fetch/fetch_when_complete
       # *name: a filename
@@ -87,16 +89,16 @@ module Simplificator
           file
         end
       end
-      
+
       # Is the status attribute set to STATUS_PICKUP ?
       def pickup?
         @status == STATUS_PICKUP
-      end	
+      end
       # Is the status attribute set to STATUS_PROCESSING ?
       def processing?
         @status == STATUS_PROCESSING
       end
-      
+
       private
       def build_fetch_xml(size = :small)
         raise WebthumbException.new(&quot;size parameter must be one of #{VALID_SIZES.join(', ')} but was #{size}&quot;) unless Base::VALID_SIZES.include?(size)
@@ -118,4 +120,4 @@ module Simplificator
       end
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>lib/rwebthumb/job.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,18 +1,25 @@
 require File.join(File.dirname(__FILE__), 'helper')
 class JobTest &lt; Test::Unit::TestCase
-  def setup()
-    xml = &lt;&lt;-EOF
-      &lt;webthumb&gt;
-        &lt;jobs&gt;
-          &lt;job estimate='20' time='2008-02-27 12:49:48' url='http://blog.joshuaeichorn.com' cost='1'&gt;wt47c5f71c37c3a&lt;/job&gt;
-        &lt;/jobs&gt;
-      &lt;/webthumb&gt;
-    EOF
+  JOB_XML = &lt;&lt;-EOF
+    &lt;webthumb&gt;
+      &lt;jobs&gt;
+        &lt;job estimate='20' time='2008-02-27 12:49:48' url='http://blog.joshuaeichorn.com' cost='1'&gt;wt47c5f71c37c3a&lt;/job&gt;
+      &lt;/jobs&gt;
+    &lt;/webthumb&gt;
+  EOF
+
+  JOBLESS_XML = &lt;&lt;-EOF
+    &lt;webthumb&gt;
+    &lt;/webthumb&gt;
+  EOF
+
+  def setup_job_from_xml(xml)
     job_xml = REXML::Document.new(xml)
     @job = Job.from_thumbnail_xml('1234', job_xml)
   end
-  def test_from_thumbnail_xml
 
+  def test_from_thumbnail_xml
+    setup_job_from_xml(JOB_XML)
     assert_equal('1234', @job.api_key)
     assert_equal(20, @job.duration_estimate)
     assert_equal(Time.parse('2008-02-27 19:49:48 UTC'), @job.submission_datetime)
@@ -21,15 +28,21 @@ class JobTest &lt; Test::Unit::TestCase
     assert_equal('wt47c5f71c37c3a', @job.job_id)
   end
 
-
   def test_build_fetch()
+    setup_job_from_xml(JOB_XML)
     xml = @job.send(:build_fetch_xml)
     assert_equal('small', REXML::XPath.first(xml, 'fetch/size').text)
     assert_equal('wt47c5f71c37c3a', REXML::XPath.first(xml, 'fetch/job').text)
   end
 
   def test_build_status_xml()
+    setup_job_from_xml(JOB_XML)
     xml = @job.send(:build_status_xml)
     assert_equal('wt47c5f71c37c3a', REXML::XPath.first(xml, 'status/job').text)
   end
+
+  def test_from_thumbnail_xml_without_any_jobs()
+    setup_job_from_xml(JOBLESS_XML)
+    assert_nil @job
+  end
 end</diff>
      <filename>test/job_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ba6aaca09a6749538c507982342138ddd69d7f4f</id>
    </parent>
  </parents>
  <author>
    <name>Ryan McGeary</name>
    <email>ryanongit@mcgeary.org</email>
  </author>
  <url>http://github.com/simplificator/rwebthumb/commit/04966931e3a0a128b71357165d37bd380be95b02</url>
  <id>04966931e3a0a128b71357165d37bd380be95b02</id>
  <committed-date>2009-06-10T17:52:59-07:00</committed-date>
  <authored-date>2009-06-10T17:51:52-07:00</authored-date>
  <message>Return a nil job for a webthumb request of an invalid URL

* Webthumb responds with an empty list of jobs for invalid URLs
* This fixes an otherwise NoMethodError in Job.from_thumbnail_xml</message>
  <tree>3296ee6d49c1307dcef6353ff1263e9a0bd8387e</tree>
  <committer>
    <name>Ryan McGeary</name>
    <email>ryanongit@mcgeary.org</email>
  </committer>
</commit>
