Skip to content

Commit b4b1df6

Browse files
committed
Added actions
1 parent 72b131c commit b4b1df6

File tree

6 files changed

+222
-4
lines changed

6 files changed

+222
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import app from "../../apiary.app.mjs";
2+
3+
export default {
4+
key: "apiary-create-api-project",
5+
name: "Create API Project",
6+
description: "Create a new API project. [See the documentation](https://apiary.docs.apiary.io/#reference/blueprint/create-api-project/create-api-project)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
type: {
12+
propDefinition: [
13+
app,
14+
"type",
15+
],
16+
},
17+
public: {
18+
propDefinition: [
19+
app,
20+
"public",
21+
],
22+
},
23+
desiredName: {
24+
propDefinition: [
25+
app,
26+
"desiredName",
27+
],
28+
},
29+
code: {
30+
propDefinition: [
31+
app,
32+
"code",
33+
],
34+
},
35+
},
36+
37+
async run({ $ }) {
38+
const response = await this.app.createApiProject({
39+
$,
40+
data: {
41+
type: this.type,
42+
public: this.public,
43+
desiredName: this.desiredName,
44+
code: this.code,
45+
},
46+
});
47+
48+
$.export("$summary", `Successfully created a new API Project with the following domain: ${response.domain}`);
49+
50+
return response;
51+
},
52+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import app from "../../apiary.app.mjs";
2+
3+
export default {
4+
key: "apiary-fetch-blueprint",
5+
name: "Fetch Blueprint",
6+
description: "Fetch an API Blueprint for a particular API. [See the documentation](https://apiary.docs.apiary.io/#reference/blueprint/fetch-blueprint/fetch-blueprint)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
apiSubdomain: {
12+
propDefinition: [
13+
app,
14+
"apiSubdomain",
15+
],
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.fetchBlueprint({
21+
$,
22+
apiSubdomain: this.apiSubdomain,
23+
});
24+
25+
$.export("$summary", "Successfully fetched the blueprint for the specified API Subdomain");
26+
27+
return response;
28+
},
29+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import app from "../../apiary.app.mjs";
2+
3+
export default {
4+
key: "apiary-publish-blueprint",
5+
name: "Publish Blueprint",
6+
description: "Publish an API Blueprint for a particular API. [See the documentation](https://apiary.docs.apiary.io/#reference/blueprint/publish-blueprint/publish-blueprint)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
apiSubdomain: {
12+
propDefinition: [
13+
app,
14+
"apiSubdomain",
15+
],
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.publishBlueprint({
21+
$,
22+
apiSubdomain: this.apiSubdomain,
23+
});
24+
25+
$.export("$summary", `Successfully published the blueprint with the subdomain '${this.apisSubdomain}'`);
26+
27+
return response;
28+
},
29+
};

components/apiary/apiary.app.mjs

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,95 @@
1+
import { axios } from "@pipedream/platform";
2+
import contants from "./common/contants.mjs";
3+
14
export default {
25
type: "app",
36
app: "apiary",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
apiSubdomain: {
9+
type: "string",
10+
label: "API Subdomain",
11+
description: "Subdomain of the API",
12+
async options() {
13+
const response = await this.listApis();
14+
const apisSubdomains = response.apis;
15+
return apisSubdomains.map(({
16+
apiSubdomain, apiName,
17+
}) => ({
18+
value: apiSubdomain,
19+
label: apiName,
20+
}));
21+
},
22+
},
23+
type: {
24+
type: "string",
25+
label: "Type of the API",
26+
description: "Name of the organization",
27+
options: contants.API_TYPES,
28+
},
29+
public: {
30+
type: "boolean",
31+
label: "Public",
32+
description: "Defines if the API is public or private",
33+
},
34+
desiredName: {
35+
type: "string",
36+
label: "Desired Name",
37+
description: "If the desiredName is already taken, a different domain will be generated for your API Project. It can be later changed in the settings",
38+
},
39+
code: {
40+
type: "string",
41+
label: "Code",
42+
description: "`FORMAT: 1`",
43+
},
44+
},
545
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
46+
_baseUrl() {
47+
return "https://api.apiary.io";
48+
},
49+
async _makeRequest(opts = {}) {
50+
const {
51+
$ = this,
52+
path,
53+
headers,
54+
...otherOpts
55+
} = opts;
56+
return axios($, {
57+
...otherOpts,
58+
url: this._baseUrl() + path,
59+
headers: {
60+
...headers,
61+
Authorization: `Bearer ${this.$auth.token}`,
62+
},
63+
});
64+
},
65+
async createApiProject(args = {}) {
66+
return this._makeRequest({
67+
path: "/blueprint/create",
68+
method: "post",
69+
...args,
70+
});
71+
},
72+
async fetchBlueprint({
73+
apiSubdomain, ...args
74+
}) {
75+
return this._makeRequest({
76+
path: `/blueprint/get/${apiSubdomain}`,
77+
...args,
78+
});
79+
},
80+
async publishBlueprint({
81+
apiSubdomain, ...args
82+
}) {
83+
return this._makeRequest({
84+
path: `/blueprint/get/${apiSubdomain}`,
85+
...args,
86+
});
87+
},
88+
async listApis(args = {}) {
89+
return this._makeRequest({
90+
path: "/me/apis",
91+
...args,
92+
});
993
},
1094
},
1195
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
API_TYPES: [
3+
"personal",
4+
"team",
5+
],
6+
};

components/apiary/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/apiary",
3+
"version": "0.0.1",
4+
"description": "Pipedream Chat Data Components",
5+
"main": "apiary.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"apiary"
9+
],
10+
"homepage": "https://pipedream.com/apps/apiary",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}

0 commit comments

Comments
 (0)