Skip to content

Commit 347e3fa

Browse files
authored
Merging pull request #15577
* Added actions * Added actions * Done requests changes
1 parent 3f93f80 commit 347e3fa

File tree

8 files changed

+170
-19
lines changed

8 files changed

+170
-19
lines changed

components/ecologi/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../ecologi.app.mjs";
2+
3+
export default {
4+
key: "ecologi-buy-offsets",
5+
name: "Buy Offsets",
6+
description: "Buy carbon avoidance credits through Ecologi. [See the documentation](https://docs.ecologi.com/docs/public-api-docs/e07bbee7fa605-purchase-carbon-avoidance)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
number: {
12+
propDefinition: [
13+
app,
14+
"number",
15+
],
16+
},
17+
units: {
18+
propDefinition: [
19+
app,
20+
"units",
21+
],
22+
},
23+
test: {
24+
propDefinition: [
25+
app,
26+
"test",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.app.buyOffsets({
32+
$,
33+
data: {
34+
number: this.number,
35+
units: this.units,
36+
test: this.test,
37+
},
38+
});
39+
$.export("$summary", "Successfully bought carbon avoidance credits");
40+
return response;
41+
},
42+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import app from "../../ecologi.app.mjs";
2+
3+
export default {
4+
key: "ecologi-buy-trees",
5+
name: "Buy Trees",
6+
description: "Purchase trees through Ecologi. [See the documentation](https://docs.ecologi.com/docs/public-api-docs/004342d262f93-purchase-trees)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
number: {
12+
propDefinition: [
13+
app,
14+
"number",
15+
],
16+
},
17+
name: {
18+
propDefinition: [
19+
app,
20+
"name",
21+
],
22+
},
23+
test: {
24+
propDefinition: [
25+
app,
26+
"test",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.app.buyTrees({
32+
$,
33+
data: {
34+
number: this.number,
35+
name: this.name,
36+
test: this.test,
37+
},
38+
});
39+
40+
$.export("$summary", `Successfully bought ${this.number} tree(s)`);
41+
42+
return response;
43+
},
44+
};

components/ecologi/app/ecologi.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
UNIT_TYPES: [
3+
"KG",
4+
"Tonnes",
5+
],
6+
};

components/ecologi/ecologi.app.mjs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
4+
export default {
5+
type: "app",
6+
app: "ecologi",
7+
propDefinitions: {
8+
number: {
9+
type: "integer",
10+
label: "number",
11+
description: "Number of trees of offsets to purchase",
12+
},
13+
name: {
14+
type: "string",
15+
label: "name",
16+
description: "The 'funded by' name for the trees",
17+
optional: true,
18+
},
19+
units: {
20+
type: "string",
21+
label: "units",
22+
description: "The unit of the amount of offsets to purchase",
23+
options: constants.UNIT_TYPES,
24+
},
25+
test: {
26+
type: "boolean",
27+
label: "test",
28+
description: "Whether this is a test transaction or not",
29+
optional: true,
30+
},
31+
},
32+
methods: {
33+
_baseUrl() {
34+
return "https://public.ecologi.com";
35+
},
36+
async _makeRequest(opts = {}) {
37+
const {
38+
$ = this,
39+
path,
40+
headers,
41+
...otherOpts
42+
} = opts;
43+
return axios($, {
44+
...otherOpts,
45+
url: this._baseUrl() + path,
46+
headers: {
47+
"Authorization": `Bearer ${this.$auth.api_key}`,
48+
"Accept": "application/json",
49+
...headers,
50+
},
51+
});
52+
},
53+
54+
async buyTrees(args = {}) {
55+
return this._makeRequest({
56+
path: "/impact/trees",
57+
method: "post",
58+
...args,
59+
});
60+
},
61+
async buyOffsets(args = {}) {
62+
return this._makeRequest({
63+
path: "/impact/carbon",
64+
method: "post",
65+
...args,
66+
});
67+
},
68+
},
69+
};

components/ecologi/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/ecologi",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Ecologi Components",
55
"main": "dist/app/ecologi.app.mjs",
66
"keywords": [
77
"pipedream",
88
"ecologi"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/ecologi",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)