我正在使用vertx和java,我是vertx的新手,并且我有一个api。请转到下面的链接以更好地了解
https://www.tez-tour.com/tariffsearch/hotels?countryId=1104&cityId=345&locale=en (countryId (destination)= Turkey, cityId (city of depature)= Moscow)
和一个Python示例脚本,用于从游览api获取数据
import asyncio
from aiohttp import ClientSession
import json
async def do_request(url):
async with ClientSession() as session:
async with session.get(url) as response:
resp = await response.read()
#print(str(resp, 'utf-8'))
parsed = json.loads(str(resp, 'utf-8'))
print(parsed)
tasks = []
tourCities = {
/*'Turkey': {
'cities': [1285,12689,12706,143330,9004247,4433,5736,139343,4434,12691,21301,12705,149827,4151426]
},*/
'Austria': {
'tourId': [308122,3024267,147579,353869,320460,3024283,253138,3026464,3024262,293808,469713,3024272,314293,467029,348518,544505,384331,594027,3025654,258494],
'params': {
'hotelClasses': [ // Типы отелей
{"classId": 269506,"name": "Special Cat.","weight": -9},
{"classId": 261942,"name": "Chalet","weight": -8},
{"classId": 253005,"name": "Apts","weight": -6},
{"classId": 253006,"name": "Pens","weight": -5},
],
"tourTypes": [ // Состав тура
{"id": 1,"name": "Полный пакет","haveResidence": true,"haveTransfer": true,"haveFly": true,"haveInsurance": true},
{"id": 2,"name": "Проживание+трансфер","haveResidence": true,"haveTransfer": true,"haveFly": false,"haveInsurance": true},
],
"pansion": [ // Пансион
{"rAndBId": 15350,"name": "Размещение без питания","weight": 0,"sortOrder": 0},
{"rAndBId": 2424,"name": "Только завтраки","weight": 1,"sortOrder": 1},
{"rAndBId": 2474,"name": "Завтрак и ужин","weight": 3,"sortOrder": 3},
],
"tours": [ // Регионы (города, куда ищем тур)
{"name": "Бад-Кляйнкирхайм","tourId": [308122]},
{"name": "Баден","tourId": [3024267]},
旅游运营商有一个网站(或外部REST API),可从中获取旅游数据 他们每个人都向我们提供身份验证数据(登录名和密码)以连接到他们的旅游数据库(无jdbc,仅基于Web的访问权限)
所以我有一些接口要实现,我应该使用WebClient,但是我不完全了解如何编写此方法以从上面的api中获取 我有两种实现方法
@Override
public YuService runParserTask(String tourOperator, Handler<AsyncResult<Void>> handler) {
return this;
}
@Override
public YuService getTaskStatus(String tourOperator, Handler<AsyncResult<ParseTask>> handler) {
return this;
}
和具有ENUM状态的解析器dto如下
@DataObject(generateConverter = true)
public class ParseTask {
private String type;
private Status status;
public ParseTask(String type, Status status) {
this.type = type;
this.status = status;
}
public ParseTask(JsonObject json) {
ParseTaskConverter.fromJson(json, this);
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
ParseTaskConverter.toJson(this, json);
return json;
}
我可以解释一下可能是一些代码,可以帮助我更好地理解如何实现此方法