diff --git a/components/autoblogger/actions/get-blogposts/get-blogposts.mjs b/components/autoblogger/actions/get-blogposts/get-blogposts.mjs new file mode 100644 index 0000000000000..646f687bd6295 --- /dev/null +++ b/components/autoblogger/actions/get-blogposts/get-blogposts.mjs @@ -0,0 +1,22 @@ +import app from "../../autoblogger.app.mjs"; + +export default { + key: "autoblogger-get-blogposts", + name: "Get Blogposts", + description: "Retrieves blogposts using the API key. [See the documentation](https://u.pcloud.link/publink/show?code=XZdjuv0ZtabS8BN58thUiE8FGjznajoMc6Qy)", + version: "0.0.1", + type: "action", + props: { + app, + }, + + async run({ $ }) { + const response = await this.app.getBlogposts({ + $, + }); + + $.export("$summary", `Successfully retrieved ${response.length} blogposts`); + + return response; + }, +}; diff --git a/components/autoblogger/actions/validate-api-key/validate-api-key.mjs b/components/autoblogger/actions/validate-api-key/validate-api-key.mjs new file mode 100644 index 0000000000000..9fca04302f918 --- /dev/null +++ b/components/autoblogger/actions/validate-api-key/validate-api-key.mjs @@ -0,0 +1,23 @@ +import app from "../../autoblogger.app.mjs"; + +export default { + key: "autoblogger-validate-api-key", + name: "Validate API Key", + description: "Validates the provided API key. [See the documentation](https://u.pcloud.link/publink/show?code=XZdjuv0ZtabS8BN58thUiE8FGjznajoMc6Qy)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.validateKey({ + $, + }); + + $.export("$summary", `API Key ${response.is_valid + ? "is" + : "isn't"} valid`); + + return response; + }, +}; diff --git a/components/autoblogger/autoblogger.app.mjs b/components/autoblogger/autoblogger.app.mjs index 9e54a87dfec80..408803f971739 100644 --- a/components/autoblogger/autoblogger.app.mjs +++ b/components/autoblogger/autoblogger.app.mjs @@ -1,11 +1,41 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "autoblogger", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://autoblogger-api.otherweb.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "x-api-key": `${this.$auth.api_key}`, + "Accept": "application/json", + }, + }); + }, + async validateKey(args = {}) { + return this._makeRequest({ + path: "/api/v1/site/validate/apikey", + ...args, + }); + }, + async getBlogposts(args = {}) { + return this._makeRequest({ + path: "/api/v1/blogposts", + ...args, + }); }, }, }; diff --git a/components/autoblogger/package.json b/components/autoblogger/package.json index 2db61f7a014ae..3e5ddee0c3e8e 100644 --- a/components/autoblogger/package.json +++ b/components/autoblogger/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/autoblogger", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream AutoBlogger Components", "main": "autoblogger.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dfc0fe9556e70..4344578aa357a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -816,7 +816,10 @@ importers: specifiers: {} components/autoblogger: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/autobound: specifiers: {} @@ -36639,7 +36642,7 @@ packages: dev: false /verror/1.10.0: - resolution: {integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=} + resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==} engines: {'0': node >=0.6.0} dependencies: assert-plus: 1.0.0