@pipedream/recreation_gov 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ import app from "../../recreation_gov.app.mjs";
2
+
3
+ export default {
4
+ key: "recreation_gov-get-recreation-area",
5
+ version: "0.0.1",
6
+ type: "action",
7
+ name: "Get Recreation Area",
8
+ description: "Retrieves details of a specific campsite. [See the documentation](https://ridb.recreation.gov/docs#/Campsites/getCampsites)",
9
+ props: {
10
+ app,
11
+ recAreaId: {
12
+ propDefinition: [
13
+ app,
14
+ "recAreaId",
15
+ ],
16
+ },
17
+ },
18
+ async run ({ $ }) {
19
+ const resp = this.app.getRecArea({
20
+ $,
21
+ recAreaId: this.recAreaId,
22
+ params: {
23
+ full: "true",
24
+ },
25
+ });
26
+ $.export("$summary", `Recreation Area - ${resp.RecAreaName} has been retrieved.`);
27
+ return resp;
28
+ },
29
+ };
@@ -0,0 +1,46 @@
1
+ import app from "../../recreation_gov.app.mjs";
2
+ import utils from "../../common/utils.mjs";
3
+
4
+ export default {
5
+ key: "recreation_gov-search-campsites",
6
+ version: "0.0.1",
7
+ type: "action",
8
+ name: "Search Campsites",
9
+ description: "Searchs campsites with the given query. If no query given, returns campsites from the beginning. Returning campsite number is limited to `1000`. [See the documentation](https://ridb.recreation.gov/docs#/Campsites/getCampsites)",
10
+ props: {
11
+ app,
12
+ query: {
13
+ type: "string",
14
+ label: "Query",
15
+ description: "Query filter criteria. Searches on campsite name, type, loop, type of use (Overnight/Day), campsite accessible (Yes/No)",
16
+ optional: true,
17
+ },
18
+ offset: {
19
+ type: "integer",
20
+ label: "Offset",
21
+ description: "Used when all results could not be retrieved due to limit of `1000`. Set this offset to fetch next resources.",
22
+ optional: true,
23
+ },
24
+ },
25
+ async run ({ $ }) {
26
+ const resourcesStream = utils.getResourcesStream({
27
+ resourceFn: this.app.getCampsites,
28
+ resourceKey: "RECDATA",
29
+ resourceLimit: 1000,
30
+ offset: this.offset,
31
+ resourceFnArgs: {
32
+ $,
33
+ params: {
34
+ query: this.query,
35
+ },
36
+ },
37
+ });
38
+ const items = [];
39
+ for await (const item of resourcesStream) {
40
+ items.push(item);
41
+ }
42
+ // eslint-disable-next-line multiline-ternary
43
+ $.export("$summary", `${items.length} campsite${items.length == 1 ? "" : "s"} found.`);
44
+ return items;
45
+ },
46
+ };
@@ -0,0 +1,72 @@
1
+ import app from "../../recreation_gov.app.mjs";
2
+ import utils from "../../common/utils.mjs";
3
+
4
+ export default {
5
+ key: "recreation_gov-search-recreation-areas",
6
+ version: "0.0.1",
7
+ type: "action",
8
+ name: "Search Recreation Areas",
9
+ description: "Searchs recreation areas with the given properties. If no parameters given, returns all. [See the documentation](https://ridb.recreation.gov/docs#/Recreation%20Areas/getRecAreas)",
10
+ props: {
11
+ app,
12
+ query: {
13
+ type: "string",
14
+ label: "Query",
15
+ description: "Query filter criteria. Searches on RecArea name, description, keywords, and stay limit",
16
+ optional: true,
17
+ },
18
+ states: {
19
+ propDefinition: [
20
+ app,
21
+ "states",
22
+ ],
23
+ },
24
+ activities: {
25
+ propDefinition: [
26
+ app,
27
+ "activities",
28
+ ],
29
+ },
30
+ latitude: {
31
+ type: "string",
32
+ label: "Latitude",
33
+ description: "Latitude of the point in decimal degrees",
34
+ optional: true,
35
+ },
36
+ longitude: {
37
+ type: "string",
38
+ label: "Longitude",
39
+ description: "Longitude of the point in decimal degrees",
40
+ optional: true,
41
+ },
42
+ radius: {
43
+ type: "string",
44
+ label: "Radius",
45
+ description: "Distance (in miles) by which to include search results",
46
+ optional: true,
47
+ },
48
+ },
49
+ async run ({ $ }) {
50
+ const resourcesStream = utils.getResourcesStream({
51
+ resourceFn: this.app.getRecAreas,
52
+ resourceKey: "RECDATA",
53
+ resourceFnArgs: {
54
+ $,
55
+ params: {
56
+ query: this.query,
57
+ state: this.states?.join(","),
58
+ activity: this.activities?.join(","),
59
+ latitude: this.latitude,
60
+ longitude: this.longitude,
61
+ radius: this.radius,
62
+ },
63
+ },
64
+ });
65
+ const items = [];
66
+ for await (const item of resourcesStream)
67
+ items.push(item);
68
+ // eslint-disable-next-line multiline-ternary
69
+ $.export("$summary", `${items.length} recreation area${items.length == 1 ? "" : "s"} found.`);
70
+ return items;
71
+ },
72
+ };
@@ -0,0 +1,230 @@
1
+ const states = [
2
+ {
3
+ "label": "ALABAMA",
4
+ "value": "AL",
5
+ },
6
+ {
7
+ "label": "ALASKA",
8
+ "value": "AK",
9
+ },
10
+ {
11
+ "label": "AMERICAN SAMOA",
12
+ "value": "AS",
13
+ },
14
+ {
15
+ "label": "ARIZONA",
16
+ "value": "AZ",
17
+ },
18
+ {
19
+ "label": "ARKANSAS",
20
+ "value": "AR",
21
+ },
22
+ {
23
+ "label": "CALIFORNIA",
24
+ "value": "CA",
25
+ },
26
+ {
27
+ "label": "COLORADO",
28
+ "value": "CO",
29
+ },
30
+ {
31
+ "label": "CONNECTICUT",
32
+ "value": "CT",
33
+ },
34
+ {
35
+ "label": "DELAWARE",
36
+ "value": "DE",
37
+ },
38
+ {
39
+ "label": "DISTRICT OF COLUMBIA",
40
+ "value": "DC",
41
+ },
42
+ {
43
+ "label": "FLORIDA",
44
+ "value": "FL",
45
+ },
46
+ {
47
+ "label": "GEORGIA",
48
+ "value": "GA",
49
+ },
50
+ {
51
+ "label": "GUAM",
52
+ "value": "GU",
53
+ },
54
+ {
55
+ "label": "HAWAII",
56
+ "value": "HI",
57
+ },
58
+ {
59
+ "label": "IDAHO",
60
+ "value": "ID",
61
+ },
62
+ {
63
+ "label": "ILLINOIS",
64
+ "value": "IL",
65
+ },
66
+ {
67
+ "label": "INDIANA",
68
+ "value": "IN",
69
+ },
70
+ {
71
+ "label": "IOWA",
72
+ "value": "IA",
73
+ },
74
+ {
75
+ "label": "KANSAS",
76
+ "value": "KS",
77
+ },
78
+ {
79
+ "label": "KENTUCKY",
80
+ "value": "KY",
81
+ },
82
+ {
83
+ "label": "LOUISIANA",
84
+ "value": "LA",
85
+ },
86
+ {
87
+ "label": "MAINE",
88
+ "value": "ME",
89
+ },
90
+ {
91
+ "label": "MARYLAND",
92
+ "value": "MD",
93
+ },
94
+ {
95
+ "label": "MASSACHUSETTS",
96
+ "value": "MA",
97
+ },
98
+ {
99
+ "label": "MICHIGAN",
100
+ "value": "MI",
101
+ },
102
+ {
103
+ "label": "MINNESOTA",
104
+ "value": "MN",
105
+ },
106
+ {
107
+ "label": "MISSISSIPPI",
108
+ "value": "MS",
109
+ },
110
+ {
111
+ "label": "MISSOURI",
112
+ "value": "MO",
113
+ },
114
+ {
115
+ "label": "MONTANA",
116
+ "value": "MT",
117
+ },
118
+ {
119
+ "label": "NEBRASKA",
120
+ "value": "NE",
121
+ },
122
+ {
123
+ "label": "NEVADA",
124
+ "value": "NV",
125
+ },
126
+ {
127
+ "label": "NEW HAMPSHIRE",
128
+ "value": "NH",
129
+ },
130
+ {
131
+ "label": "NEW JERSEY",
132
+ "value": "NJ",
133
+ },
134
+ {
135
+ "label": "NEW MEXICO",
136
+ "value": "NM",
137
+ },
138
+ {
139
+ "label": "NEW YORK",
140
+ "value": "NY",
141
+ },
142
+ {
143
+ "label": "NORTH CAROLINA",
144
+ "value": "NC",
145
+ },
146
+ {
147
+ "label": "NORTH DAKOTA",
148
+ "value": "ND",
149
+ },
150
+ {
151
+ "label": "NORTHERN MARIANA IS",
152
+ "value": "MP",
153
+ },
154
+ {
155
+ "label": "OHIO",
156
+ "value": "OH",
157
+ },
158
+ {
159
+ "label": "OKLAHOMA",
160
+ "value": "OK",
161
+ },
162
+ {
163
+ "label": "OREGON",
164
+ "value": "OR",
165
+ },
166
+ {
167
+ "label": "PENNSYLVANIA",
168
+ "value": "PA",
169
+ },
170
+ {
171
+ "label": "PUERTO RICO",
172
+ "value": "PR",
173
+ },
174
+ {
175
+ "label": "RHODE ISLAND",
176
+ "value": "RI",
177
+ },
178
+ {
179
+ "label": "SOUTH CAROLINA",
180
+ "value": "SC",
181
+ },
182
+ {
183
+ "label": "SOUTH DAKOTA",
184
+ "value": "SD",
185
+ },
186
+ {
187
+ "label": "TENNESSEE",
188
+ "value": "TN",
189
+ },
190
+ {
191
+ "label": "TEXAS",
192
+ "value": "TX",
193
+ },
194
+ {
195
+ "label": "UTAH",
196
+ "value": "UT",
197
+ },
198
+ {
199
+ "label": "VERMONT",
200
+ "value": "VT",
201
+ },
202
+ {
203
+ "label": "VIRGINIA",
204
+ "value": "VA",
205
+ },
206
+ {
207
+ "label": "VIRGIN ISLANDS",
208
+ "value": "VI",
209
+ },
210
+ {
211
+ "label": "WASHINGTON",
212
+ "value": "WA",
213
+ },
214
+ {
215
+ "label": "WEST VIRGINIA",
216
+ "value": "WV",
217
+ },
218
+ {
219
+ "label": "WISCONSIN",
220
+ "value": "WI",
221
+ },
222
+ {
223
+ "label": "WYOMING",
224
+ "value": "WY",
225
+ },
226
+ ];
227
+
228
+ export {
229
+ states,
230
+ };
@@ -0,0 +1,67 @@
1
+ const PAGE_SIZE = 50;
2
+
3
+ export default {
4
+ async asyncPropHandler({
5
+ resourceFn, resourceKey, page, labelVal, params,
6
+ } = {}) {
7
+ let resp = await resourceFn({
8
+ ...params,
9
+ params: {
10
+ ...params?.params,
11
+ ...(typeof page != "undefined" && {
12
+ offset: page * PAGE_SIZE,
13
+ limit: PAGE_SIZE,
14
+ }),
15
+ },
16
+ });
17
+ const items = resourceKey.split(".").reduce((acc, curr) => acc?.[curr], resp);
18
+ const label = labelVal?.label ?? "name";
19
+ const value = labelVal?.value ?? "id";
20
+ const options = items.map((item) => ({
21
+ label: typeof label == "string" ?
22
+ label.split(".").reduce((acc, curr) => acc?.[curr], item) :
23
+ label(item),
24
+ value: typeof value == "string" ?
25
+ value.split(".").reduce((acc, curr) => acc?.[curr], item) :
26
+ value(item),
27
+ }));
28
+ return typeof page != "undefined"
29
+ ? {
30
+ options,
31
+ context: {
32
+ page: page + 1,
33
+ },
34
+ } :
35
+ options;
36
+ },
37
+ async *getResourcesStream({
38
+ resourceFn, resourceFnArgs, resourceLimit, resourceKey, offset,
39
+ }) {
40
+ let page = 0, resourceCount = 0, startOffset = offset ?? 0;
41
+ while (true) {
42
+ const nextResources = await resourceFn({
43
+ ...resourceFnArgs,
44
+ params: {
45
+ ...resourceFnArgs?.params,
46
+ limit: PAGE_SIZE,
47
+ offset: startOffset + PAGE_SIZE * page++,
48
+ },
49
+ });
50
+ const resources = resourceKey
51
+ ? resourceKey.split(".").reduce((acc, curr) => acc?.[curr], nextResources)
52
+ : nextResources;
53
+ if (!resources?.length)
54
+ return;
55
+ for (const resource of resources) {
56
+ if (resourceLimit && resourceLimit < ++resourceCount) {
57
+ return;
58
+ } else {
59
+ yield resource;
60
+ }
61
+ }
62
+ if (resources?.length < PAGE_SIZE) {
63
+ return;
64
+ }
65
+ }
66
+ },
67
+ };
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@pipedream/recreation_gov",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Pipedream Recreation.gov Components",
5
5
  "main": "dist/app/recreation_gov.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "recreation_gov"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/recreation_gov",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
- "license": "MIT",
16
12
  "publishConfig": {
17
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1"
18
17
  }
19
18
  }
@@ -0,0 +1,130 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import utils from "./common/utils.mjs";
3
+ import { states } from "./common/constants.mjs";
4
+
5
+ export default {
6
+ type: "app",
7
+ app: "recreation_gov",
8
+ propDefinitions: {
9
+ recAreaId: {
10
+ type: "string",
11
+ label: "Recreation Area Id",
12
+ description: "Recreation Area Id",
13
+ async options({ page }) {
14
+ return utils.asyncPropHandler({
15
+ resourceFn: this.getRecAreas,
16
+ page,
17
+ resourceKey: "RECDATA",
18
+ labelVal: {
19
+ label: "RecAreaName",
20
+ value: "RecAreaID",
21
+ },
22
+ });
23
+ },
24
+ },
25
+ campsiteId: {
26
+ type: "string",
27
+ label: "Campsite Id",
28
+ description: "Campsite Id",
29
+ async options({ page }) {
30
+ return utils.asyncPropHandler({
31
+ resourceFn: this.getCampsites,
32
+ page,
33
+ resourceKey: "RECDATA",
34
+ labelVal: {
35
+ label: "CampsiteName",
36
+ value: "CampsiteID",
37
+ },
38
+ });
39
+ },
40
+ },
41
+ activities: {
42
+ type: "integer[]",
43
+ label: "Activities",
44
+ description: "Activity Ids",
45
+ optional: true,
46
+ async options({ page }) {
47
+ return utils.asyncPropHandler({
48
+ resourceFn: this.getActivities,
49
+ page,
50
+ resourceKey: "RECDATA",
51
+ labelVal: {
52
+ label: "ActivityName",
53
+ value: "ActivityID",
54
+ },
55
+ });
56
+ },
57
+ },
58
+ states: {
59
+ type: "string[]",
60
+ label: "States",
61
+ description: "Two-letter state abbreviations",
62
+ optional: true,
63
+ options: states,
64
+ },
65
+ },
66
+ methods: {
67
+ _getUrl(path) {
68
+ return `https://ridb.recreation.gov/api/v1${path}`;
69
+ },
70
+ _getHeaders(headers = {}) {
71
+ return {
72
+ "Content-Type": "application/json",
73
+ "Accept": "application/json",
74
+ "User-Agent": "@PipedreamHQ/pipedream v0.1",
75
+ ...headers,
76
+ };
77
+ },
78
+ async _makeRequest({
79
+ $, path, params, headers, ...otherConfig
80
+ } = {}) {
81
+ const config = {
82
+ url: this._getUrl(path),
83
+ headers: this._getHeaders(headers),
84
+ params: {
85
+ apikey: this.$auth.api_key,
86
+ ...params,
87
+ },
88
+ ...otherConfig,
89
+ };
90
+ console.log("axios config", config);
91
+ return axios($ ?? this, config);
92
+ },
93
+ async getCampsites(args = {}) {
94
+ return this._makeRequest({
95
+ path: "/campsites",
96
+ ...args,
97
+ });
98
+ },
99
+ async getCampsite({
100
+ campsiteId,
101
+ ...args
102
+ } = {}) {
103
+ return this._makeRequest({
104
+ path: `/campsites/${campsiteId}`,
105
+ ...args,
106
+ });
107
+ },
108
+ async getRecAreas(args = {}) {
109
+ return this._makeRequest({
110
+ path: "/recareas",
111
+ ...args,
112
+ });
113
+ },
114
+ async getRecArea({
115
+ recAreaId,
116
+ ...args
117
+ } = {}) {
118
+ return this._makeRequest({
119
+ path: `/recareas/${recAreaId}`,
120
+ ...args,
121
+ });
122
+ },
123
+ async getActivities(args = {}) {
124
+ return this._makeRequest({
125
+ path: "/activities",
126
+ ...args,
127
+ });
128
+ },
129
+ },
130
+ };
@@ -0,0 +1,46 @@
1
+ import common from "../common/attribute-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "recreation_gov-campsite-availability-changed",
6
+ name: "New Campsite Availability Changed Event",
7
+ description: "Emit new events when selected campsite's availability is changed. [See the documentation](https://ridb.recreation.gov/docs#/Campsites/getCampsite)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ campsiteId: {
14
+ propDefinition: [
15
+ common.props.app,
16
+ "campsiteId",
17
+ ],
18
+ },
19
+ },
20
+ methods: {
21
+ ...common.methods,
22
+ getResourceFnConfig() {
23
+ return {
24
+ resourceFn: this.app.getCampsite,
25
+ resourceKey: "RECDATA",
26
+ params: {
27
+ campsiteId: this.campsiteId,
28
+ },
29
+ };
30
+ },
31
+ getMeta(item) {
32
+ return {
33
+ ts: new Date().getTime(),
34
+ id: new Date().getTime(),
35
+ // eslint-disable-next-line multiline-ternary
36
+ summary: `Campsite(${item.CampsiteName}) availability was changed to ${item.CampsiteAccessible ? "available" : "not available"}`,
37
+ };
38
+ },
39
+ compareFn(item) {
40
+ return item.CampsiteAccessible !== this.getAttribute();
41
+ },
42
+ getAttributeKey() {
43
+ return "CampsiteAccessible";
44
+ },
45
+ },
46
+ };
@@ -0,0 +1,29 @@
1
+ import base from "./base.mjs";
2
+
3
+ export default {
4
+ ...base,
5
+ methods: {
6
+ ...base.methods,
7
+ setAttribute(attribute) {
8
+ this.db.set("attribute", attribute);
9
+ },
10
+ getAttribute() {
11
+ return this.db.get("attribute");
12
+ },
13
+ getAttributeKey() {
14
+ throw new Error("getAttributeKey() is not implemented!");
15
+ },
16
+ compareFn() {
17
+ throw new Error("compareFn() is not implemented!");
18
+ },
19
+ },
20
+ async run() {
21
+ const item = await this.getResourceFnConfig().resourceFn({
22
+ ...this.getResourceFnConfig().params,
23
+ });
24
+ if (this.compareFn(item[0])) { //the API always returns an array with a single element
25
+ this.$emit(item[0], this.getMeta(item[0]));
26
+ this.setAttribute(item[0][this.getAttributeKey()]);
27
+ }
28
+ },
29
+ };
@@ -0,0 +1,23 @@
1
+ import app from "../../recreation_gov.app.mjs";
2
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
+
4
+ export default {
5
+ props: {
6
+ app,
7
+ timer: {
8
+ type: "$.interface.timer",
9
+ default: {
10
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
11
+ },
12
+ },
13
+ db: "$.service.db",
14
+ },
15
+ methods: {
16
+ getResourceFnConfig() {
17
+ throw new Error("getResourceFnConfig() is not implemented!");
18
+ },
19
+ getMeta() {
20
+ throw new Error("getMeta() is not implemented!");
21
+ },
22
+ },
23
+ };
@@ -0,0 +1,42 @@
1
+ import base from "./base.mjs";
2
+ import utils from "../../common/utils.mjs";
3
+
4
+ const EVENT_COUNT = 25; // Historical event count
5
+
6
+ export default {
7
+ ...base,
8
+ methods: {
9
+ ...base.methods,
10
+ setCount(count) {
11
+ this.db.set("count", count);
12
+ },
13
+ getCount() {
14
+ return this.db.get("count") || 0;
15
+ },
16
+ getItem(item) {
17
+ return item;
18
+ },
19
+ },
20
+ hooks: {
21
+ async deploy() {
22
+ const config = this.getResourceFnConfig();
23
+ const firstResponse = await config.resourceFn(config.resourceFnArgs);
24
+ const recordCount = firstResponse?.METADATA?.RESULTS?.TOTAL_COUNT;
25
+ // eslint-disable-next-line multiline-ternary
26
+ this.setCount(recordCount > EVENT_COUNT ? recordCount - EVENT_COUNT : 0);
27
+ },
28
+ },
29
+ async run() {
30
+ let offset = this.getCount();
31
+ const resourcesStream = utils.getResourcesStream({
32
+ ...this.getResourceFnConfig(),
33
+ offset,
34
+ });
35
+ for await (const resource of resourcesStream) {
36
+ const item = await this.getItem(resource);
37
+ this.$emit(item, this.getMeta(item));
38
+ offset++;
39
+ }
40
+ this.setCount(offset);
41
+ },
42
+ };
@@ -0,0 +1,32 @@
1
+ import common from "../common/count-based.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "recreation_gov-new-recreation-area-added",
6
+ name: "New Recreation Area Added Event",
7
+ description: "Emit new events when a new recreation area is added to the Recreation.gov database. [See the documentation](https://ridb.recreation.gov/docs#/Recreation%20Areas/getRecAreas)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ getResourceFnConfig() {
14
+ return {
15
+ resourceFn: this.app.getRecAreas,
16
+ resourceKey: "RECDATA",
17
+ };
18
+ },
19
+ getMeta(item) {
20
+ return {
21
+ ts: new Date().getTime(),
22
+ id: parseInt(item.RecAreaID),
23
+ summary: `New recreation area(${item.RecAreaName}) was added to RDIB`,
24
+ };
25
+ },
26
+ async getItem(item) {
27
+ return this.app.getRecArea({
28
+ recAreaId: parseInt(item.RecAreaID),
29
+ });
30
+ },
31
+ },
32
+ };