Skip to content

Commit d8e4e1f

Browse files
committed
updates
1 parent 8a5824d commit d8e4e1f

File tree

2 files changed

+82
-16
lines changed

2 files changed

+82
-16
lines changed

components/dataforseo/actions/get-tripadvisor-reviews/get-tripadvisor-reviews.mjs

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@ export default {
1414
label: "Keyword",
1515
description: "The keyword to search for",
1616
},
17+
countryCode: {
18+
type: "string",
19+
label: "Country Code",
20+
description: "The country code of the target location. Ex: `US`",
21+
},
1722
locationCode: {
1823
propDefinition: [
1924
dataforseo,
20-
"locationCode",
25+
"tripAdvisorLocationCode",
26+
(c) => ({
27+
countryCode: c.countryCode,
28+
}),
2129
],
2230
},
2331
languageCode: {
2432
propDefinition: [
2533
dataforseo,
2634
"languageCode",
2735
],
36+
optional: true,
2837
},
2938
sortBy: {
3039
type: "string",
@@ -36,26 +45,58 @@ export default {
3645
],
3746
optional: true,
3847
},
48+
waitForResults: {
49+
type: "boolean",
50+
label: "Wait for Results",
51+
description: "Wait for the results to be available. Not for use with Pipedream Connect.",
52+
default: true,
53+
optional: true,
54+
},
55+
postbackUrl: {
56+
type: "string",
57+
label: "Postback URL",
58+
description: "The URL to receive the search results. Only applicable when \"Wait for Results\" = `FALSE`",
59+
optional: true,
60+
},
3961
},
4062
async run({ $ }) {
41-
const response = await this.dataforseo.getTripadvisorReviews({
42-
$,
43-
data: [
44-
{
45-
keyword: this.keyword,
46-
location_code: this.locationCode,
47-
language_code: this.languageCode,
48-
sort_by: this.sortBy,
49-
},
50-
],
51-
});
63+
let response;
64+
const context = $.context;
65+
const run = context
66+
? context.run
67+
: {
68+
runs: 1,
69+
};
70+
71+
if (run.runs === 1) {
72+
let postbackUrl = this.postbackUrl;
73+
if (context && this.waitForResults) {
74+
({ resume_url: postbackUrl } = $.flow.rerun(600000, null, 1));
75+
}
76+
response = await this.dataforseo.getTripadvisorReviews({
77+
$,
78+
data: [
79+
{
80+
keyword: this.keyword,
81+
location_code: this.locationCode,
82+
language_code: this.languageCode,
83+
sort_by: this.sortBy,
84+
postback_url: postbackUrl,
85+
},
86+
],
87+
});
88+
89+
if (response.status_code !== 20000) {
90+
throw new ConfigurationError(`Error: ${response.status_message}`);
91+
}
5292

53-
if (response.status_code !== 20000) {
54-
throw new ConfigurationError(`Error: ${response.status_message}`);
93+
if (response.tasks[0].status_code !== 20000 && response.tasks[0].status_code !== 20100) {
94+
throw new ConfigurationError(`Error: ${response.tasks[0].status_message}`);
95+
}
5596
}
5697

57-
if (response.tasks[0].status_code !== 20000 && response.tasks[0].status_code !== 20100) {
58-
throw new ConfigurationError(`Error: ${response.tasks[0].status_message}`);
98+
if (run.runs > 1) {
99+
response = run.callback_request.body;
59100
}
60101

61102
$.export("$summary", `Successfully retrieved TripAdvisor reviews for "${this.keyword}".`);

components/dataforseo/dataforseo.app.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ export default {
2020
}));
2121
},
2222
},
23+
tripAdvisorLocationCode: {
24+
type: "integer",
25+
label: "Location Code",
26+
description: "The code of the target location",
27+
async options({ countryCode }) {
28+
const response = await this.getTripadvisorLocations({
29+
countryCode,
30+
});
31+
const locationCodes = response.tasks[0].result;
32+
return locationCodes?.map(({
33+
location_name, location_code,
34+
}) => ({
35+
value: location_code,
36+
label: location_name,
37+
})) || [];
38+
},
39+
},
2340
locationCoordinate: {
2441
type: "string",
2542
label: "Location Coordinate",
@@ -247,6 +264,14 @@ export default {
247264
...args,
248265
});
249266
},
267+
getTripadvisorLocations({
268+
countryCode, ...args
269+
}) {
270+
return this._makeRequest({
271+
path: `/business_data/tripadvisor/locations/${countryCode}`,
272+
...args,
273+
});
274+
},
250275
getGoogleAdsLanguages(args = {}) {
251276
return this._makeRequest({
252277
path: "/keywords_data/google_ads/languages",

0 commit comments

Comments
 (0)