Class: Craigslist::API::Serializer
- Inherits:
-
Object
- Object
- Craigslist::API::Serializer
- Defined in:
- lib/craigslist/api/serializer.rb
Overview
Renders Posting objects into the RDF/RSS document the bulk interface expects.
REXML lives here and nowhere else. Bulk submissions inline base64 images, so a large batch is a large document; if building a DOM ever becomes a memory problem this class can be reimplemented as a streaming writer without changing anything public.
Constant Summary collapse
- RSS_NAMESPACE =
Default namespace for the RSS 1.0 elements.
"http://purl.org/rss/1.0/"- RDF_NAMESPACE =
RDF namespace, used for the item manifest.
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"- CL_NAMESPACE =
Craigslist's own namespace, carrying every cl:* element.
"http://www.craigslist.org/about/cl-bulk-ns/1.0"
Instance Method Summary collapse
-
#initialize(config) ⇒ Serializer
constructor
A new instance of Serializer.
-
#serialize(postings, io: nil) ⇒ String, IO
Whatever was written to.
Constructor Details
#initialize(config) ⇒ Serializer
Returns a new instance of Serializer.
25 26 27 |
# File 'lib/craigslist/api/serializer.rb', line 25 def initialize(config) @config = config end |
Instance Method Details
#serialize(postings, io: nil) ⇒ String, IO
Returns whatever was written to.
32 33 34 35 36 |
# File 'lib/craigslist/api/serializer.rb', line 32 def serialize(postings, io: nil) output = io || +"" build_document(Array(postings)).write(output) output end |