/**
   * {@inheritDoc}
   *
   * @see org.apache.http.client.ResponseHandler#handleResponse(org.apache.http.HttpResponse)
   */
  @Override
  public final ApiResponse<V> handleResponse(final HttpResponse response)
      throws ClientProtocolException, IOException {

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("handleResponse.start");
    }

    InputStream inputStream = response.getEntity().getContent();

    final ApiResponse<V> apiResponse = handleJsonResponse(inputStream);

    inputStream.close();

    try {
      KeoUtils.checkResponse(apiResponse);
    } catch (final JsonParseException e) {
      throw new IOException("Unable to parse the json response received from Keolis:\n" + e);
    }

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("handleResponse.end");
    }
    return apiResponse;
  }
  /**
   * Handles the JSON reponse and deserialize it.
   *
   * @param responseStream http response input stream
   * @return the api response
   */
  private ApiResponse<V> handleJsonResponse(final InputStream inputStream) {

    return KeoUtils.getGsonInstance().fromJson(new InputStreamReader(inputStream), type);
  }