Class: Craigslist::API::Serializer

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(config) ⇒ Serializer

Returns a new instance of Serializer.

Parameters:



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.

Parameters:

  • postings (Array<Posting>)
  • io (IO, String, nil) (defaults to: nil)

    destination; a new String is used if omitted

Returns:

  • (String, IO)

    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