Skip to content

Commit 8264853

Browse files
committed
Added actions
1 parent 3317f40 commit 8264853

File tree

5 files changed

+226
-5
lines changed

5 files changed

+226
-5
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../crowdpower.app.mjs";
2+
3+
export default {
4+
key: "crowdpower-create-customer-charge",
5+
name: "Create Customer Charge",
6+
description: "Create a charge for a user. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#d89820d6-5d65-4ff7-87ba-6cddb359d8f3)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
userId: {
17+
propDefinition: [
18+
app,
19+
"userId",
20+
],
21+
},
22+
amount: {
23+
propDefinition: [
24+
app,
25+
"amount",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.app.createCustomerCharge({
31+
$,
32+
data: {
33+
user_id: this.userId,
34+
amount: this.amount,
35+
},
36+
});
37+
$.export("$summary", response.success
38+
? `Request succeeded with code ${response.code}`
39+
: `Request failed with code ${response.code}`);
40+
return response;
41+
},
42+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../crowdpower.app.mjs";
2+
3+
export default {
4+
key: "crowdpower-create-customer-event",
5+
name: "Create Customer Event",
6+
description: "Create a new event related to a customer. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#63159fcd-7df3-46c5-ac83-eeb72678b650)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
userId: {
17+
propDefinition: [
18+
app,
19+
"userId",
20+
],
21+
},
22+
customAttributes: {
23+
propDefinition: [
24+
app,
25+
"customAttributes",
26+
],
27+
description: "Custom attributes of the event",
28+
},
29+
action: {
30+
propDefinition: [
31+
app,
32+
"action",
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const response = await this.app.createCustomerEvent({
38+
$,
39+
data: {
40+
user_id: this.userId,
41+
custom_attributes: this.customAttributes,
42+
action: this.action,
43+
},
44+
});
45+
$.export("$summary", response.success
46+
? `Request succeeded with code ${response.code}`
47+
: `Request failed with code ${response.code}`);
48+
return response;
49+
},
50+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import app from "../../crowdpower.app.mjs";
2+
3+
export default {
4+
key: "crowdpower-upsert-customer",
5+
name: "Upsert Customer",
6+
description: "Create or update a customer. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#9415bd14-59ab-47b1-b0ec-73826d9cb5db)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
userId: {
17+
propDefinition: [
18+
app,
19+
"userId",
20+
],
21+
description: "ID of the customer that will be created or updated",
22+
},
23+
email: {
24+
propDefinition: [
25+
app,
26+
"email",
27+
],
28+
},
29+
name: {
30+
propDefinition: [
31+
app,
32+
"name",
33+
],
34+
},
35+
customAttributes: {
36+
propDefinition: [
37+
app,
38+
"customAttributes",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.app.upsertCustomer({
44+
$,
45+
data: {
46+
user_id: this.userId,
47+
email: this.email,
48+
name: this.name,
49+
custom_attributes: this.customAttributes,
50+
},
51+
});
52+
$.export("$summary", response.success
53+
? `Request succeeded with code ${response.code}`
54+
: `Request failed with code ${response.code}`);
55+
return response;
56+
},
57+
};
Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,80 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "crowdpower",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
userId: {
8+
type: "string",
9+
label: "User ID",
10+
description: "ID of the user",
11+
},
12+
amount: {
13+
type: "string",
14+
label: "Amount",
15+
description: "Amount of the charge",
16+
},
17+
email: {
18+
type: "string",
19+
label: "Email",
20+
description: "Email of the customer",
21+
},
22+
name: {
23+
type: "string",
24+
label: "Name",
25+
description: "Name of the customer",
26+
},
27+
customAttributes: {
28+
type: "object",
29+
label: "Custom Attributes",
30+
description: "Custom attributes",
31+
},
32+
action: {
33+
type: "string",
34+
label: "Action",
35+
description: "Action related to the event",
36+
},
37+
},
538
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
39+
_baseUrl() {
40+
return "https://beacon.crowdpower.io/";
41+
},
42+
async _makeRequest(opts = {}) {
43+
const {
44+
$ = this,
45+
path,
46+
headers,
47+
...otherOpts
48+
} = opts;
49+
return axios($, {
50+
...otherOpts,
51+
url: this._baseUrl() + path,
52+
headers: {
53+
"Authorization": `Bearer ${this.$auth.application_key}`,
54+
...headers,
55+
},
56+
});
57+
},
58+
async createCustomerCharge(args = {}) {
59+
return this._makeRequest({
60+
path: "/charges",
61+
method: "post",
62+
...args,
63+
});
64+
},
65+
async upsertCustomer(args = {}) {
66+
return this._makeRequest({
67+
path: "/customers",
68+
method: "post",
69+
...args,
70+
});
71+
},
72+
async createCustomerEvent(args = {}) {
73+
return this._makeRequest({
74+
path: "/events",
75+
method: "post",
76+
...args,
77+
});
978
},
1079
},
1180
};

components/crowdpower/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/crowdpower",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"description": "Pipedream CrowdPower Components",
55
"main": "crowdpower.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": "^1.6.8"
1417
}
1518
}

0 commit comments

Comments
 (0)