Skip to content

Instantly share code, notes, and snippets.

@HugoDF
Created April 28, 2019 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HugoDF/48f37c693d2f17e0e6c32d3df81f7ce3 to your computer and use it in GitHub Desktop.
Save HugoDF/48f37c693d2f17e0e6c32d3df81f7ce3 to your computer and use it in GitHub Desktop.
Netlify Lambda (has to be build using netlify-lambda library) to fetch pocket entries tagged as "newsletter"
import axios from 'axios'
const {
POCKET_CONSUMER_KEY,
POCKET_ACCESS_TOKEN
} = process.env
async function fetchBookmarks() {
const res = await axios.post('https://getpocket.com/v3/get', {
consumer_key: POCKET_CONSUMER_KEY,
access_token: POCKET_ACCESS_TOKEN,
tag: 'newsletter',
state: 'all',
detailType: 'complete'
})
const { list } = res.data
// list is a key-value timestamp->entry map
const entries = Object.values(list)
return entries.map(({
given_title,
given_url,
resolved_url,
resolved_title,
excerpt,
authors,
rest,
}) => ({
...rest,
title: given_title || resolved_title,
url: given_url || resolved_url,
excerpt,
authors: authors
? Object.values(authors)
.map(({ name }) => name)
.filter(Boolean)
.join(',')
: ''
}))
}
export async function handler(event) {
if (event.httpMethod !== 'GET') {
return {
statusCode: 404,
body: 'Not Found'
}
}
const bookmarks = await fetchBookmarks()
return {
statusCode: 200,
body: JSON.stringify(bookmarks)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment