Все источники
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) import type { GlancewayAPI, SourceMethods } from "../../types";
export default (api: GlancewayAPI): SourceMethods => {
return {
async refresh() {
const token = api.config.get("API_TOKEN");
const query = `{
posts(order: RANKING) {
edges {
node {
id
name
tagline
url
votesCount
createdAt
}
}
}
}`;
const response = await api.fetch<{
data: {
posts: {
edges: Array<{
node: {
id: string;
name: string;
tagline: string;
url: string;
votesCount: number;
createdAt: string;
};
}>;
};
};
}>("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) {
return;
}
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,
})),
);
},
};
}; import type { GlancewayAPI, SourceMethods } from "../../types";
export default (api: GlancewayAPI): SourceMethods => {
return {
async refresh() {
const token = api.config.get("API_TOKEN");
const query = `{
posts(order: RANKING) {
edges {
node {
id
name
tagline
url
votesCount
createdAt
}
}
}
}`;
const response = await api.fetch<{
data: {
posts: {
edges: Array<{
node: {
id: string;
name: string;
tagline: string;
url: string;
votesCount: number;
createdAt: string;
};
}>;
};
};
}>("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) {
return;
}
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,
})),
);
},
};
};