public static String create ( final OmdbParameters params ) throws OMDBException { StringBuilder sb = new StringBuilder ( BASE_URL ) ; sb . append ( DELIMITER_FIRST ) ; //Add the APIKey first if ( params . has ( Param . APIKEY ) ) { String apikey = ( String ) params . get ( Param . APIKEY ) ; sb . append ( Param . APIKEY . getValue ( ) ) . append ( apikey ) ; } else { throw new OMDBException ( ApiExceptionType . AUTH_FAILURE , "Must include an ApiKey to make a call" ) ; } //Needed for everything after sb . append ( DELIMITER_SUBSEQUENT ) ; if ( params . has ( Param . SEARCH ) ) { String search = ( String ) params . get ( Param . SEARCH ) ; sb . append ( Param . SEARCH . getValue ( ) ) . append ( search . replace ( " " , "+" ) ) ; } else if ( params . has ( Param . IMDB ) ) { sb . append ( Param . IMDB . getValue ( ) ) . append ( params . get ( Param . IMDB ) ) ; } else if ( params . has ( Param . TITLE ) ) { String title = ( String ) params . get ( Param . TITLE ) ; sb . append ( Param . TITLE . getValue ( ) ) . append ( title . replace ( " " , "+" ) ) ; } else { throw new OMDBException ( ApiExceptionType . INVALID_URL , "Must include a search or ID" ) ; } // Append the year appendParam ( params , Param . YEAR , sb ) ; // Append the plot requirement if ( params . has ( Param . PLOT ) && ( PlotType ) params . get ( Param . PLOT ) != PlotType . getDefault ( ) ) { appendParam ( params , Param . PLOT , sb ) ; } // Append the tomatoes requirement appendParam ( params , Param . TOMATOES , sb ) ; // Append the Type appendParam ( params , Param . RESULT , sb ) ; // Append the JSON request - This is not used by this API appendParam ( params , Param . DATA , sb ) ; // Append the version appendParam ( params , Param . VERSION , sb ) ; // Append the callback function - This is not used by this API appendParam ( params , Param . CALLBACK , sb ) ; LOG . trace ( "Created URL: {}" , sb . toString ( ) ) ; return sb . toString ( ) ; }
Create the String representation of the URL for passed parameters