Class: FeedProcessor::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_processor/util.rb

Class Method Summary collapse

Class Method Details

.decode_content(res) ⇒ Object

shamelessly stolen from feedzirra



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/feed_processor/util.rb', line 4

def self.decode_content(res)
  case res['content-encoding']
  when 'gzip'
    begin
      gz =  Zlib::GzipReader.new(StringIO.new(res.body))
      xml = gz.read
      gz.close
    rescue Zlib::GzipFile::Error 
      # Maybe this is not gzipped?
      xml = res.body
    end
  when 'deflate'
    xml = Zlib::Inflate.inflate(res.body)
  else
    xml = res.body
  end

  xml
end