Here try the below code, it should give you a good start.
// requrires 3 arguments
// user, project, path
// usage e.g: [bitbucket user="jespern" project="django-piston" path="piston/utils.py"]
function bitbucket_code( $atts ) {
extract( $atts );
global $post;
$path_to_name = str_replace("https://wordpress.stackexchange.com/", "_", $path);
$meta_key = "bitbucket_{$user}_{$project}_{$path_to_name}";
$code = get_post_meta( $post->ID, $meta_key, true );
if ( !$code ) {
$bitbucket_url = "https://api.bitbucket.org/1.0/repositories/$user/$project/raw/tip/$path";
// just in case its not there ;)
if( !class_exists( 'WP_Http' ) )
include_once( ABSPATH . WPINC. '/class-http.php' );
$request = new WP_Http();
$response = $request->request( $bitbucket_url );
$code = htmlentities( $response['body'] );
update_post_meta( $post->ID, $meta_key, $code );
}
return '<pre>'. $code . '</pre>';
}
add_shortcode('bitbucket', 'bitbucket_code');