UNPKG

tripadvisor_api_module_v1

Version:
178 lines 8.2 kB
"use strict"; // import "dotenv/config"; // import { Router } from "express"; // import TripadvisorAPI from "../tripadvisor/tripadvisor-api.js"; // import { TripadvisorCategory } from "../consts/tripadvisor-categories.js"; // import { TripadvisorRadiusUnit } from "../consts/tripadvisor-radius-unit.js"; // import { TripadvisorLanguageCode } from "../consts/tripadvisor-language-codes.js"; // import { TripadvisorCurrency } from "../consts/tripadvisor-currencies.js"; // const router = Router(); // const tripadvisorApiUrl = new TripadvisorAPI(process.env.TRIPADVISOR_API_KEY || ""); // /** // * Nearby Search // * ex. 37.601242, 127.036436, 1000 // * latLong: string, // * category?: TripadvisorCategory, // * phone?: string, // * address?: string, // * radius?: number, // * radiusUnit?: TripadvisorRadiusUnit, // * language?: TripadvisorLanguageCode, // */ // router.get("/get/tripadvisor/search/nearby/:latLong", async (req, res) => { // const latLong = req.params.latLong; // const category = req.query.category?.toString() as TripadvisorCategory | undefined; // query string 처리 // const phone = req.query.phone?.toString() || undefined; // query string 처리 // const address = req.query.address?.toString() || undefined; // query string 처리 // const radius = req.query.radius?.toString() || undefined; // query string 처리 // const radiusUnit = (req.query.radiusUnit?.toString() as TripadvisorRadiusUnit) || undefined; // query string 처리 // const language = req.query.language?.toString() || undefined; // query string 처리 // console.log("/get/tripadvisor/search/nearby/:latLong", latLong, category, phone, address, radius, radiusUnit, language); // // ex. https://www.googleapis.com/youtube/v3/search?part=snippet&key=[YOUR_API_KEY]&maxResults=50&q=%EC%84%9C%EC%9A%B8%EC%97%AC%ED%96%89&order=relevance // try { // const response = await tripadvisorApiUrl.searchNearby( // latLong, // category as TripadvisorCategory, // phone, // address, // radius ? Number(radius) : undefined, // radiusUnit as TripadvisorRadiusUnit, // language as TripadvisorLanguageCode, // ); // console.log(response); // res.json(response); // } catch (error) { // console.error(error); // res.status(500).json({ error: "Failed to fetch data from Tripadvisor API" }); // } // }); // /** // * Text Search // * ex. 서울여행 // * searchQuery: string, // * category?: TripadvisorCategory, // * phone?: string, // * address?: string, // * latLong?: string, // * radius?: number, // * radiusUnit?: TripadvisorRadiusUnit, // * language?: TripadvisorLanguageCode, // */ // router.get("/get/tripadvisor/search/text/:query", async (req, res) => { // const query = req.params.query; // const category = req.query.category?.toString() as TripadvisorCategory | undefined; // query string 처리 // const phone = req.query.phone?.toString() || undefined; // query string 처리 // const address = req.query.address?.toString() || undefined; // query string 처리 // const latLong = req.query.latLong?.toString() || undefined; // query string 처리 // const radius = req.query.radius?.toString() || undefined; // query string 처리 // const radiusUnit = (req.query.radiusUnit?.toString() as TripadvisorRadiusUnit) || undefined; // query string 처리 // const language = req.query.language?.toString() || undefined; // query string 처리 // console.log("/get/tripadvisor/search/text/:query", query); // // ex. https://www.googleapis.com/youtube/v3/search?part=snippet&key=[YOUR_API_KEY]&maxResults=50&q=%EC%84%9C%EC%9A%B8%EC%97%AC%ED%96%89&order=relevance // try { // const response = await tripadvisorApiUrl.searchByText( // query, // category as TripadvisorCategory, // phone, // address, // latLong, // radius ? Number(radius) : undefined, // radiusUnit as TripadvisorRadiusUnit, // language as TripadvisorLanguageCode, // ); // console.log(response); // res.json(response); // } catch (error) { // console.error(error); // res.status(500).json({ error: "Failed to fetch data from Tripadvisor API" }); // } // }); // /** // * Get Location Details // * ex. 경복궁 324888 // * locationId: string, // * language?: TripadvisorLanguageCode, // * currency?: TripadvisorCurrency, // */ // router.get("/get/tripadvisor/search/text/:locationId/details", async (req, res) => { // const locationId = req.params.locationId; // const language = req.query.language?.toString() || undefined; // query string 처리 // const currency = req.query.currency?.toString() || undefined; // query string 처리 // console.log("/get/tripadvisor/search/text/:locationId", locationId, language, currency); // // ex. https://www.googleapis.com/youtube/v3/search?part=snippet&key=[YOUR_API_KEY]&maxResults=50&q=%EC%84%9C%EC%9A%B8%EC%97%AC%ED%96%89&order=relevance // try { // const response = await tripadvisorApiUrl.getLocationDetails( // locationId, // language as TripadvisorLanguageCode, // currency as TripadvisorCurrency, // ); // console.log(response); // res.json(response); // } catch (error) { // console.error(error); // res.status(500).json({ error: "Failed to fetch data from Tripadvisor API" }); // } // }); // /** // * Get Location Photos // * ex. 서울여행 Low 37.601242, 127.036436 High 37.601242, 127.036436 // * locationId: string, // * language?: TripadvisorLanguageCode, // * limit?: number, // * offset?: number, // * source?: string, // */ // router.get("/get/tripadvisor/search/text/:locationId/photos", async (req, res) => { // const locationId = req.params.locationId; // const language = req.query.language?.toString() || undefined; // query string 처리 // const limit = req.query.limit?.toString() || undefined; // query string 처리 // const offset = req.query.offset?.toString() || undefined; // query string 처리 // const source = req.query.source?.toString() || undefined; // query string 처리 // console.log("/get/tripadvisor/search/text/:locationId/photos", locationId, language, limit, offset, source); // // ex. https://www.googleapis.com/youtube/v3/search?part=snippet&key=[YOUR_API_KEY]&maxResults=50&q=%EC%84%9C%EC%9A%B8%EC%97%AC%ED%96%89&order=relevance // try { // const response = await tripadvisorApiUrl.getLocationPhotos( // locationId, // language as TripadvisorLanguageCode, // limit ? Number(limit) : undefined, // offset ? Number(offset) : undefined, // source, // ); // console.log(response); // res.json(response); // } catch (error) { // console.error(error); // res.status(500).json({ error: "Failed to fetch data from YouTube API" }); // } // }); // /** // * Get Location Reviews // * ex. 경복궁 // * locationId: string, // * language?: TripadvisorLanguageCode, // * limit?: number, // * offset?: number, // */ // router.get("/get/tripadvisor/search/text/:locationId/reviews", async (req, res) => { // const locationId = req.params.locationId; // const language = req.query.language?.toString() || undefined; // query string 처리 // const limit = req.query.limit?.toString() || undefined; // query string 처리 // const offset = req.query.offset?.toString() || undefined; // query string 처리 // console.log("/get/tripadvisor/search/text/:locationId/reviews", locationId, language, limit, offset); // // ex. https://www.googleapis.com/youtube/v3/search?part=snippet&key=[YOUR_API_KEY]&maxResults=50&q=%EC%84%9C%EC%9A%B8%EC%97%AC%ED%96%89&order=relevance // try { // const response = await tripadvisorApiUrl.getLocationReviews( // locationId, // language as TripadvisorLanguageCode, // limit ? Number(limit) : undefined, // offset ? Number(offset) : undefined, // ); // console.log(response); // res.json(response); // } catch (error) { // console.error(error); // res.status(500).json({ error: "Failed to fetch data from Tripadvisor API" }); // } // }); // export default router; //# sourceMappingURL=tripadvisor-api-test.js.map