<?php

class pythonapi
{
    public function __construct()
    {
        $this->_db = Application::instance()->getDB();
    }
    public function export_zip()
    {
        $data = $_POST;
        $data[ "dburl" ] = Application::get( 'db_uri' );
        
        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded",
                'method'  => 'POST',
                'content' => http_build_query( $data ),
                'timeout' => 2.5
            )
        );
        
        $url = Application::get( 'python_api_export_case' );
        $context = stream_context_create( $options );
        
        try {
            $result = file_get_contents( $url, false, $context );
            $result = json_decode( $result );
        
        } catch ( Exception $e ) {
            throw new Exception( "Python API unreachable" );
        }
        
        if( ! $result->error )
            return $result->id;
        else
            throw new Exception( $result->message );
    }
};

?>