Skip to content

Commit

Permalink
Release v0.2.0beta2
Browse files Browse the repository at this point in the history
Explicit arrays for xml parsing turned off by default.  xml2js parsing
options now controlled via xmlOptions
  • Loading branch information
Edward de Groot committed Sep 15, 2011
1 parent 7209761 commit 56d48b2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions History.md
Expand Up @@ -43,3 +43,9 @@
* non-GET requests are not cached
* parsed xml now uses explicit arrays for child elements
* ability to utilize loose parsing when dealing with inexplicit or incorrect content-types

0.2.0beta2 / 2011-09-15
=======================

* xml2js parsing options can now be passed in via xmlOptions
* parsed xml no longer provides explicit arrays for child elements by default (but you can enable via xmlOptions)
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -37,6 +37,7 @@ At this item, the following configuration options can be specified:
* verbosity - possible values are 'DEBUG', 'INFO', 'WARNING' and 'ERROR' (default is 'INFO')
* parser - possible values are 'json' and 'xml' (default is undefined, in which auto-detection by content-type header is used)
* ignoreCacheControl - do not utilize the cache-control header to override the cache configuration if present (default if false)
* xmlOptions - options passed into the [xml2js](https://github.com/Leonidas-from-XIV/node-xml2js) parser (default is none / {})

When you request a resource from the pantry, a couple interesting things happen. If the item is available in the pantry, and hasn't 'spoiled', it will be returned immediately via the callback. If it has expired (it's beyond its best before date) but hasn't spoiled, it will still be returned and then refreshed in the background.

Expand Down
8 changes: 8 additions & 0 deletions examples/atom-sp6.coffee
@@ -0,0 +1,8 @@
pantry = require '../src/pantry'
util = require 'util'

pantry.fetch {
xmlOptions: {explicitCharkey: true, explicitArray: true}
uri: 'http://www.edmontonjournal.com/1419033.atom'
}, (error, item) ->
console.log util.inspect(item, false, null)
8 changes: 8 additions & 0 deletions examples/rss.coffee
@@ -0,0 +1,8 @@
pantry = require '../src/pantry'
util = require 'util'

pantry.fetch {
xmlOptions: {explicitCharkey: true, explicitArray: true}
uri: 'http://rss.cbc.ca/lineup/topstories.xml'
}, (error, item) ->
console.log util.inspect(item, false, null)
1 change: 1 addition & 0 deletions examples/xml-loose.coffee
Expand Up @@ -2,6 +2,7 @@ pantry = require '../src/pantry'

pantry.fetch {
parser: 'xml'
xmlOptions: {explicitCharkey: true, explicitArray: true}
uri: 'http://app.canada.com/entertainment/tribune.svc/ProgramDetails?programid=MV003438830000'
}, (error, item) ->
console.log "\ttitle: #{item.titles[0].title[0]['#']}"
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "pantry",
"description": "A JSON/XML resource caching library based on Request",
"version": "0.2.0beta",
"version": "0.2.0beta2",
"homepage": "https://github.com/Postmedia/pantry",
"author": "Edward de Groot <edegroot@postmedia.com> (http://mred9.wordpress.com)",
"contributors": [
Expand Down
4 changes: 2 additions & 2 deletions src/pantry.coffee
Expand Up @@ -10,7 +10,7 @@ log = new Log()
currentStock = {} # key/value list of all current items in stock
stockCount = 0 # number of items currently in stock

config = { shelfLife: 60, maxLife: 300, capacity: 1000, ideal: 900, caseSensitive: true, verbosity: "INFO"}
config = { shelfLife: 60, maxLife: 300, capacity: 1000, ideal: 900, caseSensitive: true, verbosity: "INFO", xmlOptions: {}}
log.notice "Initializing the Pantry"
log.info "Configuration: shelfLife=#{config.shelfLife}, maxLife=#{config.maxLife}, capacity=#{config.capacity}, ideal=#{config.ideal}"

Expand Down Expand Up @@ -168,7 +168,7 @@ class StockedItem extends EventEmitter
body = body[start...body.length] if start

# now we can parse
parser = new xml2js.Parser(explicitArray: true)
parser = new xml2js.Parser(@options.xmlOptions)
parser.on 'end', (results) =>
@stock(response, results)
parser.parseString body
Expand Down

0 comments on commit 56d48b2

Please sign in to comment.