podcast-index-api
Advanced tools
Comparing version 1.1.8 to 1.1.9
255
index.js
@@ -6,4 +6,3 @@ const got = require('got') | ||
// | ||
// https://api.podcastindex.org/developer_docs | ||
// updated: https://podcastindex-org.github.io/docs-api/ | ||
// API docs: https://podcastindex-org.github.io/docs-api/#get-/search/byterm | ||
// | ||
@@ -14,2 +13,3 @@ | ||
const PATH_SEARCH_BY_TERM = 'search/byterm' | ||
const PATH_SEARCH_EPISODE_BY_PERSON = 'search/byperson' | ||
const PATH_ADD_BY_FEED_URL = 'add/byfeedurl' | ||
@@ -25,6 +25,14 @@ const PATH_ADD_BY_ITUNES_ID = 'add/byitunesid' | ||
const PATH_PODCASTS_BY_ITUNES_ID = 'podcasts/byitunesid' | ||
const PATH_PODCASTS_BY_TAG = 'podcasts/bytag' | ||
const PATH_PODCASTS_TRENDING = 'podcasts/trending' | ||
const PATH_PODCASTS_DEAD = 'podcasts/dead' | ||
const PATH_RECENT_FEEDS = 'recent/feeds' | ||
const PATH_RECENT_EPISODES = 'recent/episodes' | ||
const PATH_RECENT_NEWFEEDS = 'recent/newfeeds' | ||
const PATH_RECENT_SOUNDBITES = 'recent/soundbites' | ||
const PATH_VALUE_BY_FEED_ID = 'value/byfeedid' | ||
const PATH_VALUE_BY_FEED_URL = 'value/byfeedurl' | ||
const PATH_STATS_CURRENT = 'stats/current' | ||
const PATH_CATEGORIES_LIST = 'categories/list' | ||
const PATH_HUB_PUBNOTIFIY = 'hub/pubnotify' | ||
@@ -38,3 +46,3 @@ const qs = (o) => '?' + querystring.stringify(o) | ||
if ( | ||
response.statusCode == 500 || | ||
response.statusCode === 500 || | ||
(body.hasOwnProperty('status') && body.status === 'false') | ||
@@ -84,64 +92,136 @@ ) { | ||
const custom = async (path, queries) => { | ||
const response = await api(path + qs(queries)) | ||
return withResponse(response) | ||
} | ||
return { | ||
api, | ||
searchByTerm: async (q) => { | ||
const response = await api(PATH_SEARCH_BY_TERM + qs({ q: q })) | ||
return withResponse(response) | ||
custom, | ||
searchByTerm: async (q, val = '', clean = false, fullText = false) => { | ||
let queries = { | ||
q: q, | ||
} | ||
if (val !== '') queries['val'] = val | ||
if (clean) queries['clean'] = '' | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_SEARCH_BY_TERM, queries) | ||
}, | ||
searchEpisodesByPerson: async (q, fullText = false) => { | ||
let queries = { | ||
q: q, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_SEARCH_EPISODE_BY_PERSON, queries) | ||
}, | ||
podcastsByFeedUrl: async (feedUrl) => { | ||
const response = await api( | ||
PATH_PODCASTS_BY_FEED_URL + qs({ url: feedUrl }) | ||
) | ||
return withResponse(response) | ||
return custom(PATH_PODCASTS_BY_FEED_URL, { url: feedUrl }) | ||
}, | ||
podcastsByFeedId: async (feedId) => { | ||
const response = await api( | ||
PATH_PODCASTS_BY_FEED_ID + qs({ id: feedId }) | ||
) | ||
return withResponse(response) | ||
return custom(PATH_PODCASTS_BY_FEED_ID, { id: feedId }) | ||
}, | ||
podcastsByFeedItunesId: async (itunesId) => { | ||
const response = await api( | ||
PATH_PODCASTS_BY_ITUNES_ID + qs({ id: itunesId }) | ||
) | ||
return withResponse(response) | ||
return custom(PATH_PODCASTS_BY_ITUNES_ID, { id: itunesId }) | ||
}, | ||
addByFeedUrl: async (feedUrl) => { | ||
const response = await api( | ||
PATH_ADD_BY_FEED_URL + qs({ url: feedUrl }) | ||
) | ||
return withResponse(response) | ||
podcastsByTag: async () => { | ||
return custom(PATH_PODCASTS_BY_TAG, { 'podcast-value': '' }) | ||
}, | ||
podcastsTrending: async ( | ||
max = 10, | ||
since = null, | ||
lang = null, | ||
cat = null, | ||
notcat = null | ||
) => { | ||
return custom(PATH_PODCASTS_TRENDING, { | ||
max: max, | ||
since: since, | ||
lang: lang, | ||
cat: cat, | ||
notcat: notcat, | ||
}) | ||
}, | ||
podcastsDead: async () => { | ||
return custom(PATH_PODCASTS_DEAD) | ||
}, | ||
addByFeedUrl: async (feedUrl, chash = null, itunesId = null) => { | ||
return custom(PATH_ADD_BY_FEED_URL, { | ||
url: feedUrl, | ||
chash: chash, | ||
itunesid: itunesId, | ||
}) | ||
}, | ||
addByItunesId: async (itunesId) => { | ||
const response = await api( | ||
PATH_ADD_BY_ITUNES_ID + qs({ id: itunesId }) | ||
) | ||
return withResponse(response) | ||
return custom(PATH_ADD_BY_ITUNES_ID, { id: itunesId }) | ||
}, | ||
episodesByFeedId: async (feedId) => { | ||
const response = await api( | ||
PATH_EPISODES_BY_FEED_ID + qs({ id: feedId }) | ||
) | ||
return withResponse(response) | ||
episodesByFeedId: async ( | ||
feedId, | ||
since = null, | ||
max = 10, | ||
fullText = false | ||
) => { | ||
let queries = { | ||
id: feedId, | ||
since: since, | ||
max: max, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_EPISODES_BY_FEED_ID, queries) | ||
}, | ||
episodesByFeedUrl: async (feedUrl) => { | ||
const response = await api( | ||
PATH_EPISODES_BY_FEED_URL + qs({ url: feedUrl }) | ||
) | ||
return withResponse(response) | ||
episodesByFeedUrl: async ( | ||
feedUrl, | ||
since = null, | ||
max = 10, | ||
fullText = false | ||
) => { | ||
let queries = { | ||
url: feedUrl, | ||
since: since, | ||
max: max, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_EPISODES_BY_FEED_URL, queries) | ||
}, | ||
episodesByItunesId: async (itunesId) => { | ||
const response = await api( | ||
PATH_EPISODES_BY_ITUNES_ID + qs({ id: itunesId }) | ||
) | ||
return withResponse(response) | ||
episodesByItunesId: async ( | ||
itunesId, | ||
since = null, | ||
max = 10, | ||
fullText = false | ||
) => { | ||
let queries = { | ||
id: itunesId, | ||
since: since, | ||
max: max, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_EPISODES_BY_ITUNES_ID, queries) | ||
}, | ||
episodesById: async (id) => { | ||
const response = await api(PATH_EPISODES_BY_ID + qs({ id: id })) | ||
return withResponse(response) | ||
episodesById: async (id, fullText = false) => { | ||
let queries = { | ||
id: id, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_EPISODES_BY_ID, queries) | ||
}, | ||
episodesRandom: async (max = 1) => { | ||
const response = await api(PATH_EPISODES_RANDOM + qs({ max: max })) | ||
return withResponse(response) | ||
episodesRandom: async ( | ||
max = 1, | ||
lang = null, | ||
cat = null, | ||
notcat = null, | ||
fullText = false | ||
) => { | ||
let queries = { | ||
max: max, | ||
lang: lang, | ||
cat: cat, | ||
notcat: notcat, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_EPISODES_RANDOM, queries) | ||
}, | ||
recentFeeds: async ( | ||
@@ -151,14 +231,12 @@ max = 40, | ||
cat = null, | ||
lang = null | ||
lang = null, | ||
notcat = null | ||
) => { | ||
const response = await api( | ||
PATH_RECENT_FEEDS + | ||
qs({ | ||
max: max, | ||
since: since, | ||
cat: cat, | ||
lang: lang, | ||
}) | ||
) | ||
return withResponse(response) | ||
return custom(PATH_RECENT_FEEDS, { | ||
max: max, | ||
since: since, | ||
lang: lang, | ||
cat: cat, | ||
notcat: notcat, | ||
}) | ||
}, | ||
@@ -168,23 +246,52 @@ recentEpisodes: async ( | ||
excludeString = null, | ||
excludeBlank = null | ||
before = null, | ||
fullText = false | ||
) => { | ||
const response = await api( | ||
PATH_RECENT_EPISODES + | ||
qs({ | ||
max: max, | ||
excludeString: excludeString ? excludeString : null, | ||
excludeBlank: excludeBlank ? excludeBlank : null, | ||
}) | ||
) | ||
return withResponse(response) | ||
let queries = { | ||
max: max, | ||
excludeString: excludeString ? excludeString : null, | ||
before: before, | ||
} | ||
if (fullText) queries['fullText'] = '' | ||
return custom(PATH_RECENT_EPISODES, queries) | ||
}, | ||
recentNewFeeds: async () => { | ||
const response = await api(PATH_RECENT_NEWFEEDS) | ||
return withResponse(response) | ||
recentNewFeeds: async (max = 20, since = null) => { | ||
return custom(PATH_RECENT_NEWFEEDS, { | ||
max: max, | ||
since: since, | ||
}) | ||
}, | ||
recentSoundbites: async (max = 20) => { | ||
return custom(PATH_RECENT_SOUNDBITES, { | ||
max: max, | ||
}) | ||
}, | ||
valueByFeedId: async (feedId) => { | ||
return custom(PATH_VALUE_BY_FEED_ID, { | ||
id: feedId, | ||
}) | ||
}, | ||
valueByFeedUrl: async (feedUrl) => { | ||
return custom(PATH_VALUE_BY_FEED_URL, { | ||
url: feedUrl, | ||
}) | ||
}, | ||
statsCurrent: async () => { | ||
const response = await api(PATH_STATS_CURRENT) | ||
return withResponse(response) | ||
return custom(PATH_STATS_CURRENT) | ||
}, | ||
categoriesList: async () => { | ||
return custom(PATH_CATEGORIES_LIST) | ||
}, | ||
hubPubNotify: async (feedId, update = true) => { | ||
let queries = { | ||
id: feedId, | ||
} | ||
if (update) queries['update'] = '' | ||
return custom(PATH_HUB_PUBNOTIFIY, queries) | ||
}, | ||
} | ||
} |
{ | ||
"name": "podcast-index-api", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "JS lib for the Podcast Index API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,2 +23,4 @@ # Podcast Index API Javascript library | ||
Description of API endpoints, arguments and returned data: https://podcastindex-org.github.io/docs-api/ | ||
Require the lib from your javascript file | ||
@@ -40,10 +42,38 @@ | ||
- `searchByTerm(term: String)` | ||
- `podcastsByFeedUrl(url: String)` | ||
- `podcastsByFeedId(id: Number)` | ||
- `podcastsByFeedItunesId(itunesId: Number)` | ||
- `addByFeedUrl(url: String)` | ||
- `episodesByFeedId(id: Number)` | ||
- `episodesByFeedUrl(url: String)` | ||
- `episodesByItunesId(itunesId: Number)` | ||
- `recentEpisodes(max: Number, exclude: String)` | ||
- Custom | ||
- Use for endpoints that don't have a specific function or if the function doesn't accept an argument for a | ||
desired parameter. | ||
- `custom(path: String, queries: Object)` | ||
- Search | ||
- `searchByTerm(q: String, val: String, clean: Boolean, fullText: Boolean)` | ||
- `searchEpisodesByPerson(q: String, fullText: Boolean)` | ||
- Podcasts | ||
- `podcastsByFeedUrl(feedUrl: String)` | ||
- `podcastsByFeedId(feedId: Number)` | ||
- `podcastsByFeedItunesId(itunesId: Number)` | ||
- `podcastsByTag()` | ||
- `podcastsTrending(max: Number, since: Number, lang: String, cat: String, notcat: String)` | ||
- `podcastsDead()` | ||
- Episodes | ||
- `episodesByFeedId(feedId: Number, since: Number, max: Number, fullText: Boolean)` | ||
- `episodesByFeedUrl(feedUrl: String, since: Number, max: Number, fullText: Boolean)` | ||
- `episodesByItunesId(itunesId: Number, since: Number, max: Number, fullText: Boolean)` | ||
- `episodesById(id: Number, fullText: Boolean)` | ||
- `episodesRandom(max: Number, lang: String, cat: String, notcat: String, fullText: Boolean)` | ||
- Recent | ||
- `recentFeeds(max: Number, since: Number, cat: String, lang: String, notcat: String)` | ||
- `recentEpisodes(max: Number, excludeString: String, before: Number, fullText: Boolean)` | ||
- `recentNewFeeds(max: Number, since: Number)` | ||
- `recentSoundbites(max: Number)` | ||
- Value | ||
- `valueByFeedUrl(feedUrl: String)` | ||
- `valueByFeedId(feedId: Number)` | ||
- Stats | ||
- `statsCurrent()` | ||
- Categories | ||
- `categoriesList()` | ||
- Notify Hub | ||
- `hubPubNotify(feedId: Number, update: Boolean)` | ||
- Add | ||
- `addByFeedUrl(feedUrl: String, chash: String, itunesId: Number)` | ||
- `addByItunesId(itunesId: Number)` |
@@ -11,3 +11,5 @@ jest.setTimeout(10000) | ||
const SEARCH_TERM = 'Joe Rogan Experience' | ||
const SEARCH_PERSON = 'Joe Rogan' | ||
const FEED_ID = 550168 | ||
const FEED_ID_VALUE = 920666 | ||
const FEED_ITUNES_ID = 360084272 | ||
@@ -17,2 +19,3 @@ const FEED_TITLE = 'The Joe Rogan Experience' | ||
const FEED_URL_NOT_FOUND = 'http://www.google.com/' | ||
const FEED_URL_VALUE = 'https://mp3s.nashownotes.com/pc20rss.xml' | ||
const EPISODE_ID = 16795090 | ||
@@ -29,2 +32,13 @@ const RECENT_FEEDS_COUNT = 3 | ||
it('Custom', async () => { | ||
expect.assertions(4) | ||
const results = await api.custom('search/byterm', { | ||
q: SEARCH_TERM, | ||
}) | ||
expect(results.status).toEqual('true') | ||
expect(results.feeds.length).toBeGreaterThan(0) | ||
expect(results).toHaveProperty('query', SEARCH_TERM) | ||
expect(results).toHaveProperty('feeds') | ||
}) | ||
it('Search by term (async)', async () => { | ||
@@ -53,2 +67,23 @@ expect.assertions(4) | ||
it('Search by term (value)', async () => { | ||
expect.assertions(4) | ||
const searchTerm = 'no agenda' | ||
const results = await api.searchByTerm(searchTerm, 'lightning') | ||
expect(results.status).toEqual('true') | ||
expect(results.feeds.length).toBeGreaterThan(0) | ||
expect(results).toHaveProperty('query', searchTerm) | ||
expect(results).toHaveProperty('feeds') | ||
// expect(results.feeds[0].id).toEqual(FEED_ID) | ||
// expect(results.feeds[0].title).toEqual(FEED_TITLE) | ||
}) | ||
it('Search episodes by person', async () => { | ||
expect.assertions(4) | ||
const results = await api.searchEpisodesByPerson(SEARCH_PERSON) | ||
expect(results.status).toEqual('true') | ||
expect(results.items.length).toBeGreaterThan(0) | ||
expect(results).toHaveProperty('query', SEARCH_PERSON) | ||
expect(results).toHaveProperty('items') | ||
}) | ||
// it('Add feed by URL', async () => { | ||
@@ -140,2 +175,26 @@ // const results = await api.addByFeedUrl(FEED_URL) | ||
it('Podcasts By tag', async () => { | ||
expect.assertions(3) | ||
const results = await api.podcastsByTag() | ||
expect(results.status).toEqual('true') | ||
expect(results.feeds.length).toBeGreaterThan(1) | ||
expect(results.count).toBeGreaterThan(1) | ||
}) | ||
it('Podcasts trending', async () => { | ||
expect.assertions(3) | ||
const results = await api.podcastsTrending() | ||
expect(results.status).toEqual('true') | ||
expect(results.feeds.length).toEqual(10) | ||
expect(results.count).toEqual(10) | ||
}) | ||
it('Podcasts dead', async () => { | ||
expect.assertions(3) | ||
const results = await api.podcastsDead() | ||
expect(results.status).toEqual('true') | ||
expect(results.feeds.length).toBeGreaterThan(1) | ||
expect(results.count).toBeGreaterThan(1) | ||
}) | ||
it('Recent Feeds', async () => { | ||
@@ -194,2 +253,24 @@ expect.assertions(1) | ||
it('Recent soundbites', async () => { | ||
expect.assertions(3) | ||
const results = await api.recentSoundbites(20) | ||
expect(results).toHaveProperty('status', 'true') | ||
expect(results.items.length).toBeGreaterThan(1) | ||
expect(results.count).toBeGreaterThan(1) | ||
}) | ||
it('Value By Feed URL', async () => { | ||
expect.assertions(2) | ||
const results = await api.valueByFeedUrl(FEED_URL_VALUE) | ||
expect(results).toHaveProperty('query.url', FEED_URL_VALUE) | ||
expect(results).toHaveProperty('value') | ||
}) | ||
it('Value By Feed ID', async () => { | ||
expect.assertions(2) | ||
const results = await api.valueByFeedId(FEED_ID_VALUE) | ||
expect(results).toHaveProperty('query.id', FEED_ID_VALUE.toString()) | ||
expect(results).toHaveProperty('value') | ||
}) | ||
it('Stats Current', async () => { | ||
@@ -201,1 +282,18 @@ expect.assertions(2) | ||
}) | ||
it('Categories list', async () => { | ||
expect.assertions(5) | ||
const results = await api.categoriesList() | ||
expect(results).toHaveProperty('status', 'true') | ||
expect(results.feeds.length).toBeGreaterThan(10) | ||
expect(results.count).toBeGreaterThan(10) | ||
expect(results.feeds[0]).toHaveProperty('id', 1) | ||
expect(results.feeds[0]).toHaveProperty('name', 'Arts') | ||
}) | ||
// it('Hub pun notify', async () => { | ||
// expect.assertions(2) | ||
// const results = await api.hubPubNotify(75075) | ||
// expect(results).toHaveProperty('status', 'true') | ||
// expect(results).toHaveProperty('description', 'Feed marked for immediate update.') | ||
// }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32059
674
78