Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
},
};
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);
},
},
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,
});
},
getListings({
dataset, ...opts
}) {
return this._makeRequest({
path: `/${dataset}/listings`,
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/bridge_interactive_platform/package.json
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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
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);
});
},
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,
};
Loading
Loading