diff --git a/components/tripadvisor_content_api/actions/location-details/location-details.mjs b/components/tripadvisor_content_api/actions/location-details/location-details.mjs new file mode 100644 index 0000000000000..52446efdba796 --- /dev/null +++ b/components/tripadvisor_content_api/actions/location-details/location-details.mjs @@ -0,0 +1,37 @@ +import app from "../../tripadvisor_content_api.app.mjs"; + +export default { + key: "tripadvisor_content_api-location-details", + name: "Get Location Details", + description: "Returns comprehensive information about a location. [See the documentation](https://tripadvisor-content-api.readme.io/reference/getlocationdetails)", + version: "0.0.1", + type: "action", + props: { + app, + searchQuery: { + propDefinition: [ + app, + "searchQuery", + ], + }, + locationId: { + propDefinition: [ + app, + "locationId", + (c) => ({ + searchQuery: c.searchQuery, + }), + ], + }, + }, + async run({ $ }) { + const response = await this.app.getLocationDetails({ + $, + locationId: this.locationId, + }); + + $.export("$summary", `Successfully returned the details for location '${response.name}'`); + + return response; + }, +}; diff --git a/components/tripadvisor_content_api/actions/location-reviews/location-reviews.mjs b/components/tripadvisor_content_api/actions/location-reviews/location-reviews.mjs new file mode 100644 index 0000000000000..e34a112ea09ce --- /dev/null +++ b/components/tripadvisor_content_api/actions/location-reviews/location-reviews.mjs @@ -0,0 +1,37 @@ +import app from "../../tripadvisor_content_api.app.mjs"; + +export default { + key: "tripadvisor_content_api-location-reviews", + name: "Get Location Reviews", + description: "Returns up to 5 of the most recent reviews for a specific location. [See the documentation](https://tripadvisor-content-api.readme.io/reference/getlocationreviews)", + version: "0.0.1", + type: "action", + props: { + app, + searchQuery: { + propDefinition: [ + app, + "searchQuery", + ], + }, + locationId: { + propDefinition: [ + app, + "locationId", + (c) => ({ + searchQuery: c.searchQuery, + }), + ], + }, + }, + async run({ $ }) { + const response = await this.app.getLocationReviews({ + $, + locationId: this.locationId, + }); + + $.export("$summary", `Successfully listed ${response.data.length} of the most recent reviews for the specified location`); + + return response; + }, +}; diff --git a/components/tripadvisor_content_api/actions/location-search/location-search.mjs b/components/tripadvisor_content_api/actions/location-search/location-search.mjs new file mode 100644 index 0000000000000..f549fb12e9a9c --- /dev/null +++ b/components/tripadvisor_content_api/actions/location-search/location-search.mjs @@ -0,0 +1,44 @@ +import app from "../../tripadvisor_content_api.app.mjs"; + +export default { + key: "tripadvisor_content_api-location-search", + name: "Search Locations", + description: "Returns up to 10 locations found by the given search query. [See the documentation](https://tripadvisor-content-api.readme.io/reference/searchforlocations)", + version: "0.0.1", + type: "action", + props: { + app, + searchQuery: { + propDefinition: [ + app, + "searchQuery", + ], + }, + category: { + propDefinition: [ + app, + "category", + ], + }, + address: { + propDefinition: [ + app, + "address", + ], + }, + }, + async run({ $ }) { + const response = await this.app.searchLocations({ + $, + params: { + searchQuery: this.searchQuery, + category: this.category, + address: this.address, + }, + }); + + $.export("$summary", `Found ${response.data.length} location(s)`); + + return response; + }, +}; diff --git a/components/tripadvisor_content_api/package.json b/components/tripadvisor_content_api/package.json index fb3d8b455bd6b..a8ede8c12b0bc 100644 --- a/components/tripadvisor_content_api/package.json +++ b/components/tripadvisor_content_api/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/tripadvisor_content_api", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Tripadvisor (Content API) Components", "main": "tripadvisor_content_api.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.2" } -} \ No newline at end of file +} diff --git a/components/tripadvisor_content_api/tripadvisor_content_api.app.mjs b/components/tripadvisor_content_api/tripadvisor_content_api.app.mjs index 0d63077fb7a62..4cc75253f9c1c 100644 --- a/components/tripadvisor_content_api/tripadvisor_content_api.app.mjs +++ b/components/tripadvisor_content_api/tripadvisor_content_api.app.mjs @@ -1,11 +1,92 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "tripadvisor_content_api", - propDefinitions: {}, + propDefinitions: { + locationId: { + type: "string", + label: "Location ID", + description: "The ID of the location", + async options({ searchQuery }) { + const { data: resources } = await this.searchLocations({ + params: { + searchQuery, + }, + }); + return resources.map(({ + location_id, name, + }) => ({ + value: location_id, + label: name, + })); + }, + }, + searchQuery: { + type: "string", + label: "Search Query", + description: "The search query to find locations", + }, + address: { + type: "string", + label: "Location Address", + description: "The address of the location", + optional: true, + }, + category: { + type: "string", + label: "Location Category", + description: "The category of the location", + optional: true, + options: [ + "hotels", + "attractions", + "restaurants", + "geos", + ], + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.content.tripadvisor.com/api/v1"; + }, + _makeRequest(opts = {}) { + const { + $ = this, + path, + params, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + params: { + ...params, + key: `${this.$auth.api_key}`, + }, + }); + }, + getLocationDetails({ + locationId, ...args + }) { + return this._makeRequest({ + ...args, + path: `/location/${locationId}/details`, + }); + }, + getLocationReviews({ + locationId, ...args + }) { + return this._makeRequest({ + ...args, + path: `/location/${locationId}/reviews`, + }); + }, + searchLocations(args = {}) { + return this._makeRequest({ + ...args, + path: "/location/search", + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e27a6d5b55a49..f7a1e15033b4f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8821,7 +8821,10 @@ importers: specifiers: {} components/tripadvisor_content_api: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.2 + dependencies: + '@pipedream/platform': 1.6.2 components/truss: specifiers: {}