Permalink
Browse files

Release v0.2.0beta2

Explicit arrays for xml parsing turned off by default.  xml2js parsing
options now controlled via xmlOptions
  • Loading branch information...
1 parent 7209761 commit 56d48b2b841c4964d0f9cf4fc806d7e63a2c4277 Edward de Groot committed Sep 15, 2011
Showing with 27 additions and 3 deletions.
  1. +6 −0 History.md
  2. +1 −0 README.md
  3. +8 −0 examples/atom-sp6.coffee
  4. +8 −0 examples/rss.coffee
  5. +1 −0 examples/xml-loose.coffee
  6. +1 −1 package.json
  7. +2 −2 src/pantry.coffee
View
6 History.md
@@ -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)
View
1 README.md
@@ -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.
View
8 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)
View
8 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)
View
1 examples/xml-loose.coffee
@@ -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]['#']}"
View
2 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": [
View
4 src/pantry.coffee
@@ -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}"
@@ -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

0 comments on commit 56d48b2

Please sign in to comment.