Skip to content

Commit a08135a

Browse files
Adding NewsAPI.org wrapper as a 'pkg'. (#2)
1 parent 056bfcc commit a08135a

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

blocks/pkg-news-api/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { Block } = require('node-webpipe')
2+
const NewsAPI = require('newsapi')
3+
const client = new NewsAPI(process.env.API_KEY_NEWSAPI)
4+
5+
// const { Block, Client, MSG } = require('@webpipes/server')
6+
new Block()
7+
.name("News API's Top Headline's")
8+
.description("NewsAPI.org's REST API service (https://newsapi.org)")
9+
// @NOTE: Maybe in the future, we are using some kind of standard
10+
// (&localized) in cases where we wrap other services. Maybe we can
11+
// standardize these boilerplate proxy/wrapper
12+
// user messages. NOTICE(`@NOTE/API/1`, locale)
13+
.input(
14+
'sources',
15+
// @TODO: Hack fix for `node-webpipe` server validation didn't like `array`?
16+
'object',
17+
'@NOTE/API/1: Refer to official API service docs. Defaults to the New York Times.'
18+
)
19+
.output(
20+
'articles',
21+
'object',
22+
'Top headlines and ledes from requested source(s).'
23+
)
24+
.handle(({ sources = ['the-new-york-times'] }, cb) => {
25+
const articles = client.v2
26+
.topHeadlines({
27+
sources: sources,
28+
language: 'en'
29+
})
30+
.then(({ articles }) => {
31+
cb(null, {
32+
articles
33+
})
34+
})
35+
})
36+
.listen()

blocks/pkg-news-api/package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/pkg-news-api/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "pkg-news-api",
3+
"dependencies": {
4+
"newsapi": "^2.4.0"
5+
}
6+
}

0 commit comments

Comments
 (0)