Skip to content

Commit 4d441b7

Browse files
committed
Added actions
1 parent db457a5 commit 4d441b7

File tree

5 files changed

+224
-6
lines changed

5 files changed

+224
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import app from "../../sproutgigs.app.mjs";
2+
3+
export default {
4+
key: "sproutgigs-get-categories",
5+
name: "Get Categories",
6+
description: "Get a list of categories from Sproutgigs. [See the documentation](https://sproutgigs.com/api/documentation.php#gigs-categories)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
},
12+
async run({ $ }) {
13+
const response = await this.app.getCategories({
14+
$,
15+
data: {},
16+
});
17+
$.export("$summary", "Successfully sent the request. " + response.length + " results retrieved");
18+
return response;
19+
},
20+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import app from "../../sproutgigs.app.mjs";
2+
3+
export default {
4+
key: "sproutgigs-get-zones",
5+
name: "Get Zones",
6+
description: "Get the available zones. [See the documentation](https://sproutgigs.com/api/documentation.php#jobs-zones)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
},
12+
async run({ $ }) {
13+
const response = await this.app.getZones({
14+
$,
15+
});
16+
$.export("$summary", "Successfully sent the request. " + response.length + " results retrieved");
17+
return response;
18+
},
19+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import app from "../../sproutgigs.app.mjs";
2+
3+
export default {
4+
key: "sproutgigs-post-job",
5+
name: "Post Job",
6+
description: "Post a new job to Sproutgigs. [See the documentation](https://sproutgigs.com/api/documentation.php#jobs-post)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
test: {
12+
propDefinition: [
13+
app,
14+
"test",
15+
],
16+
},
17+
zoneId: {
18+
propDefinition: [
19+
app,
20+
"zoneId",
21+
],
22+
},
23+
categoryId: {
24+
propDefinition: [
25+
app,
26+
"categoryId",
27+
],
28+
},
29+
title: {
30+
propDefinition: [
31+
app,
32+
"title",
33+
],
34+
},
35+
instructions: {
36+
propDefinition: [
37+
app,
38+
"instructions",
39+
],
40+
},
41+
proofs: {
42+
propDefinition: [
43+
app,
44+
"proofs",
45+
],
46+
},
47+
numTasks: {
48+
propDefinition: [
49+
app,
50+
"numTasks",
51+
],
52+
},
53+
taskValue: {
54+
propDefinition: [
55+
app,
56+
"taskValue",
57+
],
58+
},
59+
},
60+
async run({ $ }) {
61+
const response = await this.app.postJob({
62+
$,
63+
data: {
64+
test: this.test
65+
? 1
66+
: 0,
67+
zone_id: this.zoneId,
68+
category_id: this.categoryId,
69+
title: this.title,
70+
instructions: this.instructions,
71+
proofs: JSON.parse(this.proofs),
72+
num_tasks: this.numTasks,
73+
task_value: this.taskValue,
74+
},
75+
});
76+
$.export("$summary", "Successfully sent the request. Result message: " + response.message);
77+
return response;
78+
},
79+
};

components/sproutgigs/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sproutgigs",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream SproutGigs Components",
55
"main": "sproutgigs.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.1.0"
1417
}
1518
}
Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,108 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "sproutgigs",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
test: {
8+
type: "boolean",
9+
label: "Test",
10+
description: "Enable development mode, the job will not be created",
11+
optional: true,
12+
},
13+
zoneId: {
14+
type: "string",
15+
label: "Zone ID",
16+
description: "Zone ID for the job",
17+
async options() {
18+
const response = await this.getZones();
19+
return response.map(({
20+
id, zone,
21+
}) => ({
22+
value: id,
23+
label: zone,
24+
}));
25+
},
26+
},
27+
categoryId: {
28+
type: "string",
29+
label: "Category ID",
30+
description: "Category ID for the job",
31+
async options() {
32+
const response = await this.getCategories();
33+
return response.map(({
34+
id, category,
35+
}) => ({
36+
value: id,
37+
label: category,
38+
}));
39+
},
40+
},
41+
title: {
42+
type: "string",
43+
label: "Title",
44+
description: "Job title",
45+
},
46+
instructions: {
47+
type: "string[]",
48+
label: "Instructions",
49+
description: "List of expected work steps",
50+
},
51+
proofs: {
52+
type: "string",
53+
label: "Proofs",
54+
description: "Array of up to 4 proofs, each with description and type (text or screenshot), i.e.: `[{\"description\":\"Profile screenshot\",\"type\":\"screenshot\"}]`",
55+
},
56+
numTasks: {
57+
type: "integer",
58+
label: "Number of Tasks",
59+
description: "Number of tasks to be performed",
60+
},
61+
taskValue: {
62+
type: "string",
63+
label: "Task Value",
64+
description: "Amount paid per task",
65+
},
66+
},
567
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
68+
_baseUrl() {
69+
return "https://sproutgigs.com/api";
70+
},
71+
async _makeRequest(opts = {}) {
72+
const {
73+
$ = this,
74+
path,
75+
auth,
76+
...otherOpts
77+
} = opts;
78+
return axios($, {
79+
...otherOpts,
80+
url: this._baseUrl() + path,
81+
auth: {
82+
username: `${this.$auth.user_id}`,
83+
password: `${this.$auth.api_secret}`,
84+
...auth,
85+
},
86+
});
87+
},
88+
async postJob(args = {}) {
89+
return this._makeRequest({
90+
path: "/jobs/post-job.php",
91+
method: "post",
92+
...args,
93+
});
94+
},
95+
async getCategories(args = {}) {
96+
return this._makeRequest({
97+
path: "/jobs/get-categories.php",
98+
...args,
99+
});
100+
},
101+
async getZones(args = {}) {
102+
return this._makeRequest({
103+
path: "/jobs/get-zones.php",
104+
...args,
105+
});
9106
},
10107
},
11-
};
108+
};

0 commit comments

Comments
 (0)