所有信息源
Product Hunt
新闻 v1.0.0Today's top products from Product Hunt
@codytseng #producthunt #products #startups
配置项
| 名称 | 键 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|---|
| API Token | API_TOKEN | secret | 是 | — | Product Hunt Developer Token (get one at https://api.producthunt.com/v2/oauth/applications) |
源代码
version: 1.0.0
name: Product Hunt
description: Today's top products from Product Hunt
author: codytseng
author_url: https://github.com/codytseng
category: News
tags:
- producthunt
- products
- startups
config:
- key: API_TOKEN
name: API Token
type: secret
required: true
description: Product Hunt Developer Token (get one at https://api.producthunt.com/v2/oauth/applications) version: 1.0.0
name: Product Hunt
description: Today's top products from Product Hunt
author: codytseng
author_url: https://github.com/codytseng
category: News
tags:
- producthunt
- products
- startups
config:
- key: API_TOKEN
name: API Token
type: secret
required: true
description: Product Hunt Developer Token (get one at https://api.producthunt.com/v2/oauth/applications) module.exports = async (api) => {
const token = api.config.get("API_TOKEN");
async function fetchData() {
const query = `{
posts(order: RANKING) {
edges {
node {
id
name
tagline
url
votesCount
createdAt
}
}
}
}`;
const response = await api.fetch("https://api.producthunt.com/v2/api/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ query }),
});
if (!response.ok || !response.json) {
throw new Error(`Failed to fetch Product Hunt posts (HTTP ${response.status})`);
}
api.emit(
response.json.data.posts.edges.map((edge) => ({
id: edge.node.id,
title: edge.node.name,
subtitle: edge.node.tagline,
url: edge.node.url,
timestamp: edge.node.createdAt,
})),
);
}
await fetchData();
return {
refresh: fetchData,
};
}; module.exports = async (api) => {
const token = api.config.get("API_TOKEN");
async function fetchData() {
const query = `{
posts(order: RANKING) {
edges {
node {
id
name
tagline
url
votesCount
createdAt
}
}
}
}`;
const response = await api.fetch("https://api.producthunt.com/v2/api/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ query }),
});
if (!response.ok || !response.json) {
throw new Error(`Failed to fetch Product Hunt posts (HTTP ${response.status})`);
}
api.emit(
response.json.data.posts.edges.map((edge) => ({
id: edge.node.id,
title: edge.node.name,
subtitle: edge.node.tagline,
url: edge.node.url,
timestamp: edge.node.createdAt,
})),
);
}
await fetchData();
return {
refresh: fetchData,
};
};