Skip to content

Commit e4bc63c

Browse files
committed
Added actions
1 parent 9cbf1c2 commit e4bc63c

File tree

8 files changed

+272
-18
lines changed

8 files changed

+272
-18
lines changed

components/klipfolio/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import app from "../../klipfolio.app.mjs";
2+
3+
export default {
4+
key: "klipfolio-create-datasource",
5+
name: "Create Datasource",
6+
description: "Create a data source. [See the documentation](https://apidocs.klipfolio.com/reference/data-sources#post-datasources)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name"
15+
]
16+
},
17+
description: {
18+
propDefinition: [
19+
app,
20+
"description"
21+
]
22+
},
23+
format: {
24+
propDefinition: [
25+
app,
26+
"format"
27+
]
28+
},
29+
connector: {
30+
propDefinition: [
31+
app,
32+
"connector"
33+
]
34+
},
35+
refreshInterval: {
36+
propDefinition: [
37+
app,
38+
"refreshInterval"
39+
]
40+
},
41+
endpointUrl: {
42+
propDefinition: [
43+
app,
44+
"endpointUrl"
45+
]
46+
},
47+
method: {
48+
propDefinition: [
49+
app,
50+
"method"
51+
]
52+
},
53+
},
54+
55+
async run({ $ }) {
56+
const response = await this.app.createDatasource({
57+
$,
58+
data: {
59+
name: this.name,
60+
description: this.description,
61+
format: this.format,
62+
connector: this.connector,
63+
refresh_interval: parseInt(this.refreshInterval, 10),
64+
properties: {
65+
endpoint_url: this.endpointUrl,
66+
method: this.method,
67+
}
68+
},
69+
});
70+
$.export("$summary", `Successfully created Datasource named '${this.name}'`);
71+
return response;
72+
},
73+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import app from "../../klipfolio.app.mjs";
2+
3+
export default {
4+
key: "klipfolio-delete-datasource",
5+
name: "Delete Datasource",
6+
description: "Delete the data source associated with a specific data source ID. [See the documentation](https://apidocs.klipfolio.com/reference/data-sources#delete-datasourcesid)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
datasourceId: {
12+
propDefinition: [
13+
app,
14+
"datasourceId"
15+
]
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.deleteDatasource({
21+
$,
22+
datasourceId: this.datasourceId,
23+
});
24+
$.export("$summary", `Successfully deleted datasource with ID: ${this.datasourceId}`);
25+
return response;
26+
},
27+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../klipfolio.app.mjs";
2+
3+
export default {
4+
key: "klipfolio-update-datasource",
5+
name: "Update Datasource",
6+
description: "Update the specified data source. [See the documentation](https://apidocs.klipfolio.com/reference/data-sources#put-datasourcesid)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
datasourceId: {
12+
propDefinition: [
13+
app,
14+
"datasourceId"
15+
]
16+
},
17+
name: {
18+
propDefinition: [
19+
app,
20+
"name"
21+
]
22+
},
23+
description: {
24+
propDefinition: [
25+
app,
26+
"description"
27+
]
28+
},
29+
refreshInterval: {
30+
propDefinition: [
31+
app,
32+
"refreshInterval"
33+
]
34+
},
35+
},
36+
37+
async run({ $ }) {
38+
const response = await this.app.updateDatasource({
39+
$,
40+
datasourceId: this.datasourceId,
41+
data: {
42+
name: this.name,
43+
description: this.description,
44+
refreshInterval: this.refreshInterval,
45+
},
46+
});
47+
$.export("$summary", `Successfully updated Datasource named '${this.name}'`);
48+
return response;
49+
},
50+
};

components/klipfolio/app/klipfolio.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
DATASOURCE_CONNECTORS: [
3+
'box', 'comscore', 'db', 'dropbox', 'facebook', 'ftp', 'google_adwords', 'google_analytics', 'google_drive', 'google_spreadsheets', 'hubspot', 'iformbuilder', 'marketo', 'omniture', 'radian6', 'salesforce', 'searchMetrics', 'shopify', 'simple_rest', 'survey_monkey', 'versature', 'xero', 'xmla'
4+
],
5+
REFRESH_INTERVALS: [
6+
'0', '60', '300', '900', '1800', '3600', '7200', '10800', '14400', '43200', '86400'
7+
]
8+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
4+
export default {
5+
type: "app",
6+
app: "klipfolio",
7+
propDefinitions: {
8+
name: {
9+
type: "string",
10+
label: "Name",
11+
description: "Name of the Datasource",
12+
},
13+
description: {
14+
type: "string",
15+
label: "Description",
16+
description: "Description of the Datasource",
17+
},
18+
format: {
19+
type: "string",
20+
label: "Format",
21+
description: "Format of the Datasource, i.e.: `xml`",
22+
},
23+
connector: {
24+
type: "string",
25+
label: "Connector",
26+
description: "Connector of the Datasource",
27+
options: constants.DATASOURCE_CONNECTORS,
28+
},
29+
refreshInterval: {
30+
type: "string",
31+
label: "Refresh Interval",
32+
description: "Refresh Interval of the Datasource",
33+
options: constants.REFRESH_INTERVALS,
34+
},
35+
endpointUrl: {
36+
type: "string",
37+
label: "Endpoint URL",
38+
description: "Endpoint URL of the Datasource, i.e.: `http://test/data/scatter.xml`",
39+
},
40+
method: {
41+
type: "string",
42+
label: "Method",
43+
description: "Method for the endpoint, i.e.: `GET`",
44+
},
45+
datasourceId: {
46+
type: "string",
47+
label: "Datasource ID",
48+
description: "ID of the Datasource",
49+
async options() {
50+
const response = await this.getDatasources();
51+
const datasourceIds = response.data.datasources;
52+
return datasourceIds.map(({ id, name }) => ({
53+
label: name,
54+
value: id
55+
}));
56+
}
57+
},
58+
},
59+
methods: {
60+
_baseUrl() {
61+
return `https://app.klipfolio.com/api/1.0`;
62+
},
63+
async _makeRequest(opts = {}) {
64+
const {
65+
$ = this,
66+
path,
67+
headers,
68+
...otherOpts
69+
} = opts;
70+
return axios($, {
71+
...otherOpts,
72+
url: this._baseUrl() + path,
73+
headers: {
74+
...headers,
75+
"kf-api-key": `${this.$auth.api_key}`,
76+
},
77+
});
78+
},
79+
async createDatasource(args = {}) {
80+
return this._makeRequest({
81+
path: "/datasources",
82+
method: "post",
83+
...args,
84+
});
85+
},
86+
async updateDatasource({ datasourceId, ...args }) {
87+
return this._makeRequest({
88+
path: `/datasources/${datasourceId}`,
89+
method: "put",
90+
...args,
91+
});
92+
},
93+
async deleteDatasource({ datasourceId, ...args }) {
94+
return this._makeRequest({
95+
path: `/datasources/${datasourceId}`,
96+
method: "delete",
97+
...args,
98+
});
99+
},
100+
async getDatasources(args = {}) {
101+
return this._makeRequest({
102+
path: "/datasources",
103+
...args,
104+
});
105+
},
106+
},
107+
};

components/klipfolio/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
22
"name": "@pipedream/klipfolio",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Klipfolio Components",
55
"main": "dist/app/klipfolio.app.mjs",
66
"keywords": [
77
"pipedream",
88
"klipfolio"
99
],
10-
"files": ["dist"],
10+
"files": [
11+
"dist"
12+
],
1113
"homepage": "https://pipedream.com/apps/klipfolio",
1214
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1315
"publishConfig": {
1416
"access": "public"
17+
},
18+
"dependencies": {
19+
"@pipedream/platform": "^3.0.3"
1520
}
1621
}

0 commit comments

Comments
 (0)