public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); string url = RequestHelper.ComposeURL("GetRailwayStationInfo"); string company = req.Query["company"]; string line = req.Query["line"]; string station = req.Query["station"]; string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject(requestBody); company = company ?? data?.company; line = line ?? data?.line; station = station ?? data?.station; if (company != null && line != null) { url = $"{url}?acl:consumerKey={await TokenHelper.GetToken("tokyochallenge")}&odpt:operator={OperatorInfo.GetCompanyByName(company)}"; //url = $"{url}?acl:consumerKey={"KEY"}&odpt:operator={OperatorInfo.GetCompanyByName(company)}"; url += $"&odpt:railway={OperatorInfo.GetFormattedLineName(company, line)}"; if (station != null) { url += $"&owl:sameAs={OperatorInfo.GetFormattedStationName(company,line,station)}"; } string response = await RequestHelper.GetJsonString(url); JToken jsonArr = JArray.Parse(response); List <dynamic> result = new List <dynamic>(); foreach (var i in jsonArr) { result.Add(new { StationName = i["dc:title"]?.ToString(), StationCode = i["odpt:stationCode"]?.ToString(), English = i["odpt:stationTitle"]?["en"].ToString(), Latitude = i["geo:lat"], Longitude = i["geo:long"] }); } return((ActionResult) new OkObjectResult(result)); } return(new BadRequestObjectResult("Please pass parameters on the query string or in the request body")); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); Regex regex = new Regex(@"odpt\.\S+\."); string flightNumber = req.Query["flightNumber"]; string airport = req.Query["airport"]; string to = req.Query["to"]; string url = RequestHelper.ComposeURL("GetFlightInfoDeparture"); string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject(requestBody); flightNumber = flightNumber ?? data?.flightNumber; airport = airport ?? data?.airport; to = to ?? data?.to; if (airport != null) { url = $"{url}?acl:consumerKey={await TokenHelper.GetToken("tokyochallenge")}&odpt:operator={OperatorInfo.GetAirportCode(airport)}"; if (flightNumber != null) { url += $"&odpt:flightNumbers={flightNumber}"; } if (to != null) { url += $"&odpt:destinationAirport=odpt.Airport:{to}"; } string response = await RequestHelper.GetJsonString(url); JArray jsonArray = JArray.Parse(response); List <dynamic> result = new List <dynamic>(); foreach (var i in jsonArray) { result.Add(new { Terminal = i["odpt:terminal"]?.ToString().Replace("odpt.AirportTerminal:", "").Substring(4), Gate = i["odpt:gate]"] != null ? regex.Replace(i["odpt:gate"].ToString(), "") : null, DepartureAirport = i["odpt:departureAirport"]?.ToString().Replace("odpt.Airport:", ""), DestinationAirport = i["odpt:destinationAirport"]?.ToString().Replace("odpt.Airport:", ""), FlightNumbers = i["odpt:flightNumbers"], ActualTime = i["odpt:actualTime"], ScheduledTime = i["odpt:scheduledTime"], EstimatedTime = i["odpt:estimatedTime"], FlightStatus = i["odpt:flightStatus"]?.ToString().Replace("odpt.FlightStatus:", ""), AircraftModel = i["odpt:aircraftModel"], BaggageClaim = i["odpt:baggageClaim "], CheckInCounters = i["odpt:checkInCounters"], }); } return(new OkObjectResult(result)); } else { return(new BadRequestObjectResult("Please pass airport name on the query string or in the request body")); } }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); string url = RequestHelper.ComposeURL("GetRailwayFare"); string fromStation = req.Query["fromStation"]; string fromLine = req.Query["fromLine"]; string toStation = req.Query["toStation"]; string toLine = req.Query["toLine"]; string company = req.Query["company"]; string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject(requestBody); fromStation = fromStation ?? data?.fromStation; fromLine = fromLine ?? data?.fromLine; toStation = toStation ?? data?.toStation; toLine = toLine ?? data?.toLine; company = company ?? data?.company; if (company == "JR-East" & fromStation != null & toStation != null) { url = $"https://tokyofare.azurewebsites.net/jr?from={fromStation}&to={toStation}"; string response = await RequestHelper.GetJsonString(url); JToken jsonObj = JObject.Parse(response); List <dynamic> result = new List <dynamic>(); int a = (int)jsonObj["icCardFare"]; result.Add(new RailwayFare() { IcCardFare = (int)jsonObj["icCardFare"], TicketFare = (int)jsonObj["ticketFare"], ChildIcCardFare = (int)jsonObj["childIcCardFare"], ChildTicketFare = (int)jsonObj["childTicketFare"] }); return(new OkObjectResult(result.First())); } if (company == "TsukubaExpress" & fromStation != null & toStation != null) { url = $"https://tokyofare.azurewebsites.net/tsukubaexpress?from={fromStation}&to={toStation}"; string response = await RequestHelper.GetJsonString(url); JToken jsonObj = JObject.Parse(response); List <dynamic> result = new List <dynamic>(); int a = (int)jsonObj["icCardFare"]; result.Add(new RailwayFare() { IcCardFare = (int)jsonObj["icCardFare"], TicketFare = (int)jsonObj["ticketFare"], ChildIcCardFare = (int)jsonObj["childIcCardFare"], ChildTicketFare = (int)jsonObj["childTicketFare"] }); return(new OkObjectResult(result.First())); } if (fromStation != null & toStation != null & fromLine != null & toStation != null & company != null) { url = $"{url}?acl:consumerKey={await TokenHelper.GetToken("tokyochallenge")}&odpt:operator={OperatorInfo.GetCompanyByName(company)}&odpt:fromStation={OperatorInfo.GetFormattedStationName(company, fromLine, fromStation)}&odpt:toStation={OperatorInfo.GetFormattedStationName(company, toLine, toStation)}"; string response = await RequestHelper.GetJsonString(url); JToken jsonArr = JArray.Parse(response); List <dynamic> result = new List <dynamic>(); foreach (var i in jsonArr) { result.Add(new RailwayFare() { IcCardFare = (int)i["odpt:icCardFare"], TicketFare = (int)i["odpt:ticketFare"], ChildIcCardFare = (int)i["odpt:childIcCardFare"], ChildTicketFare = (int)i["odpt:childTicketFare"] }); } return(new OkObjectResult(result.First())); } return(new BadRequestObjectResult("Please pass the required parameters on the query string or in the request body")); }