private static int postRUM ( String apiKey , String jsonPayload ) { try { if ( validateApiKey ( apiKey ) ) { String endpoint = RaygunSettings . getRUMEndpoint ( ) ; MediaType MEDIA_TYPE_JSON = MediaType . parse ( "application/json; charset=utf-8" ) ; OkHttpClient client = new OkHttpClient . Builder ( ) . connectTimeout ( NETWORK_TIMEOUT , TimeUnit . SECONDS ) . writeTimeout ( NETWORK_TIMEOUT , TimeUnit . SECONDS ) . readTimeout ( NETWORK_TIMEOUT , TimeUnit . SECONDS ) . build ( ) ; RequestBody body = RequestBody . create ( MEDIA_TYPE_JSON , jsonPayload ) ; Request request = new Request . Builder ( ) . url ( endpoint ) . header ( "X-ApiKey" , apiKey ) . post ( body ) . build ( ) ; Response response = null ; try { response = client . newCall ( request ) . execute ( ) ; RaygunLogger . d ( "RUM HTTP POST result: " + response . code ( ) ) ; return response . code ( ) ; } catch ( IOException ioe ) { RaygunLogger . e ( "OkHttp POST to Raygun RUM backend failed - " + ioe . getMessage ( ) ) ; ioe . printStackTrace ( ) ; } finally { if ( response != null ) response . body ( ) . close ( ) ; } } } catch ( Exception e ) { RaygunLogger . e ( "Can't post to RUM. Exception - " + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } return - 1 ; }
Raw post method that delivers a pre - built RUM payload to the Raygun API .