lib/API.php
public function execute() {
        $endpoint = "batch";
        $path = $this->build_path($endpoint);

        $ch = curl_init($path);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, self::HTTP_POST);

        // set payload
        $payload_string = json_encode($this->commands);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_string);

        // set headers
        $httpheaders = array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($payload_string),
            $this->API_HEADER_KEY . ": " . $this->API_KEY,
            $this->API_HEADER_CLIENT . ": " . $this->API_CLIENT_STUB
        );

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/data/ca-certificates.pem');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheaders);

        if ($this->DEBUG) {
            // enable curl verbose output to STDERR
            curl_setopt($ch, CURLOPT_VERBOSE, true);

            $this->log_message(sprintf("payload: %s\r\npath: %s\r\n", $payload_string, $path));
        }

        $code = null;

        try {
            $result = curl_exec($ch);
            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $response = json_decode( $result );

            if ($code != 200) {
                throw new API_Error("Request was not successful", $code, $result, $response);
            }
        } catch (API_Error $e) {
            if ($this->DEBUG) {
                $this->log_message(
                    sprintf("Caught exception: %s\r\n%s", $e->getMessage(), print_r($e, true)),
                    self::LOG_ERR
                );
            }

            $response = (object) array(
                'code' => $code,
                'status' => "error",
                'success' => false,
                'exception' => $e
            );
        }

        curl_close($ch);
        $this->commands = array();

        return $response;
    }
public function execute() {
        $endpoint = "batch";
        $path = $this->build_path($endpoint);

        $ch = curl_init($path);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, self::HTTP_POST);

        // set payload
        $payload_string = json_encode($this->commands);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_string);

        // set headers
        $httpheaders = array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($payload_string),
            $this->API_HEADER_KEY . ": " . $this->API_KEY,
            $this->API_HEADER_CLIENT . ": " . $this->API_CLIENT_STUB
        );

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/data/ca-certificates.pem');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheaders);

        if ($this->DEBUG) {
            // enable curl verbose output to STDERR
            curl_setopt($ch, CURLOPT_VERBOSE, true);

            $this->log_message(sprintf("payload: %s\r\npath: %s\r\n", $payload_string, $path));
        }

        $code = null;

        try {
            $result = curl_exec($ch);
            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $response = json_decode( $result );

            if ($code != 200) {
                throw new API_Error("Request was not successful", $code, $result, $response);
            }
        } catch (API_Error $e) {
            if ($this->DEBUG) {
                $this->log_message(
                    sprintf("Caught exception: %s\r\n%s", $e->getMessage(), print_r($e, true)),
                    self::LOG_ERR
                );
            }

            $response = (object) array(
                'code' => $code,
                'status' => "error",
                'success' => false,
                'exception' => $e
            );
        }

        curl_close($ch);
        $this->commands = array();

        return $response;
    }
public function execute ( ) { $ endpoint = "batch" ; $ path = $ this -> build_path ( $ endpoint ) ; $ ch = curl_init ( $ path ) ; curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , self :: HTTP_POST ) ; // set payload $ payload_string = json_encode ( $ this -> commands ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ payload_string ) ; // set headers $ httpheaders = array ( 'Content-Type: application/json' , 'Content-Length: ' . strlen ( $ payload_string ) , $ this -> API_HEADER_KEY . ": " . $ this -> API_KEY , $ this -> API_HEADER_CLIENT . ": " . $ this -> API_CLIENT_STUB ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , true ) ; curl_setopt ( $ ch , CURLOPT_CAINFO , dirname ( __FILE__ ) . '/data/ca-certificates.pem' ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ httpheaders ) ; if ( $ this -> DEBUG ) { // enable curl verbose output to STDERR curl_setopt ( $ ch , CURLOPT_VERBOSE , true ) ; $ this -> log_message ( sprintf ( "payload: %s\r\npath: %s\r\n" , $ payload_string , $ path ) ) ; } $ code = null ; try { $ result = curl_exec ( $ ch ) ; $ code = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; $ response = json_decode ( $ result ) ; if ( $ code != 200 ) { throw new API_Error ( "Request was not successful" , $ code , $ result , $ response ) ; } } catch ( API_Error $ e ) { if ( $ this -> DEBUG ) { $ this -> log_message ( sprintf ( "Caught exception: %s\r\n%s" , $ e -> getMessage ( ) , print_r ( $ e , true ) ) , self :: LOG_ERR ) ; } $ response = ( object ) array ( 'code' => $ code , 'status' => "error" , 'success' => false , 'exception' => $ e ) ; } curl_close ( $ ch ) ; $ this -> commands = array ( ) ; return $ response ; }
Execute all currently queued commands

@return array BatchAPI response object.
Execute all currently queued commands