Sha256: 36c2bbafac71ba64a2e6683fee6480c5ac534b2e6e4419adcd91f9e2d73a03e0
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module GoogleAjax module Parser def self.parse(api, method, data) data = if defined? Rails ActiveSupport::JSON::decode(data) else JSON.parse(data) end process_errors(data) parser = PARSERS[api][method] response = data['responseData'] parser.is_a?(Symbol) ? send(parser, response) : parser.new(response) if response end def self.process_errors(data) status = data['responseStatus'] unless (200..206).include? status raise StandardError, data['responseDetails'] end end def self.parse_feed_list(data) data['entries'].map(&Feed::Feed.method(:new)) end def self.parse_one_feed(data) Feed::Feed.new(data['feed']) end PARSERS = { :feed => { :find => :parse_feed_list, :load => :parse_one_feed, :lookup => Feed::Feed }, :language => { :detect => Language::Language, :translate => Language::Translation }, :search => { :blogs => Search::Results, :books => Search::Results, :images => Search::Results, :local => Search::Results, :news => Search::Results, :video => Search::Results, :web => Search::Results } } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
googleajax-0.2.0 | lib/googleajax/parser.rb |