Skip to content

Commit e942adc

Browse files
committed
Reverting xperiencify
1 parent fe3c42b commit e942adc

File tree

6 files changed

+160
-14
lines changed

6 files changed

+160
-14
lines changed

components/xperiencify/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js
2+
*.mjs
3+
dist
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { defineApp } from "@pipedream/types";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default defineApp({
5+
type: "app",
6+
app: "xperiencify",
7+
propDefinitions: {
8+
courseId: {
9+
type: "integer",
10+
label: "Course",
11+
description: "Course",
12+
async options() {
13+
const courses = await this.listCourses();
14+
return courses.map((course) => ({
15+
label: course.title,
16+
value: course.id,
17+
}));
18+
},
19+
},
20+
student: {
21+
type: "string",
22+
label: "Student",
23+
description: "The student's email address",
24+
async options({ courseId }) {
25+
const students = !courseId
26+
? await this.listAllStudents()
27+
: await this.getStudentsForCourse({
28+
courseId,
29+
});
30+
return students.map((student) => ({
31+
label: student.first_name,
32+
value: student.email,
33+
}));
34+
},
35+
},
36+
tags: {
37+
type: "string[]",
38+
label: "Tags",
39+
description: "Student tags",
40+
async options({ studentEmail }) {
41+
const tags = await this.listStudentTags({
42+
data: {
43+
student_email: studentEmail,
44+
},
45+
});
46+
return tags;
47+
},
48+
},
49+
},
50+
methods: {
51+
async _makeRequest({
52+
$ = this, path, params, ...opts
53+
}) {
54+
try {
55+
return await axios($, {
56+
url: `https://api.xperiencify.io/api/public${path}`,
57+
params: {
58+
api_key: this.$auth.api_key,
59+
...params,
60+
},
61+
...opts,
62+
});
63+
} catch (e) {
64+
console.error(e.response.data);
65+
throw e;
66+
}
67+
},
68+
async listCourses(opts = {}) {
69+
return this._makeRequest({
70+
path: "/coach/courses",
71+
...opts,
72+
});
73+
},
74+
async listAllStudents() {
75+
const courses = await this.listCourses();
76+
const promises = courses.map(async (course) => this.getStudentsForCourse({
77+
courseId: course.id,
78+
}));
79+
return (await Promise.all(promises)).flat().sort();
80+
},
81+
async listStudentTags(opts = {}) {
82+
return this._makeRequest({
83+
path: "/student/tag/list",
84+
...opts,
85+
});
86+
},
87+
async addTagsToStudent(opts = {}) {
88+
return this._makeRequest({
89+
path: "/student/tag/manager",
90+
method: "post",
91+
...opts,
92+
});
93+
},
94+
async removeTagsFromStudent(opts = {}) {
95+
return this._makeRequest({
96+
path: "/student/tag/manager",
97+
method: "delete",
98+
...opts,
99+
});
100+
},
101+
async removeStudentFromAllCourses(opts = {}) {
102+
return this._makeRequest({
103+
path: "/student/course/remove/all",
104+
method: "post", // yes, it's supposed to be post
105+
...opts,
106+
});
107+
},
108+
async getStudentsForCourse({ courseId }) {
109+
const courses = await this.listCourses();
110+
const [
111+
course,
112+
] = courses.filter((course) => course.id === courseId) || [];
113+
114+
if (!course) {
115+
throw new Error(`Course ${courseId} not found`);
116+
}
117+
return course.users;
118+
},
119+
async addStudentToCourse(opts = {}) {
120+
return this._makeRequest({
121+
path: "/student/create",
122+
method: "post",
123+
...opts,
124+
});
125+
},
126+
async removeStudentFromCourse(opts = {}) {
127+
return this._makeRequest({
128+
path: "/student/course/remove",
129+
method: "post", // yes, it's supposed to be post
130+
...opts,
131+
});
132+
},
133+
},
134+
});

components/xperiencify/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"name": "@pipedream/xperiencify",
33
"version": "0.0.6",
44
"description": "Pipedream Xperiencify Components",
5-
"main": "xperiencify.app.mjs",
5+
"main": "dist/app/xperiencify.app.mjs",
6+
"files": [
7+
"dist"
8+
],
69
"keywords": [
710
"pipedream",
811
"xperiencify"
@@ -14,5 +17,8 @@
1417
},
1518
"dependencies": {
1619
"@pipedream/platform": "^1.2.0"
20+
},
21+
"devDependencies": {
22+
"@pipedream/types": "^0.3.2"
1723
}
1824
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.components.json"
3+
}

components/xperiencify/xperiencify.app.mjs

Lines changed: 0 additions & 11 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)