private List<ApiPagedChannelHistory> getApiChannelHistory(LocalDateTime start, LocalDateTime end) { ApiPagedResponse apiPagedResponse = new ApiPagedResponse(start); do { appendChannelHistory(apiPagedResponse); } while (apiPagedResponse.responsesAreAfter(end) && apiPagedResponse.hasMoreResponses()); return apiPagedResponse.getResponses(); }
private void updateLastResponseDateTime(ApiPagedChannelHistory apiPagedChannelHistory) { List<ApiPagedChannelHistory.ApiMessage> apiMessages = apiPagedChannelHistory.apiMessages; ApiPagedChannelHistory.ApiMessage oldestApiMessage = apiMessages.get(apiMessages.size() - 1); String lastResponseEpochTime = oldestApiMessage.timeStamp; lastResponseDateTime = convertToLocalDateTime(lastResponseEpochTime); hasMore = apiPagedChannelHistory.hasMore; }
public void addResponse(ApiPagedChannelHistory apiPagedChannelHistory) { updateLastResponseDateTime(apiPagedChannelHistory); responses.add(apiPagedChannelHistory); }
@Test public void responseThatHasMessagesThatAreOlderThanTestDate_returnFalse() throws Exception { ApiPagedChannelHistory apiPagedChannelHistory = createApiPagedChannelHistoryWithLastResponseDate(TWENTY16_DEC_1_0_0_0); ApiPagedResponse response = new ApiPagedResponse(null); response.addResponse(apiPagedChannelHistory); assertThat(response.responsesAreAfter(TWENTY16_DEC_12_2_0_0_0)).isEqualTo(false); }
private void appendChannelHistory(ApiPagedResponse apiPagedResponse) { Response<ApiPagedChannelHistory> response = fetchApiChannelHistoryResponse(apiPagedResponse.getLastResponseEpochTime()); if (response.isSuccessful()) { ApiPagedChannelHistory apiPagedChannelHistory = response.body(); apiPagedResponse.addResponse(apiPagedChannelHistory); } else { throw new IllegalStateException("No internet or server down or something." + " code: " + response.code() + " error: " + response.body()); } }
@Test public void responseThatHasMessagesThatAreYoungerThanTestDate_returnTrue() throws Exception { ApiPagedChannelHistory apiPagedChannelHistory = createApiPagedChannelHistoryWithLastResponseDate(TWENTY16_DEC_3_0_0_0); ApiPagedResponse response = new ApiPagedResponse(null); response.addResponse(apiPagedChannelHistory); assertThat(response.responsesAreAfter(TWENTY16_DEC_12_2_0_0_0)).isEqualTo(true); }
public boolean responsesAreAfter(LocalDateTime dateTime) { List<ApiPagedChannelHistory.ApiMessage> latestMessages = responses.get(responses.size() - 1).apiMessages; ApiPagedChannelHistory.ApiMessage latestMessage = latestMessages.get(latestMessages.size() - 1); LocalDateTime latestMessageDateTime = convertToLocalDateTime(latestMessage.timeStamp); return latestMessageDateTime.isAfter(dateTime); } }