Skip to content

Commit d959284

Browse files
Merge branch 'master' into feat/run-action-stash-id
2 parents 418a41c + 281b9df commit d959284

File tree

28 files changed

+707
-33
lines changed

28 files changed

+707
-33
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import changesPage from "../../changes_page.app.mjs";
2+
3+
export default {
4+
key: "changes_page-get-latest-post",
5+
name: "Get Latest Post",
6+
description: "Get the latest post from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-latest-post)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
changesPage,
11+
},
12+
async run({ $ }) {
13+
const post = await this.changesPage.getLatestPost({
14+
$,
15+
});
16+
$.export("$summary", "Successfully retrieved latest post");
17+
return post;
18+
},
19+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import changesPage from "../../changes_page.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "changes_page-get-pinned-post",
6+
name: "Get Pinned Post",
7+
description: "Get the pinned post from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-pinned-post)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
changesPage,
12+
},
13+
async run({ $ }) {
14+
try {
15+
const post = await this.changesPage.getPinnedPost({
16+
$,
17+
});
18+
$.export("$summary", "Successfully retrieved pinned post");
19+
return post;
20+
} catch (error) {
21+
if (error.response?.status === 404) {
22+
throw new ConfigurationError("No pinned post found");
23+
}
24+
throw error;
25+
}
26+
},
27+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import changesPage from "../../changes_page.app.mjs";
2+
3+
export default {
4+
key: "changes_page-get-post",
5+
name: "Get Post",
6+
description: "Get a post by ID from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-a-post-by-id)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
changesPage,
11+
postId: {
12+
propDefinition: [
13+
changesPage,
14+
"postId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const post = await this.changesPage.getPost({
20+
$,
21+
postId: this.postId,
22+
});
23+
$.export("$summary", `Successfully retrieved post ${this.postId}`);
24+
return post;
25+
},
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import changesPage from "../../changes_page.app.mjs";
2+
3+
export default {
4+
key: "changes_page-list-posts",
5+
name: "List Posts",
6+
description: "Retrieve a list of posts from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-all-posts)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
changesPage,
11+
maxResults: {
12+
type: "integer",
13+
label: "Max Results",
14+
description: "The maximum number of posts to retrieve",
15+
default: 100,
16+
},
17+
},
18+
async run({ $ }) {
19+
const posts = await this.changesPage.getPaginatedResources({
20+
fn: this.changesPage.listPosts,
21+
max: this.maxResults,
22+
});
23+
$.export("$summary", `Successfully retrieved ${posts.length} posts`);
24+
return posts;
25+
},
26+
};
Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,97 @@
1+
import { axios } from "@pipedream/platform";
2+
const DEFAULT_LIMIT = 50;
3+
14
export default {
25
type: "app",
36
app: "changes_page",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
postId: {
9+
type: "string",
10+
label: "Post ID",
11+
description: "The ID of the post to retrieve",
12+
async options({ page }) {
13+
const posts = await this.listPosts({
14+
params: {
15+
offset: page * DEFAULT_LIMIT,
16+
},
17+
});
18+
return posts.map((post) => ({
19+
label: post.title,
20+
value: post.id,
21+
}));
22+
},
23+
},
24+
},
525
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
26+
_baseUrl() {
27+
return `https://${this.$auth.subdomain}.changes.page`;
28+
},
29+
_makeRequest({
30+
$ = this, path, ...opts
31+
}) {
32+
return axios($, {
33+
url: `${this._baseUrl()}${path}`,
34+
...opts,
35+
});
36+
},
37+
getPost({
38+
postId, ...opts
39+
}) {
40+
return this._makeRequest({
41+
path: `/changes.json/${postId}`,
42+
...opts,
43+
});
44+
},
45+
getLatestPost(opts = {}) {
46+
return this._makeRequest({
47+
path: "/latest.json",
48+
...opts,
49+
});
50+
},
51+
getPinnedPost(opts = {}) {
52+
return this._makeRequest({
53+
path: "/pinned.json",
54+
...opts,
55+
});
56+
},
57+
listPosts(opts = {}) {
58+
return this._makeRequest({
59+
path: "/changes.json",
60+
...opts,
61+
});
62+
},
63+
async *paginate({
64+
fn, params = {}, max,
65+
}) {
66+
params = {
67+
...params,
68+
offset: 0,
69+
};
70+
let total, count = 0;
71+
do {
72+
const response = await fn({
73+
params,
74+
});
75+
if (!response || response.length === 0) {
76+
break;
77+
}
78+
for (const item of response) {
79+
yield item;
80+
if (max && ++count >= max) {
81+
return;
82+
}
83+
}
84+
total = response.length;
85+
params.offset += DEFAULT_LIMIT;
86+
} while (total === DEFAULT_LIMIT);
87+
},
88+
async getPaginatedResources(opts = {}) {
89+
const resources = this.paginate(opts);
90+
const items = [];
91+
for await (const item of resources) {
92+
items.push(item);
93+
}
94+
return items;
995
},
1096
},
1197
};

components/changes_page/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/changes_page",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream changes.page Components",
55
"main": "changes_page.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import changesPage from "../../changes_page.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
key: "changes_page-new-post-created",
6+
name: "New Post Created",
7+
description: "Emit new event when a new post is created. [See the documentation](https://docs.changes.page/docs/api/page#get-all-posts)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
changesPage,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
},
21+
methods: {
22+
_getLastTs() {
23+
return this.db.get("lastTs") || 0;
24+
},
25+
_setLastTs(ts) {
26+
this.db.set("lastTs", ts);
27+
},
28+
generateMeta(post) {
29+
return {
30+
id: post.id,
31+
summary: post.title,
32+
ts: Date.parse(post.created_at),
33+
};
34+
},
35+
async processEvent(max) {
36+
const lastTs = this._getLastTs();
37+
const results = this.changesPage.paginate({
38+
fn: this.changesPage.listPosts,
39+
max,
40+
});
41+
const posts = [];
42+
for await (const post of results) {
43+
if (Date.parse(post.created_at) > lastTs) {
44+
posts.push(post);
45+
} else {
46+
break;
47+
}
48+
}
49+
if (!posts.length) {
50+
return;
51+
}
52+
this._setLastTs(Date.parse(posts[0].created_at));
53+
posts.reverse().forEach((post) => {
54+
const meta = this.generateMeta(post);
55+
this.$emit(post, meta);
56+
});
57+
},
58+
},
59+
hooks: {
60+
async deploy() {
61+
await this.processEvent(25);
62+
},
63+
},
64+
async run() {
65+
await this.processEvent();
66+
},
67+
};

components/codeqr/codeqr.app.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
type: "app",
3+
app: "codeqr",
4+
propDefinitions: {},
5+
methods: {
6+
// this.$auth contains connected account data
7+
authKeys() {
8+
console.log(Object.keys(this.$auth));
9+
},
10+
},
11+
};

components/codeqr/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@pipedream/codeqr",
3+
"version": "0.0.1",
4+
"description": "Pipedream CodeQR Components",
5+
"main": "codeqr.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"codeqr"
9+
],
10+
"homepage": "https://pipedream.com/apps/codeqr",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
}
15+
}

0 commit comments

Comments
 (0)