1 | [![Build Status](https://secure.travis-ci.org/michaelnisi/pickup.svg)](http://travis-ci.org/michaelnisi/pickup)
|
2 | [![Coverage Status](https://coveralls.io/repos/github/michaelnisi/pickup/badge.svg?branch=master)](https://coveralls.io/github/michaelnisi/pickup?branch=master)
|
3 |
|
4 | # pickup - transform feeds
|
5 |
|
6 | The **pickup** [Node](http://nodejs.org/) package provides a [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) stream from [RSS 2.0](http://cyber.law.harvard.edu/rss/rss.html), including [iTunes](https://www.apple.com/itunes/podcasts/specs.html) namespace extensions, and [Atom 1.0](http://atomenabled.org/developers/syndication/) formatted XML to newline separated JSON strings or objects.
|
7 |
|
8 | ## Usage
|
9 |
|
10 | ### Command-line
|
11 |
|
12 | If you haven't yet, first install **[json](https://github.com/trentm/json)**—a command for working with JSON on the command-line:
|
13 |
|
14 | ```
|
15 | $ npm install -g json
|
16 | ```
|
17 |
|
18 | Now you can pipe **pickup** to **json**:
|
19 |
|
20 | ```
|
21 | $ export URL=www.newyorker.com/feed/posts
|
22 | $ curl -sS $URL | pickup | json -g
|
23 | ```
|
24 |
|
25 | Or, for example, to filter the titles:
|
26 |
|
27 | ```
|
28 | $ curl -sS $URL | pickup | json -ga title
|
29 | ```
|
30 |
|
31 | ### Library
|
32 |
|
33 | #### Transforming from stdin to stdout
|
34 |
|
35 | ```js
|
36 | const pickup = require('pickup')
|
37 |
|
38 | process.stdin
|
39 | .pipe(pickup())
|
40 | .pipe(process.stdout)
|
41 | ```
|
42 |
|
43 | You can run this example from the command-line:
|
44 |
|
45 | ```
|
46 | $ curl -sS $URL | node example/stdin.js | json -g
|
47 | ```
|
48 |
|
49 | #### Proxy server
|
50 |
|
51 | ```js
|
52 | const http = require('http')
|
53 | const pickup = require('pickup')
|
54 |
|
55 | http.createServer((req, res) => {
|
56 | http.get('http:/'.concat(req.url), (feed) => {
|
57 | feed.pipe(pickup()).pipe(res)
|
58 | })
|
59 | }).listen(8080)
|
60 | ```
|
61 |
|
62 | To try the proxy server:
|
63 |
|
64 | ```
|
65 | $ node example/proxy.js &
|
66 | $ curl -sS http://localhost:8080/$URL | json -ga title
|
67 | ```
|
68 |
|
69 | ## Types
|
70 |
|
71 | ### str()
|
72 |
|
73 | This can either be a `String()`, `null`, or `undefined`.
|
74 |
|
75 | ### opts()
|
76 |
|
77 | The options [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) is passed to the `Transform` stream constructor.
|
78 |
|
79 | **pickup** uses following additional options:
|
80 |
|
81 | - `eventMode` [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) defaults to `false`, if `true` readable state buffers are not filled and no `'data'`, but `'feed'` and `'entry'` events are emitted.
|
82 |
|
83 | - `charset` `str()` | `'UTF-8'` | `'ISO-8859-1'` An optional string to specify the encoding of input data. In the common use case you received this string in the headers of your HTTP response before you began parsing. If you, not so commonly, cannot provide the encoding upfront, **pickup** tries to detect the encoding, and eventually defaults to `'UTF-8'`. The `charset` option is corresponding to the optional `charset` MIME type parameter found in `Content-Type` HTTP headers. It's OK to pass any string, **pickup** will fall back on `'UTF-8'` when confused.
|
84 |
|
85 | ### url()
|
86 |
|
87 | An `undefined` property, not populated by the parser, to identify feeds and entries in upstream systems, without prompting V8 to create new [hidden classes](https://github.com/v8/v8/wiki/Design%20Elements#fast-property-access).
|
88 |
|
89 | ### feed()
|
90 |
|
91 | - `author` `str()`
|
92 | - `copyright` `str()`
|
93 | - `id` `str()`
|
94 | - `image` `str()`
|
95 | - `language` `str()`
|
96 | - `link` `str()`
|
97 | - `originalURL` `url()`
|
98 | - `payment` `str()`
|
99 | - `subtitle` `str()`
|
100 | - `summary` `str()`
|
101 | - `title` `str()`
|
102 | - `ttl` `str()`
|
103 | - `updated` `str()`
|
104 | - `url` `url()`
|
105 |
|
106 | ### enclosure()
|
107 |
|
108 | - `length` `str()`
|
109 | - `type` `str()`
|
110 | - `url` `str()`
|
111 |
|
112 | ### entry()
|
113 |
|
114 | - `author` `str()`
|
115 | - `duration` `str()`
|
116 | - `enclosure` `enclosure()` or `undefined`
|
117 | - `id` `str()`
|
118 | - `image` `str()`
|
119 | - `link` `str()`
|
120 | - `originalURL` `url()`
|
121 | - `subtitle` `str()`
|
122 | - `summary` `str()`
|
123 | - `title` `str()`
|
124 | - `updated` `str()`
|
125 | - `url` `url()`
|
126 |
|
127 | ### Event:'feed'
|
128 |
|
129 | ```js
|
130 | feed()
|
131 | ```
|
132 | Emitted when the meta information of the feed gets available.
|
133 |
|
134 | ### Event:'entry'
|
135 |
|
136 | ```js
|
137 | entry()
|
138 | ```
|
139 | Emitted for each entry.
|
140 |
|
141 | ## Exports
|
142 |
|
143 | ```js
|
144 | pickup(opts())
|
145 | ```
|
146 |
|
147 | **pickup** exports a function that returns a [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) stream which emits newline separated JSON strings, in `objectMode` the `'data'` event contains `entry()` or `feed()` objects. As per XML's structure the last `'data'` event usually contains the `feed()` object. In `eventMode` neither `'readable'` nor `'data'` events are emitted, instead `'feed'` and `'entry'` events are fired.
|
148 |
|
149 | ## Installation
|
150 |
|
151 | With [npm](https://npmjs.org/package/pickup), do:
|
152 |
|
153 | ```
|
154 | $ npm install pickup
|
155 | ```
|
156 |
|
157 | To use the CLI (as above):
|
158 |
|
159 | ```
|
160 | $ npm install -g pickup
|
161 | ```
|
162 |
|
163 | ## Contribute
|
164 |
|
165 | Please create an issue if you encounter a feed that **pickup** fails to parse.
|
166 |
|
167 | ## License
|
168 |
|
169 | [MIT license](https://raw.github.com/michaelnisi/pickup/master/LICENSE)
|