Skip to content

Commit 9f8e7ef

Browse files
committed
Update tests and documentation for new properties
1 parent e6982f6 commit 9f8e7ef

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ return fetch('http://www.nasa.gov/rss/dyn/breaking_news.rss')
8080
summary: undefined, // summary of the channel
8181
},
8282
items: [{ // list of items in the feed
83+
id: undefined, // item id
8384
title: undefined, // item title
85+
imageUrl: undefined, // item image url
8486
links: [{
8587
url: undefined, // item link url
8688
rel: undefined // type of item link
@@ -138,7 +140,9 @@ return fetch('http://www.nasa.gov/rss/dyn/breaking_news.rss')
138140

139141
| Parsed Value | RSS v2.0 | Atom v1.0 |
140142
| ------------- | ------------- | ------------- |
143+
| id | guid | id |
141144
| title | title | title |
145+
| imageUrl | | icon |
142146
| links | link | link |
143147
| description | description | summary |
144148
| content | | content |

model/rss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ model.rss = {
5454
rel: undefined
5555
}],
5656
id: undefined,
57-
image: undefined,
57+
imageUrl: undefined,
5858
description: undefined,
5959
content: undefined,
6060
categories: [{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-rss-parser",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "React Native compatible package to parse RSS feeds",
55
"main": "index.js",
66
"scripts": {

parsers/atomv1.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ function getChannelCategories(node) {
8888

8989
function getChannelImage(node) {
9090
var img = utils.getElementTextContent(node, 'image');
91-
if(img == '' || img == undefined || img == null){
91+
92+
if(img === '' || img === undefined){
9293
img = utils.getElementTextContent(node, 'logo');
9394
}
94-
if(img == '' || img == undefined || img == null){
95+
96+
if(img === '' || img === undefined){
9597
img = utils.getElementTextContent(node, 'icon');
9698
}
9799

@@ -129,7 +131,7 @@ function getItemContent(node) {
129131
return utils.getElementTextContent(node, 'content');
130132
}
131133

132-
function getItemIcon(node) {
134+
function getItemImage(node) {
133135
return utils.getElementTextContent(node, 'icon');
134136
}
135137

@@ -155,9 +157,11 @@ function getItemCategories(node) {
155157

156158
function getItemPublished(node) {
157159
var pub = utils.getElementTextContent(node, 'updated');
158-
if(pub == '' || pub == undefined || pub == null){
160+
161+
if(pub === '' || pub === undefined){
159162
utils.getElementTextContent(node, 'published');
160163
}
164+
161165
return pub;
162166
}
163167

@@ -188,7 +192,7 @@ function mapItems(document) {
188192
links: getItemLinks(item),
189193
description: getItemDescription(item),
190194
id: getItemId(item),
191-
image: getItemIcon(item),
195+
imageUrl: getItemImage(item),
192196
content: getItemContent(item),
193197
authors: getItemAuthors(item),
194198
categories: getItemCategories(item),

test/samples/atomv1.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ exports.feed = `
22
<?xml version="1.0" encoding="utf-8"?>
33
<feed xmlns="http://www.w3.org/2005/Atom">
44
<title>ATOM title</title>
5-
<subtitle>A sample ATOM feed</subtitle>
5+
<subtitle>A sample ATOM feed</subtitle>
6+
<logo>https://b.thumbs.redditmedia.com/ntr1FkBiO3nk4t4Vgy5GXoPQ_j2hirENH9iT8rXNf8M.png</logo>
67
<generator uri="http://jekyllrb.com" version="3.1.2">Jekyll</generator>
78
<link href="http://bakery-store.example.com/" rel="alternate" type="text/html" />
89
<updated>2016-05-13T16:22:08+12:00</updated>
@@ -14,6 +15,7 @@ exports.feed = `
1415
<published>2016-01-02T00:00:00+13:00</published>
1516
<updated>2016-01-02T00:00:00+13:00</updated>
1617
<id>http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from</id>
18+
<icon>https://b.thumbs.redditmedia.com/ntr1FkBiO3nk4t4Vgy5GXoPQ_j2hirENH9iT8rXNf8.png</icon>
1719
<content type="html" xml:base="http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html">&lt;p&gt;The chocolate chip cookie was invented by Ruth Graves Wakefield. She owned the Toll House Inn, in Whitman, Massachusetts, a very popular restaurant that featured home cooking in the 1930s. Her cookbook, Toll House Tried and True Recipes, was first published in 1936 by M. Barrows &amp;amp; Company, New York. The 1938 edition of the cookbook was the first to include the recipe “Toll House Chocolate Crunch Cookie” which rapidly became a favorite cookie in American homes.&lt;/p&gt;
1820
1921
&lt;p&gt;Source / Read more &lt;a href=&quot;https://en.wikipedia.org/wiki/Chocolate_chip_cookie&quot;&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;

test/test-parser-atomv1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ describe('when parse ATOM', function() {
1313
assert.equal(result.links[0].url, 'http://bakery-store.example.com/');
1414
assert.equal(result.description, 'A sample ATOM feed');
1515
assert.equal(result.items.length, 2);
16+
assert.equal(result.image.url, 'https://b.thumbs.redditmedia.com/ntr1FkBiO3nk4t4Vgy5GXoPQ_j2hirENH9iT8rXNf8M.png');
1617
assert.equal(result.items[0].title, 'Where Did The Cookie Come From');
18+
assert.equal(result.items[0].id, 'http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from');
19+
assert.equal(result.items[0].imageUrl, 'https://b.thumbs.redditmedia.com/ntr1FkBiO3nk4t4Vgy5GXoPQ_j2hirENH9iT8rXNf8.png');
1720
assert.equal(result.items[0].links.length, 1);
1821
assert.equal(result.items[0].links[0].url, 'http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html');
1922
assert.equal(result.items[0].links[0].rel, 'alternate');

test/test-parser-rssv2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('when rss parse', function() {
2727
assert.equal(result.authors.length, 1);
2828
assert.equal(result.authors[0].name, 'dave@userland.com');
2929
assert.equal(result.items.length, 9);
30+
assert.equal(result.items[0].id, 'http://scriptingnews.userland.com/backissues/2002/09/29#When:6:56:02PM');
3031
assert.equal(result.items[0].published, 'Mon, 30 Sep 2002 01:56:02 GMT');
3132
assert.equal(result.items[0].enclosures.length, 1);
3233
assert.equal(result.items[0].enclosures[0].url, 'http://www.scripting.com/mp3s/weatherReportSuite.mp3');

0 commit comments

Comments
 (0)