Skip to content

Commit fb7e822

Browse files
committed
new sources
1 parent 65d3179 commit fb7e822

File tree

9 files changed

+279
-6
lines changed

9 files changed

+279
-6
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
3+
export default {
4+
key: "zendesk_sell-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/contacts/#create-a-contact).",
7+
type: "action",
8+
version: "0.0.{{ts}}",
9+
props: {
10+
zendeskSell,
11+
},
12+
async run() {
13+
14+
},
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
3+
export default {
4+
key: "zendesk_sell-create-lead",
5+
name: "Create Lead",
6+
description: "Creates a new lead. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/leads/#create-a-lead).",
7+
type: "action",
8+
version: "0.0.{{ts}}",
9+
props: {
10+
zendeskSell,
11+
},
12+
async run() {
13+
14+
},
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
3+
export default {
4+
key: "zendesk_sell-create-task",
5+
name: "Create Task",
6+
description: "Creates a new task. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/tasks/#create-a-task).",
7+
type: "action",
8+
version: "0.0.{{ts}}",
9+
props: {
10+
zendeskSell,
11+
},
12+
async run() {
13+
14+
},
15+
};

components/zendesk_sell/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zendesk_sell",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Zendesk Sell Components",
55
"main": "zendesk_sell.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.0.3"
1417
}
15-
}
18+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
zendeskSell,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
hooks: {
16+
async deploy() {
17+
await this.processEvent(25);
18+
},
19+
},
20+
methods: {
21+
_getLastTs() {
22+
return this.db.get("lastTs") || 0;
23+
},
24+
_setLastTs(lastTs) {
25+
this.db.set("lastTs", lastTs);
26+
},
27+
getTsField() {
28+
return "created_at";
29+
},
30+
getParams() {
31+
return {
32+
sort_by: `${this.getTsField()}:desc`,
33+
};
34+
},
35+
generateMeta(item) {
36+
return {
37+
id: item.id,
38+
summary: this.getSummary(item),
39+
ts: Date.parse(item[this.getTsField()]),
40+
};
41+
},
42+
getResourceFn() {
43+
throw new Error("getResourceFn is not implemented");
44+
},
45+
getSummary() {
46+
throw new Error("getSummary is not implemented");
47+
},
48+
async processEvent(max) {
49+
const lastTs = this._getLastTs();
50+
const fn = this.getResourceFn();
51+
const params = this.getParams();
52+
const tsField = this.getTsField();
53+
54+
const results = this.zendeskSell.paginate({
55+
fn,
56+
params,
57+
max,
58+
});
59+
60+
const items = [];
61+
for await (const result of results) {
62+
const { data: item } = result;
63+
const ts = Date.parse(item[tsField]);
64+
if (ts >= lastTs) {
65+
items.push(item);
66+
} else {
67+
break;
68+
}
69+
}
70+
71+
if (!items?.length) {
72+
return;
73+
}
74+
75+
this._setLastTs(Date.parse(items[0][tsField]));
76+
77+
items.forEach((item) => {
78+
const meta = this.generateMeta(item);
79+
this.$emit(item, meta);
80+
});
81+
},
82+
},
83+
async run() {
84+
await this.processEvent();
85+
},
86+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "zendesk_sell-new-contact-created",
6+
name: "New Contact Created",
7+
description: "Emit new event when a new contact is created in Zendesk Sell.",
8+
type: "source",
9+
version: "0.0.{{ts}}",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.zendeskSell.listContacts;
15+
},
16+
getSummary(contact) {
17+
return `New Contact ID: ${contact.id}`;
18+
},
19+
},
20+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "zendesk_sell-new-deal-created",
6+
name: "New Deal Created",
7+
description: "Emit new event when a new deal is created in Zendesk Sell.",
8+
type: "source",
9+
version: "0.0.{{ts}}",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.zendeskSell.listDeals;
15+
},
16+
getSummary(deal) {
17+
return `New Deal ID: ${deal.id}`;
18+
},
19+
},
20+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "zendesk_sell-new-lead-created",
6+
name: "New Lead Created",
7+
description: "Emit new event when a new lead is created in Zendesk Sell.",
8+
type: "source",
9+
version: "0.0.{{ts}}",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.zendeskSell.listLeads;
15+
},
16+
getSummary(lead) {
17+
return `New Lead ID: ${lead.id}`;
18+
},
19+
},
20+
};
Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,90 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "zendesk_sell",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://api.getbase.com/v2";
10+
},
11+
_makeRequest({
12+
$ = this,
13+
path,
14+
...opts
15+
}) {
16+
return axios($, {
17+
url: `${this._baseUrl()}${path}`,
18+
headers: {
19+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
20+
accept: "application/json",
21+
},
22+
...opts,
23+
});
24+
},
25+
listContacts(opts = {}) {
26+
return this._makeRequest({
27+
path: "/contacts",
28+
...opts,
29+
});
30+
},
31+
listLeads(opts = {}) {
32+
return this._makeRequest({
33+
path: "/leads",
34+
...opts,
35+
});
36+
},
37+
listDeals(opts = {}) {
38+
return this._makeRequest({
39+
path: "/deals",
40+
...opts,
41+
});
42+
},
43+
createContact(opts = {}) {
44+
return this._makeRequest({
45+
method: "POST",
46+
path: "/contacts",
47+
...opts,
48+
});
49+
},
50+
createLead(opts = {}) {
51+
return this._makeRequest({
52+
method: "POST",
53+
path: "/leads",
54+
...opts,
55+
});
56+
},
57+
createTask(opts = {}) {
58+
return this._makeRequest({
59+
method: "POST",
60+
path: "/tasks",
61+
...opts,
62+
});
63+
},
64+
async *paginate({
65+
fn,
66+
params,
67+
max,
68+
}) {
69+
params = {
70+
...params,
71+
per_page: 100,
72+
page: 1,
73+
};
74+
let total, count = 0;
75+
do {
76+
const { items } = await fn({
77+
params,
78+
});
79+
for (const item of items) {
80+
yield item;
81+
if (max && ++count >= max) {
82+
return;
83+
}
84+
}
85+
total = items?.length;
86+
params.page++;
87+
} while (total);
988
},
1089
},
11-
};
90+
};

0 commit comments

Comments
 (0)