Class: Craigslist::API::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/craigslist/api/response_parser.rb

Overview

Turns the RSS document returned by validate/post into a ResultSet.

Element lookups use the literal prefixed names as they appear on the wire rather than XPath namespace resolution, which REXML handles awkwardly when a default namespace is in play.

Constant Summary collapse

UPLOAD_ID_PREFIX =

Prefix craigslist puts on the channel description in post mode.

"upload-id:"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, raw = nil) ⇒ ResponseParser

Returns a new instance of ResponseParser.



37
38
39
40
# File 'lib/craigslist/api/response_parser.rb', line 37

def initialize(root, raw = nil)
  @root = root
  @raw = raw
end

Class Method Details

.parse(xml) ⇒ ResultSet

Parameters:

  • xml (String)

    raw response body

Returns:

Raises:

  • (ParseError)

    if the body is not well-formed XML



20
21
22
23
24
25
26
# File 'lib/craigslist/api/response_parser.rb', line 20

def parse(xml)
  document = build(xml)
  root = document.root
  raise ParseError, "response contained no root element" if root.nil?

  new(root, xml.to_s).result_set
end

Instance Method Details

#result_setResultSet

Returns:



43
44
45
# File 'lib/craigslist/api/response_parser.rb', line 43

def result_set
  ResultSet.new(results: results, upload_id: upload_id, raw: raw)
end