From c034deb84d6f78b21105b3608f46d178d63442ff Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 4 Feb 2025 09:59:15 -0300 Subject: [PATCH 1/2] Added actions --- .../get-business-listings.mjs | 65 ++++++++ .../get-keyword-difficulty.mjs | 44 ++++++ .../get-ranked-keywords.mjs | 44 ++++++ components/dataforseo/common/constants.mjs | 6 + components/dataforseo/dataforseo.app.mjs | 142 +++++++++++++++++- components/dataforseo/package.json | 7 +- 6 files changed, 301 insertions(+), 7 deletions(-) create mode 100644 components/dataforseo/actions/get-business-listings/get-business-listings.mjs create mode 100644 components/dataforseo/actions/get-keyword-difficulty/get-keyword-difficulty.mjs create mode 100644 components/dataforseo/actions/get-ranked-keywords/get-ranked-keywords.mjs create mode 100644 components/dataforseo/common/constants.mjs diff --git a/components/dataforseo/actions/get-business-listings/get-business-listings.mjs b/components/dataforseo/actions/get-business-listings/get-business-listings.mjs new file mode 100644 index 0000000000000..e8ea7197156c6 --- /dev/null +++ b/components/dataforseo/actions/get-business-listings/get-business-listings.mjs @@ -0,0 +1,65 @@ +import app from "../../dataforseo.app.mjs"; + +export default { + key: "dataforseo-get-business-listings", + name: "Get Business Listings", + description: "Get Business Listings. [See the documentation](https://docs.dataforseo.com/v3/business_data/business_listings/search/live/?bash)", + version: "0.0.1", + type: "action", + props: { + app, + locationCoordinate: { + propDefinition: [ + app, + "locationCoordinate", + ], + }, + categories: { + propDefinition: [ + app, + "categories", + ], + }, + title: { + propDefinition: [ + app, + "title", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + isClaimed: { + propDefinition: [ + app, + "isClaimed", + ], + }, + limit: { + propDefinition: [ + app, + "limit", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getBusinessListings({ + $, + data: [ + { + location_coordinate: this.locationCoordinate, + categories: this.categories, + description: this.description, + title: this.title, + is_claimed: this.isClaimed, + limit: this.limit, + }, + ], + }); + $.export("$summary", `Successfully sent the request. Status: ${response.tasks[0].status_message}`); + return response; + }, +}; diff --git a/components/dataforseo/actions/get-keyword-difficulty/get-keyword-difficulty.mjs b/components/dataforseo/actions/get-keyword-difficulty/get-keyword-difficulty.mjs new file mode 100644 index 0000000000000..ec0f079888410 --- /dev/null +++ b/components/dataforseo/actions/get-keyword-difficulty/get-keyword-difficulty.mjs @@ -0,0 +1,44 @@ +import app from "../../dataforseo.app.mjs"; + +export default { + key: "dataforseo-get-keyword-difficulty", + name: "Get Keyword Difficulty", + description: "Get Keyword Difficulty. [See the documentation](https://docs.dataforseo.com/v3/dataforseo_labs/google/bulk_keyword_difficulty/live/?bash)", + version: "0.0.1", + type: "action", + props: { + app, + languageCode: { + propDefinition: [ + app, + "languageCode", + ], + }, + locationCode: { + propDefinition: [ + app, + "locationCode", + ], + }, + keywords: { + propDefinition: [ + app, + "keywords", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getKeywordDifficulty({ + $, + data: [ + { + language_code: this.languageCode, + location_code: this.locationCode, + keywords: this.keywords, + }, + ], + }); + $.export("$summary", `Successfully sent the request. Status: ${response.tasks[0].status_message}`); + return response; + }, +}; diff --git a/components/dataforseo/actions/get-ranked-keywords/get-ranked-keywords.mjs b/components/dataforseo/actions/get-ranked-keywords/get-ranked-keywords.mjs new file mode 100644 index 0000000000000..f8d8ef8eb7ffe --- /dev/null +++ b/components/dataforseo/actions/get-ranked-keywords/get-ranked-keywords.mjs @@ -0,0 +1,44 @@ +import app from "../../dataforseo.app.mjs"; + +export default { + key: "dataforseo-get-ranked-keywords", + name: "Get Ranked Keywords", + description: "Description for get-ranked-keywords. [See the documentation](https://docs.dataforseo.com/v3/keywords_data/google_ads/keywords_for_site/task_post/?bash)", + version: "0.0.1", + type: "action", + props: { + app, + locationCode: { + propDefinition: [ + app, + "locationCode", + ], + }, + targetType: { + propDefinition: [ + app, + "targetType", + ], + }, + target: { + propDefinition: [ + app, + "target", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getRankedKeywords({ + $, + data: [ + { + location_code: this.locationCode, + target_type: this.targetType, + target: this.target, + }, + ], + }); + $.export("$summary", `Successfully sent the request. Status: ${response.tasks[0].status_message}`); + return response; + }, +}; diff --git a/components/dataforseo/common/constants.mjs b/components/dataforseo/common/constants.mjs new file mode 100644 index 0000000000000..004a1c4b1e0db --- /dev/null +++ b/components/dataforseo/common/constants.mjs @@ -0,0 +1,6 @@ +export default { + TARGET_TYPES: [ + "site", + "page", + ], +}; diff --git a/components/dataforseo/dataforseo.app.mjs b/components/dataforseo/dataforseo.app.mjs index 63244169bbd81..97c91b754813c 100644 --- a/components/dataforseo/dataforseo.app.mjs +++ b/components/dataforseo/dataforseo.app.mjs @@ -1,11 +1,143 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "dataforseo", - propDefinitions: {}, + propDefinitions: { + locationCode: { + type: "string", + label: "Location Code", + description: "The code of the target location", + async options() { + const response = await this.getLocations(); + const languageCodes = response.tasks[0].result; + return languageCodes.map(({ + location_name, location_code, + }) => ({ + value: location_code, + label: location_name, + })); + }, + }, + locationCoordinate: { + type: "string", + label: "Location Coordinate", + description: "The coordinate of the target location. It should be specified in the “latitude,longitude,radius” format, i.e.: `53.476225,-2.243572,200`", + }, + targetType: { + type: "string", + label: "Target Type", + description: "The type of the target", + options: constants.TARGET_TYPES, + }, + target: { + type: "string", + label: "Target", + description: "The domain name or the url of the target website or page", + }, + categories: { + type: "string[]", + label: "Categories", + description: "The categories you specify are used to search for business listings", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "The description of the business entity for which the results are collected", + optional: true, + }, + title: { + type: "string", + label: "Title", + description: "The name of the business entity for which the results are collected", + optional: true, + }, + isClaimed: { + type: "boolean", + label: "Is Claimed", + description: "Indicates whether the business is verified by its owner on Google Maps", + optional: true, + }, + limit: { + type: "string", + label: "Limit", + description: "The maximum number of returned businesses", + optional: true, + }, + languageCode: { + type: "string", + label: "Language Code", + description: "The language code for the request", + async options() { + const response = await this.getLanguageCode(); + const languageCodes = response.tasks[0].result; + return languageCodes.map(({ + language_name, language_code, + }) => ({ + value: language_code, + label: language_name, + })); + }, + }, + keywords: { + type: "string[]", + label: "Keywords", + description: "Target Keywords. The maximum number of keywords is 1000", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.dataforseo.com/v3"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + auth: { + username: `${this.$auth.api_login}`, + password: `${this.$auth.api_password}`, + }, + }); + }, + async getKeywordDifficulty(args = {}) { + return this._makeRequest({ + path: "/dataforseo_labs/google/bulk_keyword_difficulty/live", + method: "post", + ...args, + }); + }, + async getBusinessListings(args = {}) { + return this._makeRequest({ + path: "/business_data/business_listings/search/live", + method: "post", + ...args, + }); + }, + async getRankedKeywords(args = {}) { + return this._makeRequest({ + path: "/keywords_data/google_ads/keywords_for_site/live", + method: "post", + ...args, + }); + }, + async getLanguageCode(args = {}) { + return this._makeRequest({ + path: "/keywords_data/google_ads/languages", + ...args, + }); + }, + async getLocations(args = {}) { + return this._makeRequest({ + path: "/serp/google/ads_search/locations", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/dataforseo/package.json b/components/dataforseo/package.json index a98066dd2ed19..31d0b5466fb61 100644 --- a/components/dataforseo/package.json +++ b/components/dataforseo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/dataforseo", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream DataForSEO Components", "main": "dataforseo.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 +} From 6f3ec176efb7807fcfcf935ce62063ae51edf447 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 4 Feb 2025 10:00:03 -0300 Subject: [PATCH 2/2] Done requests changes --- pnpm-lock.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b711ee2c35128..7c18b7bbb04ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2548,7 +2548,11 @@ importers: specifier: ^8.3.2 version: 8.3.2 - components/dataforseo: {} + components/dataforseo: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/datagma: {}