Closure Compiler RESTFul API output_info Parameter

I’m using the Google Closure Compiler RESTFul API with WordPress.
The request is created using wp_remote_post() and so far everything went okay.

What I want to know is how to get the API to not only return the compiled code, but also the warnings, errors and statistics.

Read More

Supplying 'output_info' => array( 'compiled_code', 'warnings', 'errors', 'statistics' ) in the body parameter seems not to work and the API returns errors. Any ideas?

Thank you very much!

Related posts

Leave a Reply

1 comment

  1. Just looked around and found out that Closure Compiler accepts output_info parameter multiple times. This is not possible with the WP_Http API without some modifications.

    So I looked at the source of WP_Http and did the following, now it’s working 🙂

    // Default request data
    $request_data = array(
        'output_info' => array( 'compiled_code', 'warnings', 'errors', 'statistics' ), 
        'output_format' => 'json'
    );
    $request_data = array_merge( $request_data, $args, compact( 'js_code' ) );
    
    // Process the request body manually to make same named parameters possible
    $body = http_build_query( $request_data, null, '&' );
    $body = preg_replace( '/output_info%5Bd+%5D=/', 'output_info=', $body );
    
    // Initiate request
    $response = wp_remote_post( CLOSURE_COMPILER_URL, array(
        'sslverify' => false, 
        'timeout' => 10, 
        'headers' => array(
            'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' )
        ), 
        'body' => $body
    ));