@ Nullable private Request makeRequest ( List < MobileEventJson > batch ) throws IOException { if ( batch . isEmpty ( ) ) { return null ; } Sift . Config config = configProvider . getConfig ( ) ; if ( config == null ) { Log . d ( TAG , "Missing Sift.Config object" ) ; return null ; } if ( config . accountId == null || config . beaconKey == null || config . serverUrlFormat == null ) { Log . d ( TAG , "Missing account ID, beacon key, and/or server URL format" ) ; return null ; } if ( batch . isEmpty ( ) ) { Log . d ( TAG , "Batch is null or empty" ) ; return null ; } URL url = new URL ( String . format ( config . serverUrlFormat , config . accountId ) ) ; final String encodedBeaconKey = Base64 . encodeToString ( config . beaconKey . getBytes ( US_ASCII ) , Base64 . NO_WRAP ) ; Map < String , String > headers = new HashMap < String , String > ( ) ; headers . put ( "Authorization" , "Basic " + encodedBeaconKey ) ; headers . put ( "Accept" , "application/json" ) ; headers . put ( "Content-Encoding" , "gzip" ) ; headers . put ( "Content-Type" , "application/json" ) ; ListRequestJson request = new ListRequestJson ( ) . withData ( Collections . < Object > unmodifiableList ( batch ) ) ; ByteArrayOutputStream os = new ByteArrayOutputStream ( ) ; OutputStream gzip = new GZIPOutputStream ( os ) ; Writer writer = new OutputStreamWriter ( gzip , UTF8 ) ; Sift . GSON . toJson ( request , writer ) ; writer . close ( ) ; Log . d ( TAG , String . format ( "Built HTTP request for batch of size %d" , batch . size ( ) ) ) ; return new Request . Builder ( ) . withMethod ( "PUT" ) . withUrl ( url ) . withHeaders ( headers ) . withBody ( os . toByteArray ( ) ) . build ( ) ; }
Builds a Request for the specified event batch