-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - bridge_interactive_platform #18172
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 all commits
Commits
Show all changes
2 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
125 changes: 125 additions & 0 deletions
125
components/bridge_interactive_platform/actions/get-listings/get-listings.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,125 @@ | ||
| import bridgeInteractivePlatform from "../../bridge_interactive_platform.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| key: "bridge_interactive_platform-get-listings", | ||
| name: "Get Listings", | ||
| description: "Get MLS listings from a dataset. [See the documentation](https://bridgedataoutput.com/docs/explorer/mls-data)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| bridgeInteractivePlatform, | ||
| dataset: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "dataset", | ||
| ], | ||
| }, | ||
| near: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "near", | ||
| ], | ||
| }, | ||
| radius: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "radius", | ||
| ], | ||
| }, | ||
| box: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "box", | ||
| ], | ||
| }, | ||
| poly: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "poly", | ||
| ], | ||
| }, | ||
| geohash: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "geohash", | ||
| ], | ||
| }, | ||
| sortBy: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "field", | ||
| (c) => ({ | ||
| dataset: c.dataset, | ||
| }), | ||
| ], | ||
| label: "Sort By", | ||
| }, | ||
| order: { | ||
| type: "string", | ||
| label: "Order", | ||
| description: "Order of responses", | ||
| optional: true, | ||
| options: [ | ||
| "asc", | ||
| "desc", | ||
| ], | ||
| }, | ||
| fields: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "field", | ||
| (c) => ({ | ||
| dataset: c.dataset, | ||
| }), | ||
| ], | ||
| type: "string[]", | ||
| label: "Fields", | ||
| description: "Filters Response fields", | ||
| }, | ||
| limit: { | ||
| type: "integer", | ||
| label: "Limit", | ||
| description: "Maximum number of responses", | ||
| optional: true, | ||
| }, | ||
| offset: { | ||
| type: "integer", | ||
| label: "Offset", | ||
| description: "Number of responses to skip", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const coords = { | ||
| near: this.near, | ||
| poly: this.poly, | ||
| box: this.box, | ||
| geohash: this.geohash, | ||
| }; | ||
|
|
||
| if (Object.values(coords).filter(Boolean).length > 1) { | ||
| throw new ConfigurationError("Only one of near, poly, box, or geohash can be used"); | ||
| } | ||
|
|
||
| const response = await this.bridgeInteractivePlatform.getListings({ | ||
| dataset: this.dataset, | ||
| params: { | ||
| near: this.near, | ||
| radius: this.radius, | ||
| box: this.box, | ||
| poly: this.poly, | ||
| geohash: this.geohash, | ||
| sortBy: this.sortBy, | ||
| order: this.order, | ||
| fields: this.fields | ||
| ? this.fields.join(",") | ||
| : undefined, | ||
| limit: this.limit, | ||
| offset: this.offset, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Found ${response.bundle.length} listings`); | ||
| return response; | ||
| }, | ||
| }; | ||
83 changes: 78 additions & 5 deletions
83
components/bridge_interactive_platform/bridge_interactive_platform.app.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 |
|---|---|---|
| @@ -1,11 +1,84 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "bridge_interactive_platform", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| dataset: { | ||
| type: "string", | ||
| label: "Dataset", | ||
| description: "The dataset to use for the query", | ||
| }, | ||
| field: { | ||
| type: "string", | ||
| label: "Field", | ||
| description: "Response field to sort query by", | ||
| optional: true, | ||
| async options({ dataset }) { | ||
| const response = await this.getListings({ | ||
| dataset, | ||
| params: { | ||
| limit: 1, | ||
| }, | ||
| }); | ||
| const listing = response.bundle[0]; | ||
| return Object.keys(listing); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| near: { | ||
| type: "string", | ||
| label: "Near", | ||
| description: "Coord or location eg. near=-73.98,40.73 or near=San Diego", | ||
| optional: true, | ||
| }, | ||
| radius: { | ||
| type: "string", | ||
| label: "Radius", | ||
| description: "Search Radius in miles, km, or degrees (no units)s", | ||
| optional: true, | ||
| }, | ||
| box: { | ||
| type: "string", | ||
| label: "Box", | ||
| description: "Coordinates representing a box eg. box=-112.5,33.75,-123,39", | ||
| optional: true, | ||
| }, | ||
| poly: { | ||
| type: "string", | ||
| label: "Poly", | ||
| description: "Minimum 3 pairs of coordinates representing a polygon eg. poly=-112.5,33.75,-123,39,-120,38", | ||
| optional: true, | ||
| }, | ||
| geohash: { | ||
| type: "string", | ||
| label: "Geohash", | ||
| description: "Alphanumeric geohash eg. geohash=ezs42", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.bridgedataoutput.com/api/v2"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, params, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| params: { | ||
| ...params, | ||
| access_token: `${this.$auth.access_token}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getListings({ | ||
| dataset, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/${dataset}/listings`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
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/bridge_interactive_platform", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Bridge Interactive Platform Components", | ||
| "main": "bridge_interactive_platform.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
123 changes: 123 additions & 0 deletions
123
components/bridge_interactive_platform/sources/new-listing-created/new-listing-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,123 @@ | ||
| import bridgeInteractivePlatform from "../../bridge_interactive_platform.app.mjs"; | ||
| import { | ||
| DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError, | ||
| } from "@pipedream/platform"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| key: "bridge_interactive_platform-new-listing-created", | ||
| name: "New Listing Created", | ||
| description: "Emit new event when a new listing is created. [See the documentation](https://bridgedataoutput.com/docs/explorer/mls-data)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| props: { | ||
| bridgeInteractivePlatform, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| dataset: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "dataset", | ||
| ], | ||
| }, | ||
| near: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "near", | ||
| ], | ||
| }, | ||
| radius: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "radius", | ||
| ], | ||
| }, | ||
| box: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "box", | ||
| ], | ||
| }, | ||
| poly: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "poly", | ||
| ], | ||
| }, | ||
| geohash: { | ||
| propDefinition: [ | ||
| bridgeInteractivePlatform, | ||
| "geohash", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastTs() { | ||
| return this.db.get("lastTs") || 0; | ||
| }, | ||
| _setLastTs(ts) { | ||
| this.db.set("lastTs", ts); | ||
| }, | ||
| async processEvent(limit = 100) { | ||
| const coords = { | ||
| near: this.near, | ||
| poly: this.poly, | ||
| box: this.box, | ||
| geohash: this.geohash, | ||
| }; | ||
|
|
||
| if (Object.values(coords).filter(Boolean).length > 1) { | ||
| throw new ConfigurationError("Only one of near, poly, box, or geohash can be used"); | ||
| } | ||
|
|
||
| const lastTs = this._getLastTs(); | ||
| const response = await this.bridgeInteractivePlatform.getListings({ | ||
| dataset: this.dataset, | ||
| params: { | ||
| near: this.near, | ||
| radius: this.radius, | ||
| box: this.box, | ||
| poly: this.poly, | ||
| geohash: this.geohash, | ||
| sortBy: "OriginalEntryTimestamp", | ||
| order: "desc", | ||
| limit, | ||
| }, | ||
| }); | ||
|
|
||
| if (!response?.bundle?.length) { | ||
| return; | ||
| }; | ||
|
|
||
| this._setLastTs(Date.parse(response.bundle[0].OriginalEntryTimestamp)); | ||
|
|
||
| const newListings = response.bundle | ||
| .filter((listing) => Date.parse(listing.OriginalEntryTimestamp) > lastTs); | ||
| newListings.forEach((listing) => { | ||
| const meta = this.generateMeta(listing); | ||
| this.$emit(listing, meta); | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| generateMeta(listing) { | ||
| return { | ||
| id: listing.ListingId, | ||
| summary: `New Listing Created: ${listing.ListingId}`, | ||
| ts: Date.parse(listing.OriginalEntryTimestamp), | ||
| }; | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.processEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.processEvent(); | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
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.