Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 120 additions & 4 deletions components/accuranker/accuranker.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,127 @@
import { axios } from "@pipedream/platform";
const DEFAULT_LIMIT = 100;

export default {
type: "app",
app: "accuranker",
propDefinitions: {},
propDefinitions: {
domainId: {
type: "string",
label: "Domain ID",
description: "The ID of the domain",
async options({ page }) {
const { results: domains } = await this.listDomains({
params: {
limit: DEFAULT_LIMIT,
offset: DEFAULT_LIMIT * page,
fields: "id,domain",
},
});
return domains?.map((domain) => ({
label: domain.domain,
value: domain.id,
})) || [];
},
},
keywordId: {
type: "string",
label: "Keyword ID",
description: "The ID of the keyword",
async options({
domainId, page,
}) {
const { results: keywords } = await this.listKeywords({
domainId,
params: {
limit: DEFAULT_LIMIT,
offset: DEFAULT_LIMIT * page,
fields: "id,keyword",
},
});
return keywords?.map((keyword) => ({
label: keyword.keyword,
value: keyword.id,
})) || [];
},
},
periodFrom: {
type: "string",
label: "Period From",
description: "Date in format: YYYY-MM-DD",
optional: true,
},
periodTo: {
type: "string",
label: "Period To",
description: "Date in format: YYYY-MM-DD",
optional: true,
},
max: {
type: "integer",
label: "Max",
description: "Maximum number of results to return",
optional: true,
default: 100,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.accuranker.com/api/v4";
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
...opts,
});
},
listDomains(opts = {}) {
return this._makeRequest({
path: "/domains/",
...opts,
});
},
listKeywords({
domainId, ...opts
}) {
return this._makeRequest({
path: `/domains/${domainId}/keywords/`,
...opts,
});
},
listBrands(opts = {}) {
return this._makeRequest({
path: "/brands/",
...opts,
});
},
async *paginate({
fn, args, max,
}) {
args = {
...args,
params: {
...args?.params,
limit: DEFAULT_LIMIT,
},
};

let total, count = 0;
do {
const { results } = await fn(args);
for (const item of results) {
yield item;
if (max && ++count >= max) {
return count;
}
}
total = results?.length;
args.params.offset += DEFAULT_LIMIT;
} while (total === DEFAULT_LIMIT);
},
},
};
75 changes: 75 additions & 0 deletions components/accuranker/actions/list-brands/list-brands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import accuranker from "../../accuranker.app.mjs";

export default {
key: "accuranker-list-brands",
name: "List Brands",
description: "List brands in Accuranker. [See the documentation](https://app.accuranker.com/api/read-docs#tag/Brands/operation/List%20Brands)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
accuranker,
fields: {
type: "string[]",
label: "Fields",
description: "The fields to return",
optional: true,
default: [
"id",
"last_scraped",
"group",
"domain",
"display_name",
"brand_list",
"competitors",
"history",
"created_at",
],
},
periodFrom: {
propDefinition: [
accuranker,
"periodFrom",
],
},
periodTo: {
propDefinition: [
accuranker,
"periodTo",
],
},
max: {
propDefinition: [
accuranker,
"max",
],
},
},
async run({ $ }) {
const brands = this.accuranker.paginate({
fn: this.accuranker.listBrands,
args: {
$,
params: {
fields: this.fields.join(","),
period_from: this.periodFrom,
period_to: this.periodTo,
},
},
max: this.max,
});

const results = [];
for await (const brand of brands) {
results.push(brand);
}

$.export("$summary", `Found ${results.length} brand(s)`);

return results;
},
};
72 changes: 72 additions & 0 deletions components/accuranker/actions/list-domains/list-domains.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import accuranker from "../../accuranker.app.mjs";

export default {
key: "accuranker-list-domains",
name: "List Domains",
description: "List domains in Accuranker. [See the documentation](https://app.accuranker.com/api/read-docs#tag/Domains/operation/List%20Domains)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
accuranker,
fields: {
type: "string[]",
label: "Fields",
description: "The fields to return",
optional: true,
default: [
"id",
"display_name",
"domain",
"status",
"created_at",
"last_scraped",
],
},
periodFrom: {
propDefinition: [
accuranker,
"periodFrom",
],
},
periodTo: {
propDefinition: [
accuranker,
"periodTo",
],
},
max: {
propDefinition: [
accuranker,
"max",
],
},
},
async run({ $ }) {
const domains = this.accuranker.paginate({
fn: this.accuranker.listDomains,
args: {
$,
params: {
fields: this.fields.join(","),
period_from: this.periodFrom,
period_to: this.periodTo,
},
},
max: this.max,
});

const results = [];
for await (const domain of domains) {
results.push(domain);
}

$.export("$summary", `Found ${results.length} domain(s)`);

return results;
},
};
79 changes: 79 additions & 0 deletions components/accuranker/actions/list-keywords/list-keywords.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import accuranker from "../../accuranker.app.mjs";

export default {
key: "accuranker-list-keywords",
name: "List Keywords",
description: "List keywords for a domain in Accuranker. [See the documentation](https://app.accuranker.com/api/read-docs#tag/Keywords/operation/List%20Keywords)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
accuranker,
domainId: {
propDefinition: [
accuranker,
"domainId",
],
},
fields: {
type: "string[]",
label: "Fields",
description: "The fields to return",
optional: true,
default: [
"id",
"keyword",
"description",
"ranks",
"competitor_ranks",
],
},
periodFrom: {
propDefinition: [
accuranker,
"periodFrom",
],
},
periodTo: {
propDefinition: [
accuranker,
"periodTo",
],
},
max: {
propDefinition: [
accuranker,
"max",
],
max: 100,
},
},
async run({ $ }) {
const keywords = this.accuranker.paginate({
fn: this.accuranker.listKeywords,
args: {
$,
domainId: this.domainId,
params: {
fields: this.fields.join(","),
period_from: this.periodFrom,
period_to: this.periodTo,
},
},
max: this.max,
});

const results = [];
for await (const keyword of keywords) {
results.push(keyword);
}

$.export("$summary", `Found ${results.length} keyword(s)`);

return results;
},
};
4 changes: 2 additions & 2 deletions components/accuranker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/accuranker",
"version": "0.6.0",
"version": "0.7.0",
"description": "Pipedream accuranker Components",
"main": "accuranker.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
"@pipedream/platform": "^3.1.0"
}
}
Loading
Loading