Module: Thumbnail::Response

Defined in:
lib/thumbnail/response.rb

Overview

Defined Under Namespace

Classes: Failure, Success

Class Method Summary collapse

Class Method Details

.build(xml) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/thumbnail/response.rb', line 22

def self.build(xml)
  doc = Hpricot.XML(xml)
  results = []
  (doc/'//aws:ThumbnailResponse'/'aws:Response').each do |res|
    result = {}
    result[:request_id] = cleanup(res.at('aws:OperationRequest').inner_text)
    t = (res/'aws:ThumbnailResult').first 
    result[:thumbnail] = {:url => cleanup(t.at('aws:Thumbnail').inner_text).gsub(/\&/, '&'), 
                              :exists => (t.at('aws:Thumbnail').attributes["Exists"] == "true"), 
                              :request_url => cleanup(t.at('aws:RequestUrl').inner_text)}
    results << result
  end
  
  unless results.empty?
    Success.new(:parsed => results, :xml => xml, :hpricot => doc)
  else
    Failure.new(:xml => xml, :hpricot => doc)
  end
end

.cleanup(a) ⇒ Object



42
43
44
# File 'lib/thumbnail/response.rb', line 42

def self.cleanup(a)
  a.gsub(/\n|\s/, '')
end