|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | +import constants from "./common/constants.mjs"; |
| 3 | + |
1 | 4 | export default { |
2 | 5 | type: "app", |
3 | 6 | 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: "API Type", |
| 26 | + description: "Type of the API", |
| 27 | + options: constants.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 | + }, |
5 | 45 | 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 | + _headers({ |
| 50 | + headers = {}, legacy = false, |
| 51 | + }) { |
| 52 | + return legacy |
| 53 | + ? { |
| 54 | + ...headers, |
| 55 | + Authentication: `Token ${this.$auth.token}`, |
| 56 | + } |
| 57 | + : { |
| 58 | + ...headers, |
| 59 | + Authorization: `Bearer ${this.$auth.token}`, |
| 60 | + }; |
| 61 | + }, |
| 62 | + async _makeRequest(opts = {}) { |
| 63 | + const { |
| 64 | + $ = this, |
| 65 | + path, |
| 66 | + headers, |
| 67 | + legacy, |
| 68 | + ...otherOpts |
| 69 | + } = opts; |
| 70 | + return axios($, { |
| 71 | + ...otherOpts, |
| 72 | + url: this._baseUrl() + path, |
| 73 | + headers: this._headers({ |
| 74 | + headers, |
| 75 | + legacy, |
| 76 | + }), |
| 77 | + }); |
| 78 | + }, |
| 79 | + async createApiProject(args = {}) { |
| 80 | + return this._makeRequest({ |
| 81 | + path: "/blueprint/create", |
| 82 | + method: "post", |
| 83 | + legacy: true, |
| 84 | + ...args, |
| 85 | + }); |
| 86 | + }, |
| 87 | + async fetchBlueprint({ |
| 88 | + apiSubdomain, ...args |
| 89 | + }) { |
| 90 | + return this._makeRequest({ |
| 91 | + path: `/blueprint/get/${apiSubdomain}`, |
| 92 | + legacy: true, |
| 93 | + ...args, |
| 94 | + }); |
| 95 | + }, |
| 96 | + async publishBlueprint({ |
| 97 | + apiSubdomain, ...args |
| 98 | + }) { |
| 99 | + return this._makeRequest({ |
| 100 | + path: `/blueprint/publish/${apiSubdomain}`, |
| 101 | + method: "post", |
| 102 | + legacy: true, |
| 103 | + ...args, |
| 104 | + }); |
| 105 | + }, |
| 106 | + async listApis(args = {}) { |
| 107 | + return this._makeRequest({ |
| 108 | + path: "/me/apis", |
| 109 | + ...args, |
| 110 | + }); |
9 | 111 | }, |
10 | 112 | }, |
11 | 113 | }; |
0 commit comments