Skip to content

Commit a56f9a3

Browse files
committed
teach_n_go init
1 parent dd0bef4 commit a56f9a3

File tree

8 files changed

+545
-4
lines changed

8 files changed

+545
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import teachNGo from "../../teach_n_go.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "teach_n_go-create-prospect",
6+
name: "Create Prospect",
7+
description: "Creates a new prospect inside Teach 'n Go. [See the documentation](https://intercom.help/teach-n-go/en/articles/5750592-prospect-registration-api)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
teachNGo,
12+
prospectDetails: {
13+
propDefinition: [
14+
teachNGo,
15+
"prospectDetails",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.teachNGo.createProspect({
21+
prospectDetails: this.prospectDetails,
22+
});
23+
$.export("$summary", `Successfully created prospect with ID: ${response.id}`);
24+
return response;
25+
},
26+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import teachNGo from "../../teach_n_go.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "teach_n_go-create-student",
6+
name: "Create Student",
7+
description: "Registers a new student in Teach 'n Go. [See the documentation](https://intercom.help/teach-n-go/en/articles/6807235-new-student-and-class-registration-api)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
teachNGo,
12+
personalDetails: {
13+
propDefinition: [
14+
teachNGo,
15+
"personalDetails",
16+
],
17+
},
18+
academicDetails: {
19+
propDefinition: [
20+
teachNGo,
21+
"academicDetails",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.teachNGo.registerStudent({
27+
personalDetails: this.personalDetails,
28+
academicDetails: this.academicDetails,
29+
});
30+
31+
$.export("$summary", `Successfully registered student with ID: ${response.id}`);
32+
return response;
33+
},
34+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import teachNGo from "../../teach_n_go.app.mjs";
2+
3+
export default {
4+
key: "teach_n_go-invoice-mark-paid",
5+
name: "Mark Invoice as Paid",
6+
description: "Marks an existing invoice as paid within Teach 'n Go. [See the documentation](https://intercom.help/teach-n-go/en/articles/8727904-api-endpoints)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
teachNGo,
11+
invoiceId: {
12+
propDefinition: [
13+
teachNGo,
14+
"invoiceId",
15+
],
16+
},
17+
paidDate: {
18+
propDefinition: [
19+
teachNGo,
20+
"paidDate",
21+
],
22+
optional: true,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.teachNGo.markInvoiceAsPaid({
27+
invoiceId: this.invoiceId,
28+
paidDate: this.paidDate,
29+
});
30+
31+
$.export("$summary", `Successfully marked invoice ${this.invoiceId} as paid.`);
32+
return response;
33+
},
34+
};

components/teach_n_go/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { axios } from "@pipedream/platform";
2+
import teachNGo from "../../teach_n_go.app.mjs";
3+
4+
export default {
5+
key: "teach_n_go-new-class",
6+
name: "New Class Created",
7+
description: "Emit a new event when a class is created. [See the documentation](https://intercom.help/teach-n-go/en/articles/8727904-api-endpoints)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
teachNGo,
13+
db: "$.service.db",
14+
courseTitle: {
15+
propDefinition: [
16+
teachNGo,
17+
"courseTitle",
18+
],
19+
},
20+
dateAndTime: {
21+
propDefinition: [
22+
teachNGo,
23+
"dateAndTime",
24+
],
25+
},
26+
classDescription: {
27+
propDefinition: [
28+
teachNGo,
29+
"classDescription",
30+
],
31+
optional: true,
32+
},
33+
teacher: {
34+
propDefinition: [
35+
teachNGo,
36+
"teacher",
37+
],
38+
optional: true,
39+
},
40+
},
41+
hooks: {
42+
async deploy() {
43+
const classes = await this.fetchClasses();
44+
for (const classData of classes.slice(-50).reverse()) {
45+
this.$emit(classData, {
46+
id: classData.id,
47+
summary: `New Class: ${classData.title}`,
48+
ts: Date.parse(classData.dateAndTime),
49+
});
50+
}
51+
},
52+
async activate() {
53+
// Activation logic if any
54+
},
55+
async deactivate() {
56+
// Deactivation logic if any
57+
},
58+
},
59+
methods: {
60+
async fetchClasses() {
61+
return this.teachNGo._makeRequest({
62+
path: "/classes",
63+
});
64+
},
65+
async emitNewClassEvent() {
66+
const courseTitle = this.courseTitle;
67+
const dateAndTime = this.dateAndTime;
68+
const classDescription = this.classDescription || null;
69+
const teacher = this.teacher || null;
70+
71+
const classData = {
72+
courseTitle,
73+
dateAndTime,
74+
classDescription,
75+
teacher,
76+
};
77+
78+
this.$emit(classData, {
79+
summary: `New Class: ${courseTitle}`,
80+
ts: new Date().getTime(),
81+
});
82+
},
83+
},
84+
async run() {
85+
const classes = await this.fetchClasses();
86+
for (const classData of classes) {
87+
this.$emit(classData, {
88+
id: classData.id,
89+
summary: `New Class: ${classData.title}`,
90+
ts: Date.parse(classData.dateAndTime),
91+
});
92+
}
93+
},
94+
};
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import teachNGo from "../../teach_n_go.app.mjs";
2+
import {
3+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
key: "teach_n_go-new-payment",
8+
name: "New Payment Made",
9+
description: "Emit new event when a payment is made. [See the documentation](https://intercom.help/teach-n-go/en/articles/8727904-api-endpoints)",
10+
version: "0.0.1",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
teachNGo: {
15+
type: "app",
16+
app: "teach_n_go",
17+
},
18+
studentName: {
19+
propDefinition: [
20+
teachNGo,
21+
"studentName",
22+
],
23+
},
24+
amount: {
25+
propDefinition: [
26+
teachNGo,
27+
"amount",
28+
],
29+
},
30+
paymentMethod: {
31+
propDefinition: [
32+
teachNGo,
33+
"paymentMethod",
34+
],
35+
optional: true,
36+
},
37+
paymentDate: {
38+
propDefinition: [
39+
teachNGo,
40+
"paymentDate",
41+
],
42+
optional: true,
43+
},
44+
db: "$.service.db",
45+
timer: {
46+
type: "$.interface.timer",
47+
default: {
48+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
49+
},
50+
},
51+
},
52+
methods: {
53+
_getLastPaymentTimestamp() {
54+
return this.db.get("lastPaymentTimestamp") || 0;
55+
},
56+
_setLastPaymentTimestamp(timestamp) {
57+
this.db.set("lastPaymentTimestamp", timestamp);
58+
},
59+
async _fetchPayments(params) {
60+
return await axios(this, {
61+
method: "GET",
62+
url: `${this.teachNGo._baseUrl()}/path-to-payment-endpoint`, // Replace with actual endpoint
63+
headers: {
64+
"X-API-KEY": this.teachNGo.$auth.api_key,
65+
},
66+
params,
67+
});
68+
},
69+
},
70+
hooks: {
71+
async deploy() {
72+
const lastPaymentTimestamp = this._getLastPaymentTimestamp();
73+
const payments = await this._fetchPayments({
74+
lastPaymentTimestamp,
75+
});
76+
const recentPayments = payments.slice(0, 50);
77+
78+
for (const payment of recentPayments) {
79+
this.$emit(payment, {
80+
id: payment.id,
81+
summary: `New Payment: ${payment.studentName}`,
82+
ts: Date.parse(payment.paymentDate) || Date.now(),
83+
});
84+
}
85+
86+
if (recentPayments.length) {
87+
this._setLastPaymentTimestamp(Date.parse(recentPayments[0].paymentDate));
88+
}
89+
},
90+
},
91+
async run() {
92+
const lastPaymentTimestamp = this._getLastPaymentTimestamp();
93+
const payments = await this._fetchPayments({
94+
lastPaymentTimestamp,
95+
});
96+
97+
for (const payment of payments) {
98+
this.$emit(payment, {
99+
id: payment.id,
100+
summary: `New Payment: ${payment.studentName}`,
101+
ts: Date.parse(payment.paymentDate) || Date.now(),
102+
});
103+
}
104+
105+
if (payments.length) {
106+
this._setLastPaymentTimestamp(Date.parse(payments[0].paymentDate));
107+
}
108+
},
109+
};

0 commit comments

Comments
 (0)