protected void requestResult(RequestType type,String url,String result,int responseCode,String error,String encoding,String token){
  int length=-1;
  if (result != null) {
    length=result.length();
  }
  String encodingText=encoding == null ? "" : ", " + encoding;
  LOGGER.info("GOT (" + responseCode + ", "+ length+ encodingText+ "): "+ url+ " (using authorization)"+ (error != null ? " [" + error + "]" : ""));
  if (type == RequestType.VERIFY_TOKEN) {
    TokenInfo tokenInfo=parseVerifyToken(result);
    resultListener.tokenVerified(token,tokenInfo);
  }
 else   if (type == RequestType.CHANNEL_PUT) {
    requestResult(type,url,result,responseCode,error,encoding);
  }
 else   if (type == RequestType.COMMERCIAL) {
    String stream=removeRequest(url);
    String resultText="Commercial probably not running (unknown response: " + responseCode + ")";
    RequestResult resultCode=RequestResult.UNKNOWN;
    if (responseCode == 204) {
      resultText="Running commercial..";
      resultCode=RequestResult.RUNNING_COMMERCIAL;
    }
 else     if (responseCode == 422) {
      resultText="Commercial length not allowed or trying to run too early.";
      resultCode=RequestResult.FAILED;
    }
 else     if (responseCode == 401 || responseCode == 403) {
      resultText="Can't run commercial: Access denied";
      resultCode=RequestResult.ACCESS_DENIED;
      accessDenied();
    }
 else     if (responseCode == 404) {
      resultText="Can't run commercial: Channel '" + stream + "' not found";
      resultCode=RequestResult.INVALID_CHANNEL;
    }
    if (resultListener != null) {
      resultListener.runCommercialResult(stream,resultText,resultCode);
    }
  }
 else   if (type == RequestType.FOLLOWED_STREAMS) {
    streamInfoManager.requestResultFollows(result,responseCode);
  }
 else   if (type == RequestType.SUBSCRIBERS) {
    String stream=removeRequest(url);
    subscriberManager.received(responseCode,stream,result);
  }
 else   if (type == RequestType.FOLLOW) {
    String target=removeRequest(url);
    if (responseCode == 200) {
      long followTime=followGetTime(result);
      if (followTime != -1 && System.currentTimeMillis() - followTime > 5000) {
        resultListener.followResult(String.format("Already following '%s' (since %s)",target,DateTime.ago(followTime,0,2,0,DateTime.Formatting.VERBOSE)));
      }
 else {
        resultListener.followResult("Now following '" + target + "'");
      }
    }
 else     if (responseCode == 404) {
      resultListener.followResult("Couldn't follow '" + target + "' (channel not found)");
    }
 else     if (responseCode == 401) {
      resultListener.followResult("Couldn't follow '" + target + "' (access denied)");
    }
 else {
      resultListener.followResult("Couldn't follow '" + target + "' (unknown error)");
    }
  }
 else   if (type == RequestType.UNFOLLOW) {
    String target=removeRequest(url);
    if (responseCode == 204) {
      resultListener.followResult("No longer following '" + target + "'");
    }
 else     if (responseCode == 404) {
      resultListener.followResult("Couldn't unfollow '" + target + "' (channel not found)");
    }
 else     if (responseCode == 401) {
      resultListener.followResult("Couldn't unfollow '" + target + "' (access denied)");
    }
 else {
      resultListener.followResult("Couldn't unfollow '" + target + "' (unknown error)");
    }
  }
}

protected void requestResult ( RequestType type , String url , String result , int responseCode , String error , String encoding , String token ) { int length = - 1 ; if ( result != null ) { length = result . length ( ) ; } String encodingText = encoding == null ? "" : ", " + encoding ; LOGGER . info ( "GOT (" + responseCode + ", " + length + encodingText + "): " + url + " (using authorization)" + ( error != null ? " [" + error + "]" : "" ) ) ; if ( type == RequestType . VERIFY_TOKEN ) { TokenInfo tokenInfo = parseVerifyToken ( result ) ; resultListener . tokenVerified ( token , tokenInfo ) ; } else if ( type == RequestType . CHANNEL_PUT ) { requestResult ( type , url , result , responseCode , error , encoding ) ; } else if ( type == RequestType . COMMERCIAL ) { String stream = removeRequest ( url ) ; String resultText = "Commercial probably not running (unknown response: " + responseCode + ")" ; RequestResult resultCode = RequestResult . UNKNOWN ; if ( responseCode == 204 ) { resultText = "Running commercial.." ; resultCode = RequestResult . RUNNING_COMMERCIAL ; } else if ( responseCode == 422 ) { resultText = "Commercial length not allowed or trying to run too early." ; resultCode = RequestResult . FAILED ; } else if ( responseCode == 401 || responseCode == 403 ) { resultText = "Can't run commercial: Access denied" ; resultCode = RequestResult . ACCESS_DENIED ; accessDenied ( ) ; } else if ( responseCode == 404 ) { resultText = "Can't run commercial: Channel '" + stream + "' not found" ; resultCode = RequestResult . INVALID_CHANNEL ; } if ( resultListener != null ) { resultListener . runCommercialResult ( stream , resultText , resultCode ) ; } } else if ( type == RequestType . FOLLOWED_STREAMS ) { streamInfoManager . requestResultFollows ( result , responseCode ) ; } else if ( type == RequestType . SUBSCRIBERS ) { String stream = removeRequest ( url ) ; subscriberManager . received ( responseCode , stream , result ) ; } else if ( type == RequestType . FOLLOW ) { String target = removeRequest ( url ) ; if ( responseCode == 200 ) { long followTime = followGetTime ( result ) ; if ( followTime != - 1 && System . currentTimeMillis ( ) - followTime > 5000 ) { resultListener . followResult ( String . format ( "Already following '%s' (since %s)" , target , DateTime . ago ( followTime , 0 , 2 , 0 , DateTime . Formatting . VERBOSE ) ) ) ; } else { resultListener . followResult ( "Now following '" + target + "'" ) ; } } else if ( responseCode == 404 ) { resultListener . followResult ( "Couldn't follow '" + target + "' (channel not found)" ) ; } else if ( responseCode == 401 ) { resultListener . followResult ( "Couldn't follow '" + target + "' (access denied)" ) ; } else { resultListener . followResult ( "Couldn't follow '" + target + "' (unknown error)" ) ; } } else if ( type == RequestType . UNFOLLOW ) { String target = removeRequest ( url ) ; if ( responseCode == 204 ) { resultListener . followResult ( "No longer following '" + target + "'" ) ; } else if ( responseCode == 404 ) { resultListener . followResult ( "Couldn't unfollow '" + target + "' (channel not found)" ) ; } else if ( responseCode == 401 ) { resultListener . followResult ( "Couldn't unfollow '" + target + "' (access denied)" ) ; } else { resultListener . followResult ( "Couldn't unfollow '" + target + "' (unknown error)" ) ; } } }
result for authorized requests .
