|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | app: "learnworlds", |
4 | | - propDefinitions: {}, |
| 6 | + propDefinitions: { |
| 7 | + userId: { |
| 8 | + type: "string", |
| 9 | + label: "User Id", |
| 10 | + description: "Unique identifier of the used.", |
| 11 | + async options({ page }) { |
| 12 | + const { data } = await this.listUsers({ |
| 13 | + params: { |
| 14 | + page: page + 1, |
| 15 | + }, |
| 16 | + }); |
| 17 | + |
| 18 | + return data.map(({ |
| 19 | + id: value, username: label, |
| 20 | + }) => ({ |
| 21 | + label, |
| 22 | + value, |
| 23 | + })); |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
5 | 27 | methods: { |
6 | | - // this.$auth contains connected account data |
7 | | - authKeys() { |
8 | | - console.log(Object.keys(this.$auth)); |
| 28 | + _baseUrl() { |
| 29 | + return `https://${this.$auth.school_domain}/admin/api/v2`; |
| 30 | + }, |
| 31 | + _getHeaders() { |
| 32 | + return { |
| 33 | + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, |
| 34 | + "Lw-Client": `${this.$auth.oauth_client_id}`, |
| 35 | + }; |
| 36 | + }, |
| 37 | + _makeRequest({ |
| 38 | + $ = this, path, ...opts |
| 39 | + }) { |
| 40 | + return axios($, { |
| 41 | + url: this._baseUrl() + path, |
| 42 | + headers: this._getHeaders(), |
| 43 | + ...opts, |
| 44 | + }); |
| 45 | + }, |
| 46 | + enrollUser({ |
| 47 | + userId, ...opts |
| 48 | + }) { |
| 49 | + return this._makeRequest({ |
| 50 | + method: "POST", |
| 51 | + path: `/users/${userId}/enrollment`, |
| 52 | + ...opts, |
| 53 | + }); |
| 54 | + }, |
| 55 | + getBundle({ productId }) { |
| 56 | + return this._makeRequest({ |
| 57 | + path: `/bundles/${productId}`, |
| 58 | + }); |
| 59 | + }, |
| 60 | + getCourse({ productId }) { |
| 61 | + return this._makeRequest({ |
| 62 | + path: `/courses/${productId}`, |
| 63 | + }); |
| 64 | + }, |
| 65 | + getSubscription({ productId }) { |
| 66 | + return this._makeRequest({ |
| 67 | + path: `/subscription-plans/${productId}`, |
| 68 | + }); |
| 69 | + }, |
| 70 | + listBundles(opts = {}) { |
| 71 | + return this._makeRequest({ |
| 72 | + path: "/bundles", |
| 73 | + ...opts, |
| 74 | + }); |
| 75 | + }, |
| 76 | + listCourses(opts = {}) { |
| 77 | + return this._makeRequest({ |
| 78 | + path: "/courses", |
| 79 | + ...opts, |
| 80 | + }); |
| 81 | + }, |
| 82 | + listSubscriptions(opts = {}) { |
| 83 | + return this._makeRequest({ |
| 84 | + path: "/subscription-plans", |
| 85 | + ...opts, |
| 86 | + }); |
| 87 | + }, |
| 88 | + listUsers(opts = {}) { |
| 89 | + return this._makeRequest({ |
| 90 | + path: "/users", |
| 91 | + ...opts, |
| 92 | + }); |
9 | 93 | }, |
10 | 94 | }, |
11 | 95 | }; |
0 commit comments