Class: Twingly::LiveFeed::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly/livefeed/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(document) ⇒ Result

Parse an API response body.

Parameters:

  • document (String)

    containing an API response XML.

Returns:

  • (Result)

    containing the result.

Raises:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twingly/livefeed/parser.rb', line 13

def parse(document)
  nokogiri = Nokogiri::XML(document)

  failure = nokogiri.at_xpath('/error')
  handle_failure(failure) if failure

  data_node = nokogiri.at_xpath('/twinglydata')
  handle_non_xml_document(document) unless data_node

  create_result(data_node)
end