-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - changes_page #16988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
components/changes_page/actions/get-latest-post/get-latest-post.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import changesPage from "../../changes_page.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "changes_page-get-latest-post", | ||
| name: "Get Latest Post", | ||
| description: "Get the latest post from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-latest-post)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| changesPage, | ||
| }, | ||
| async run({ $ }) { | ||
| const post = await this.changesPage.getLatestPost({ | ||
| $, | ||
| }); | ||
| $.export("$summary", "Successfully retrieved latest post"); | ||
| return post; | ||
| }, | ||
| }; |
27 changes: 27 additions & 0 deletions
27
components/changes_page/actions/get-pinned-post/get-pinned-post.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import changesPage from "../../changes_page.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| key: "changes_page-get-pinned-post", | ||
| name: "Get Pinned Post", | ||
| description: "Get the pinned post from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-pinned-post)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| changesPage, | ||
| }, | ||
| async run({ $ }) { | ||
| try { | ||
| const post = await this.changesPage.getPinnedPost({ | ||
| $, | ||
| }); | ||
| $.export("$summary", "Successfully retrieved pinned post"); | ||
| return post; | ||
| } catch (error) { | ||
| if (error.response.status === 404) { | ||
| throw new ConfigurationError("No pinned post found"); | ||
| } | ||
| throw error; | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import changesPage from "../../changes_page.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "changes_page-get-post", | ||
| name: "Get Post", | ||
| description: "Get a post by ID from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-a-post-by-id)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| changesPage, | ||
| postId: { | ||
| propDefinition: [ | ||
| changesPage, | ||
| "postId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const post = await this.changesPage.getPost({ | ||
| $, | ||
| postId: this.postId, | ||
| }); | ||
| $.export("$summary", `Successfully retrieved post ${this.postId}`); | ||
| return post; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import changesPage from "../../changes_page.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "changes_page-list-posts", | ||
| name: "List Posts", | ||
| description: "Retrieve a list of posts from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-all-posts)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| changesPage, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "The maximum number of posts to retrieve", | ||
| default: 100, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const posts = await this.changesPage.getPaginatedResources({ | ||
| fn: this.changesPage.listPosts, | ||
| max: this.maxResults, | ||
| }); | ||
| $.export("$summary", `Successfully retrieved ${posts.length} posts`); | ||
| return posts; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,94 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| const DEFAULT_LIMIT = 50; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "changes_page", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| postId: { | ||
| type: "string", | ||
| label: "Post ID", | ||
| description: "The ID of the post to retrieve", | ||
| async options({ page }) { | ||
| const posts = await this.listPosts({ | ||
| params: { | ||
| offset: page * DEFAULT_LIMIT, | ||
| }, | ||
| }); | ||
| return posts.map((post) => ({ | ||
| label: post.title, | ||
| value: post.id, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return `https://${this.$auth.subdomain}.changes.page`; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getPost({ | ||
| postId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/changes.json/${postId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getLatestPost(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/latest.json", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getPinnedPost(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/pinned.json", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listPosts(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/changes.json", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, params = {}, max, | ||
| }) { | ||
| params = { | ||
| ...params, | ||
| offset: 0, | ||
| }; | ||
| let total, count = 0; | ||
| do { | ||
| const response = await fn({ | ||
| params, | ||
| }); | ||
| for (const item of response) { | ||
| yield item; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| } | ||
| total = response.length; | ||
| params.offset += DEFAULT_LIMIT; | ||
| } while (total === DEFAULT_LIMIT); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async getPaginatedResources(opts = {}) { | ||
| const resources = this.paginate(opts); | ||
| const items = []; | ||
| for await (const item of resources) { | ||
| items.push(item); | ||
| } | ||
| return items; | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/changes_page", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream changes.page Components", | ||
| "main": "changes_page.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
67 changes: 67 additions & 0 deletions
67
components/changes_page/sources/new-post-created/new-post-created.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import changesPage from "../../changes_page.app.mjs"; | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| key: "changes_page-new-post-created", | ||
| name: "New Post Created", | ||
| description: "Emit new event when a new post is created. [See the documentation](https://docs.changes.page/docs/api/page#get-all-posts)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| changesPage, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastTs() { | ||
| return this.db.get("lastTs") || 0; | ||
| }, | ||
| _setLastTs(ts) { | ||
| this.db.set("lastTs", ts); | ||
| }, | ||
| generateMeta(post) { | ||
| return { | ||
| id: post.id, | ||
| summary: post.title, | ||
| ts: Date.parse(post.created_at), | ||
| }; | ||
| }, | ||
| async processEvent(max) { | ||
| const lastTs = this._getLastTs(); | ||
| const results = this.changesPage.paginate({ | ||
| fn: this.changesPage.listPosts, | ||
| max, | ||
| }); | ||
| const posts = []; | ||
| for await (const post of results) { | ||
| if (Date.parse(post.created_at) > lastTs) { | ||
| posts.push(post); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| if (!posts.length) { | ||
| return; | ||
| } | ||
| this._setLastTs(Date.parse(posts[0].created_at)); | ||
| posts.reverse().forEach((post) => { | ||
| const meta = this.generateMeta(post); | ||
| this.$emit(post, meta); | ||
| }); | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.processEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.processEvent(); | ||
| }, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.