Skip to content

Commit 15d9f20

Browse files
committed
Merge branch 'issue-11579' into 9395-action-zoom-app-zoom-phones-get-call-logs-action
2 parents c667e68 + 7316125 commit 15d9f20

File tree

88 files changed

+615
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+615
-123
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import foursquare from "../../foursquare.app.mjs";
2+
3+
export default {
4+
key: "foursquare-create-check-in",
5+
name: "Create Check In",
6+
description: "Allows the user to generate a new check-in at a specific location on Foursquare. [See the documentation](https://docs.foursquare.com/developer/reference/create-a-checkin)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
foursquare,
11+
venueId: {
12+
propDefinition: [
13+
foursquare,
14+
"venueId",
15+
],
16+
},
17+
shout: {
18+
type: "string",
19+
label: "Shout",
20+
description: "A message about your check-in.",
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.foursquare.createCheckIn({
26+
$,
27+
params: {
28+
venueId: this.venueId,
29+
shout: this.shout,
30+
},
31+
});
32+
33+
$.export("$summary", `Successfully created check-in at venue ${this.venueId}`);
34+
return response;
35+
},
36+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import foursquare from "../../foursquare.app.mjs";
2+
3+
export default {
4+
key: "foursquare-create-tip",
5+
name: "Create Tip",
6+
description: "Allows the user to create a new tip for a venue on Foursquare. [See the documentation](https://docs.foursquare.com/developer/reference/add-a-tip)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
foursquare,
11+
venueId: {
12+
propDefinition: [
13+
foursquare,
14+
"venueId",
15+
],
16+
},
17+
tipText: {
18+
type: "string",
19+
label: "Tip Text",
20+
description: "The text of the tip.",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.foursquare.addTip({
25+
$,
26+
params: {
27+
venueId: this.venueId,
28+
text: this.tipText,
29+
},
30+
});
31+
$.export("$summary", `Successfully created tip for venue ${this.venueId}`);
32+
return response;
33+
},
34+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 1;
Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,94 @@
1+
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "foursquare",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
venueId: {
9+
type: "string",
10+
label: "Venue ID",
11+
description: "The ID of the venue where you want to interact.",
12+
},
13+
},
514
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
15+
_baseUrl() {
16+
return "https://api.foursquare.com/v2";
17+
},
18+
_headers() {
19+
return {
20+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
21+
};
22+
},
23+
_makeRequest({
24+
$ = this, path, params = {}, ...opts
25+
}) {
26+
return axios($, {
27+
url: this._baseUrl() + path,
28+
headers: this._headers(),
29+
params: {
30+
...params,
31+
v: "20240430",
32+
},
33+
...opts,
34+
});
35+
},
36+
createCheckIn(opts = {}) {
37+
return this._makeRequest({
38+
method: "POST",
39+
path: "/checkins/add",
40+
...opts,
41+
});
42+
},
43+
addTip(opts = {}) {
44+
return this._makeRequest({
45+
method: "POST",
46+
path: "/tips/add",
47+
...opts,
48+
});
49+
},
50+
getUserTips(opts = {}) {
51+
return this._makeRequest({
52+
path: "/users/self/tips",
53+
...opts,
54+
});
55+
},
56+
getUserCheckins(opts = {}) {
57+
return this._makeRequest({
58+
path: "/users/self/checkins",
59+
...opts,
60+
});
61+
},
62+
async *paginate({
63+
fn, params = {}, dataField, maxResults = null, ...opts
64+
}) {
65+
let hasMore = false;
66+
let count = 0;
67+
let page = 0;
68+
69+
do {
70+
params.limit = LIMIT;
71+
params.offset = LIMIT * page;
72+
page++;
73+
74+
const { response } = await fn({
75+
params,
76+
...opts,
77+
});
78+
79+
const items = response[dataField].items;
80+
81+
for (const d of items) {
82+
yield d;
83+
84+
if (maxResults && ++count === maxResults) {
85+
return count;
86+
}
87+
}
88+
89+
hasMore = items.length;
90+
91+
} while (hasMore);
992
},
1093
},
1194
};

components/foursquare/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/foursquare",
3+
"version": "0.1.0",
4+
"description": "Pipedream Foursquare Components",
5+
"main": "foursquare.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"foursquare"
9+
],
10+
"homepage": "https://pipedream.com/apps/foursquare",
11+
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^1.6.2"
17+
}
18+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import foursquare from "../../foursquare.app.mjs";
3+
4+
export default {
5+
props: {
6+
foursquare,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
_getLastDate() {
17+
return this.db.get("lastDate") || 0;
18+
},
19+
_setLastDate(created) {
20+
this.db.set("lastDate", created);
21+
},
22+
generateMeta(item) {
23+
return {
24+
id: item.id,
25+
summary: this.getSummary(item),
26+
ts: item.createdAt,
27+
};
28+
},
29+
async startEvent(maxResults = 0) {
30+
const lastDate = this._getLastDate();
31+
const response = this.foursquare.paginate({
32+
fn: this.getFn(),
33+
dataField: this.getDataField(),
34+
maxResults,
35+
});
36+
37+
const responseArray = [];
38+
for await (const item of response) {
39+
if (item.createdAt <= lastDate) break;
40+
responseArray.push(item);
41+
}
42+
43+
if (responseArray.length) this._setLastDate(responseArray[0].createdAt);
44+
45+
for (const item of responseArray.reverse()) {
46+
this.$emit(item, this.generateMeta(item));
47+
}
48+
},
49+
},
50+
hooks: {
51+
async deploy() {
52+
await this.startEvent(25);
53+
},
54+
},
55+
async run() {
56+
await this.startEvent();
57+
},
58+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "foursquare-new-check-in",
7+
name: "New Check-In",
8+
description: "Emit new event when a user checks in.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getSummary(item) {
15+
return `New Check-In with Id: ${item.id}`;
16+
},
17+
getDataField() {
18+
return "checkins";
19+
},
20+
getFn() {
21+
return this.foursquare.getUserCheckins;
22+
},
23+
},
24+
sampleEmit,
25+
};
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export default {
2+
"id": "59b97e6cf79faa0d5e23abeb",
3+
"createdAt": 1505328748,
4+
"type": "checkin",
5+
"private": true,
6+
"visibility": "private",
7+
"entities": [],
8+
"shout": "Monday monday!",
9+
"timeZoneOffset": -240,
10+
"venue": {
11+
"id": "4f0de7267bebfc146005dcc0",
12+
"name": "Mattlantis 🐳"
13+
},
14+
"likes": {
15+
"count": 0,
16+
"groups": []
17+
},
18+
"like": false,
19+
"isMayor": false,
20+
"photos": {
21+
"count": 1,
22+
"items": [
23+
{
24+
"id": "59b97e6d270ee77dbf2b8aa0",
25+
"createdAt": 1505328749,
26+
"source": {
27+
"name": "Swarm for iOS",
28+
"url": "https://www.swarmapp.com"
29+
},
30+
"prefix": "https://fastly.4sqi.net/img/general/",
31+
"suffix": "/7294631_KK8FbnS6sqgrlXgZeCwkYbSn2efiAQBoT7x4p_hteis.jpg",
32+
"width": 1440,
33+
"height": 1920,
34+
"user": {
35+
"id": "123456",
36+
"firstName": "John",
37+
"lastName": "Smith",
38+
"handle": "johnsmith",
39+
"privateProfile": false,
40+
"gender": "male",
41+
"countryCode": "US",
42+
"relationship": "self",
43+
"photo": {
44+
"prefix": "https://fastly.4sqi.net/img/user/",
45+
"suffix": "/blank_boy.png",
46+
"default": true
47+
},
48+
"birthday": 19700101,
49+
"isAnonymous": false
50+
},
51+
"visibility": "private"
52+
}
53+
],
54+
"layout": {
55+
"name": "single"
56+
}
57+
},
58+
"posts": {
59+
"count": 0,
60+
"textCount": 0
61+
},
62+
"comments": {
63+
"count": 0
64+
},
65+
"source": {
66+
"name": "Swarm for iOS",
67+
"url": "https://www.swarmapp.com"
68+
}
69+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "foursquare-new-tip",
7+
name: "New Tip",
8+
description: "Emit new event when a user adds a new tip.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getSummary(item) {
15+
return `New tip with Id: ${item.id}`;
16+
},
17+
getDataField() {
18+
return "tips";
19+
},
20+
getFn() {
21+
return this.foursquare.getUserTips;
22+
},
23+
},
24+
sampleEmit,
25+
};

0 commit comments

Comments
 (0)