public ServiceResponse <List <BusLocationInfo> > GetBusLocations(ServiceRequest <string> request) { var oBiletAPIRequest = new OBiletRequest <string> { Date = request.Date, Language = request.Language, DeviceSession = new DeviceSession { DeviceId = request.DeviceId, SessionId = request.SessionId }, Data = request.Data }; //TODO: Bu code bloğu extract edilmeli. var uri = _httpClient.BaseAddress + "/getbuslocations";//TODO: Burayı config'e bağla hard coded olmasın var content = new StringContent(JsonConvert.SerializeObject(oBiletAPIRequest), Encoding.UTF8, "application/json"); var response = _httpClient.PostAsync(uri, content); var result = response.Result.Content.ReadAsStringAsync(); var oBiletResponse = JsonConvert.DeserializeObject <OBiletResponse <List <BusLocationInfo> > >(result.Result); var serviceResponse = _oBiletResponseHandler.HandleResponse(oBiletResponse); return(serviceResponse); }
public ServiceResponse <List <BusJourneyInfo> > GetBusJourneys(ServiceRequest <BusJourneyFilter> request) { var cachedResult = _memoryCache.Get <ServiceResponse <List <BusJourneyInfo> > >( $"{CacheConsts.GetJourneysJourneyServiceKey}-{request.Data.OriginId}-{request.Data.DestinationId}-{request.Data.DepartureDate}"); if (cachedResult != null && cachedResult.Status == ResponseStatus.Success) { return(cachedResult); } var oBiletAPIRequest = new OBiletRequest <BusJourneyFilter> { Date = request.Date, Language = request.Language, DeviceSession = new DeviceSession { DeviceId = request.DeviceId, SessionId = request.SessionId }, Data = request.Data }; //TODO: Burayı config'e bağla hard coded olmasın var uri = _httpClient.BaseAddress + "/getbusjourneys"; var content = new StringContent(JsonConvert.SerializeObject(oBiletAPIRequest), Encoding.UTF8, "application/json"); var response = _httpClient.PostAsync(uri, content); var result = response.Result.Content.ReadAsStringAsync(); var oBiletResponse = JsonConvert.DeserializeObject <OBiletResponse <List <BusJourneyInfo> > >(result.Result); var serviceResponse = _oBiletResponseHandler.HandleResponse(oBiletResponse); if (serviceResponse.Status == ResponseStatus.Success) { _memoryCache.Set(CacheConsts.GetJourneysJourneyServiceKey, serviceResponse, CacheConsts.GetJourneysServiceDuration); } return(serviceResponse); }