Skip to content

Commit 04803d2

Browse files
authored
Merging pull request #18172
* new components * pnpm-lock.yaml
1 parent 7a12929 commit 04803d2

File tree

6 files changed

+1193
-8
lines changed

6 files changed

+1193
-8
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import bridgeInteractivePlatform from "../../bridge_interactive_platform.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "bridge_interactive_platform-get-listings",
6+
name: "Get Listings",
7+
description: "Get MLS listings from a dataset. [See the documentation](https://bridgedataoutput.com/docs/explorer/mls-data)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
bridgeInteractivePlatform,
12+
dataset: {
13+
propDefinition: [
14+
bridgeInteractivePlatform,
15+
"dataset",
16+
],
17+
},
18+
near: {
19+
propDefinition: [
20+
bridgeInteractivePlatform,
21+
"near",
22+
],
23+
},
24+
radius: {
25+
propDefinition: [
26+
bridgeInteractivePlatform,
27+
"radius",
28+
],
29+
},
30+
box: {
31+
propDefinition: [
32+
bridgeInteractivePlatform,
33+
"box",
34+
],
35+
},
36+
poly: {
37+
propDefinition: [
38+
bridgeInteractivePlatform,
39+
"poly",
40+
],
41+
},
42+
geohash: {
43+
propDefinition: [
44+
bridgeInteractivePlatform,
45+
"geohash",
46+
],
47+
},
48+
sortBy: {
49+
propDefinition: [
50+
bridgeInteractivePlatform,
51+
"field",
52+
(c) => ({
53+
dataset: c.dataset,
54+
}),
55+
],
56+
label: "Sort By",
57+
},
58+
order: {
59+
type: "string",
60+
label: "Order",
61+
description: "Order of responses",
62+
optional: true,
63+
options: [
64+
"asc",
65+
"desc",
66+
],
67+
},
68+
fields: {
69+
propDefinition: [
70+
bridgeInteractivePlatform,
71+
"field",
72+
(c) => ({
73+
dataset: c.dataset,
74+
}),
75+
],
76+
type: "string[]",
77+
label: "Fields",
78+
description: "Filters Response fields",
79+
},
80+
limit: {
81+
type: "integer",
82+
label: "Limit",
83+
description: "Maximum number of responses",
84+
optional: true,
85+
},
86+
offset: {
87+
type: "integer",
88+
label: "Offset",
89+
description: "Number of responses to skip",
90+
optional: true,
91+
},
92+
},
93+
async run({ $ }) {
94+
const coords = {
95+
near: this.near,
96+
poly: this.poly,
97+
box: this.box,
98+
geohash: this.geohash,
99+
};
100+
101+
if (Object.values(coords).filter(Boolean).length > 1) {
102+
throw new ConfigurationError("Only one of near, poly, box, or geohash can be used");
103+
}
104+
105+
const response = await this.bridgeInteractivePlatform.getListings({
106+
dataset: this.dataset,
107+
params: {
108+
near: this.near,
109+
radius: this.radius,
110+
box: this.box,
111+
poly: this.poly,
112+
geohash: this.geohash,
113+
sortBy: this.sortBy,
114+
order: this.order,
115+
fields: this.fields
116+
? this.fields.join(",")
117+
: undefined,
118+
limit: this.limit,
119+
offset: this.offset,
120+
},
121+
});
122+
$.export("$summary", `Found ${response.bundle.length} listings`);
123+
return response;
124+
},
125+
};
Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,84 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "bridge_interactive_platform",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
dataset: {
8+
type: "string",
9+
label: "Dataset",
10+
description: "The dataset to use for the query",
11+
},
12+
field: {
13+
type: "string",
14+
label: "Field",
15+
description: "Response field to sort query by",
16+
optional: true,
17+
async options({ dataset }) {
18+
const response = await this.getListings({
19+
dataset,
20+
params: {
21+
limit: 1,
22+
},
23+
});
24+
const listing = response.bundle[0];
25+
return Object.keys(listing);
26+
},
27+
},
28+
near: {
29+
type: "string",
30+
label: "Near",
31+
description: "Coord or location eg. near=-73.98,40.73 or near=San Diego",
32+
optional: true,
33+
},
34+
radius: {
35+
type: "string",
36+
label: "Radius",
37+
description: "Search Radius in miles, km, or degrees (no units)s",
38+
optional: true,
39+
},
40+
box: {
41+
type: "string",
42+
label: "Box",
43+
description: "Coordinates representing a box eg. box=-112.5,33.75,-123,39",
44+
optional: true,
45+
},
46+
poly: {
47+
type: "string",
48+
label: "Poly",
49+
description: "Minimum 3 pairs of coordinates representing a polygon eg. poly=-112.5,33.75,-123,39,-120,38",
50+
optional: true,
51+
},
52+
geohash: {
53+
type: "string",
54+
label: "Geohash",
55+
description: "Alphanumeric geohash eg. geohash=ezs42",
56+
optional: true,
57+
},
58+
},
559
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
60+
_baseUrl() {
61+
return "https://api.bridgedataoutput.com/api/v2";
62+
},
63+
_makeRequest({
64+
$ = this, path, params, ...opts
65+
}) {
66+
return axios($, {
67+
url: `${this._baseUrl()}${path}`,
68+
params: {
69+
...params,
70+
access_token: `${this.$auth.access_token}`,
71+
},
72+
...opts,
73+
});
74+
},
75+
getListings({
76+
dataset, ...opts
77+
}) {
78+
return this._makeRequest({
79+
path: `/${dataset}/listings`,
80+
...opts,
81+
});
982
},
1083
},
11-
};
84+
};

components/bridge_interactive_platform/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/bridge_interactive_platform",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Bridge Interactive Platform Components",
55
"main": "bridge_interactive_platform.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: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import bridgeInteractivePlatform from "../../bridge_interactive_platform.app.mjs";
2+
import {
3+
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
4+
} from "@pipedream/platform";
5+
import sampleEmit from "./test-event.mjs";
6+
7+
export default {
8+
key: "bridge_interactive_platform-new-listing-created",
9+
name: "New Listing Created",
10+
description: "Emit new event when a new listing is created. [See the documentation](https://bridgedataoutput.com/docs/explorer/mls-data)",
11+
version: "0.0.1",
12+
type: "source",
13+
props: {
14+
bridgeInteractivePlatform,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
dataset: {
23+
propDefinition: [
24+
bridgeInteractivePlatform,
25+
"dataset",
26+
],
27+
},
28+
near: {
29+
propDefinition: [
30+
bridgeInteractivePlatform,
31+
"near",
32+
],
33+
},
34+
radius: {
35+
propDefinition: [
36+
bridgeInteractivePlatform,
37+
"radius",
38+
],
39+
},
40+
box: {
41+
propDefinition: [
42+
bridgeInteractivePlatform,
43+
"box",
44+
],
45+
},
46+
poly: {
47+
propDefinition: [
48+
bridgeInteractivePlatform,
49+
"poly",
50+
],
51+
},
52+
geohash: {
53+
propDefinition: [
54+
bridgeInteractivePlatform,
55+
"geohash",
56+
],
57+
},
58+
},
59+
methods: {
60+
_getLastTs() {
61+
return this.db.get("lastTs") || 0;
62+
},
63+
_setLastTs(ts) {
64+
this.db.set("lastTs", ts);
65+
},
66+
async processEvent(limit = 100) {
67+
const coords = {
68+
near: this.near,
69+
poly: this.poly,
70+
box: this.box,
71+
geohash: this.geohash,
72+
};
73+
74+
if (Object.values(coords).filter(Boolean).length > 1) {
75+
throw new ConfigurationError("Only one of near, poly, box, or geohash can be used");
76+
}
77+
78+
const lastTs = this._getLastTs();
79+
const response = await this.bridgeInteractivePlatform.getListings({
80+
dataset: this.dataset,
81+
params: {
82+
near: this.near,
83+
radius: this.radius,
84+
box: this.box,
85+
poly: this.poly,
86+
geohash: this.geohash,
87+
sortBy: "OriginalEntryTimestamp",
88+
order: "desc",
89+
limit,
90+
},
91+
});
92+
93+
if (!response?.bundle?.length) {
94+
return;
95+
};
96+
97+
this._setLastTs(Date.parse(response.bundle[0].OriginalEntryTimestamp));
98+
99+
const newListings = response.bundle
100+
.filter((listing) => Date.parse(listing.OriginalEntryTimestamp) > lastTs);
101+
newListings.forEach((listing) => {
102+
const meta = this.generateMeta(listing);
103+
this.$emit(listing, meta);
104+
});
105+
},
106+
generateMeta(listing) {
107+
return {
108+
id: listing.ListingId,
109+
summary: `New Listing Created: ${listing.ListingId}`,
110+
ts: Date.parse(listing.OriginalEntryTimestamp),
111+
};
112+
},
113+
},
114+
hooks: {
115+
async deploy() {
116+
await this.processEvent(25);
117+
},
118+
},
119+
async run() {
120+
await this.processEvent();
121+
},
122+
sampleEmit,
123+
};

0 commit comments

Comments
 (0)