diff --git a/README.md b/README.md
index 1c388ee..da0fb0d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-# easy-rss-parser
+# listener rss
-A lightweight library to give some additions for the [rss-parser package](https://github.com/rbren/rss-parser).
+A lightweight library to make simple actions with a RSS feed.
# USAGE
@@ -10,10 +10,10 @@ You can parse RSS from a URL with some custom data.
An example :
```js
-const easyParser = require("easy-rss-parser");
-const ListenerRss = easyParser.ListenerRss;
+const ListenerModule = require("ListenerRSS");
+const ListenerRss = ListenerModule.ListenerRss;
-let listener = new ListenerRss("my-test-service", "fake.rss.service");
+const listener = new ListenerRss("my-test-service", "fake.rss.service");
// make a request to the adr 'fake.rss.service'
myListener.fetchRSS().then((obj, err) => {
@@ -27,16 +27,22 @@ You can parse RSS from a URL each n times.
An example :
```js
-const easyParser = require("easy-rss-parser");
-const ListenerRss = easyParser.ListenerRss;
+const ListenerModule = require("ListenerRSS");
+const ListenerRss = ListenerModule.ListenerRss;
-let listener = new ListenerRss("my-test-service", "fake.rss.service", 5 * 60);
+const listener = new ListenerRss("my-test-service", "fake.rss.service", 5 * 60);
-let callback_fun = (obj, err) => {
+const callback_fun_update = (obj) => {
// some act
};
-// call callback_fun each 5 minutes
-listener.start(callback_fun);
+const callback_fun_new_entries = (obj) => {
+ // some act
+};
+
+listener.on("update", callback_fun);
+listener.on("newEntries", callback_fun);
+
+listener.start();
/*...*/
@@ -47,12 +53,9 @@ listener.stop();
## ListenerRSSInfo
-A class to structure listener's data.
+An interface to structure listener's data.
### Constructor
-
-`constructor(name, address, timeloop, customfields)`
-
- name : the service name
- address : the service address
- [optional] timeloop : time to wait between 2 request in seconds (default 5 minutes)
@@ -67,13 +70,6 @@ A class to structure listener's data.
- listenerRSSInfo : object from the ListenerRSSInfo's class.
-`constructor(name, address, timeloop, customfields)`
-
-- name : the service name
-- address : the service address
-- [optional] timeloop : time to wait between 2 request in seconds (default 5 minutes)
-- [optional] customfields : to notice field who's custom to the service (default blank)
-
### fetchRSS()
This function allows to make a request to the rss service.
@@ -85,22 +81,41 @@ object who's contain the data. [cf Annexe Output](#output)
#### Issues
-Return an error if the server can't be resolved.
+Reject the promise if the server can't be resolved.
-### start(callbackFun)
+### start()
-This function will execute the callbackFun each time loop.
+This function will call the `update` event to each success update, the
+`update_err` event to each fail update, and the `newEntries` event for
+each update who contains a new item.
-#### Parameter
+#### Events
-The `callbackFun` is the function who's going to be called each time loop. She need to be under the shape :
+Each event take one arg into the callback function.
```js
-(obj, err) => {
- /*...*/
+const callback_fun = (obj) => {
+// some act
};
+const callback_fun_err = (err) => {
+// some act
+};
+const callback_fun_new_entries = (newEntries) => {
+// some act
+};
+
+listener.on("update", callback_fun);
+listener.on("update_err", callback_fun_err);
+listener.on("newEntries", callback_fun_new_entries);
```
+#### update
+It used a callback who receive the received object entirely inside an object.
+#### update_err
+It used a callback who receive an error object.
+#### newEntries
+It used a callback who receive only new entries inside an array.
+
### stop()
This function will stop the execution of the callbackFun each time loop.
@@ -146,21 +161,28 @@ In this case it's useless to specify the parent field, so you can just omit the
Here an example of what type of json object is output during a fetch :
```json
-feedUrl: 'fake.rrs.service'
-title: 'myFakeApiTitle'
-description: 'My Fake api desc'
-link: 'fake.rrs.service'
-items:
- - title: 'My last item'
- link: 'fake.rrs.service/item1'
- pubDate: 'Thu, 12 Nov 2015 21:16:39 +0000'
- creator: 'someone'
- content: 'this is a link & this is bold text'
- contentSnippet: 'this is a link & this is bold text'
- guid: 'fake.rrs.service/item1'
- categories:
- - test
- - npm
- - fakeInfos
- isoDate: '2015-11-12T21:16:39.000Z'
+{
+ "feedUrl": "fake.rrs.service",
+ "title": "myFakeApiTitle",
+ "description": "My Fake api desc",
+ "link": "fake.rrs.service",
+ "items": [
+ {
+ "title": "My last item",
+ "link": "fake.rrs.service/item1",
+ "pubDate": "Thu, 12 Nov 2015 21:16:39 +0000",
+ "creator": "someone",
+ "content": "this is a link & this is bold text",
+ "contentSnippet": "this is a link & this is bold text",
+ "guid": "fake.rrs.service/item1",
+ "categories": [
+ "test",
+ "npm",
+ "fakeInfos",
+ ],
+ "isoDate": "2015-11-12T21:16:39.000Z"
+ },
+ /*Some Others items*/
+ ]
+}
```
diff --git a/src/listener-rss.ts b/src/listener-rss.ts
index d2c1bca..fab200b 100644
--- a/src/listener-rss.ts
+++ b/src/listener-rss.ts
@@ -6,7 +6,8 @@ const DEFAULT_TIMELOOP: number = 5 * 60; // default timeloop is 5 min
/**
* Emit 'update' when he's making a fetch during the start fun
- * Emit 'update_err' when the fetch has an issue
+ * Emit 'error' when the fetch has an issue
+ * Emit 'newEntries' when the fetch has new entris
*/
export class ListenerRss extends EventEmitter {
name: string = "";
@@ -21,7 +22,7 @@ export class ListenerRss extends EventEmitter {
/**
* @brief constructor
- * @param config ListenerRSSInfos interface who's contain the ListenerInfos
+ * @param config ListenerRSSInfos interface who contains the ListenerInfos
*/
constructor(config: ListenerInfo) {
super();
@@ -36,7 +37,7 @@ export class ListenerRss extends EventEmitter {
}
/**
- * @brief Private function. Is useed to initilize the parser object with the customfields var
+ * @brief Private function. Is used to initilize the parser object with the customfields var
*/
generateParser() {
const parserConfig = this.customfields && {
@@ -51,7 +52,7 @@ export class ListenerRss extends EventEmitter {
}
/**
- * @brief use the parseURL function from rss-parser with the objects datas
+ * @brief use the parseURL function from rss-parser with the objects data
* @return return a promise with the received data
*/
fetchRSS(): Promise> {
@@ -60,7 +61,6 @@ export class ListenerRss extends EventEmitter {
/**
* @brief call the callback function each looptime
- * @param callback function who's going to be called with the latest get
*/
start(): void {
this.loopRunning = true;