Falcon_Handler_Mandrill::send_single PHP Метод

send_single() защищенный Метод

protected send_single ( $data )
    protected function send_single($data)
    {
        $headers = array('Accept' => 'application/json', 'Content-Type' => 'application/json');
        $body = array('key' => $this->api_key, 'message' => $data);
        $response = wp_remote_post('https://mandrillapp.com/api/1.0/messages/send.json', array('headers' => $headers, 'body' => json_encode($body)));
        $code = wp_remote_retrieve_response_code($response);
        switch ($code) {
            case 200:
                break;
            case 401:
                throw new Exception(__('Invalid API key', 'falcon'), 401);
            case 422:
                throw new Exception(sprintf(__('Error with sent body: %s', 'falcon'), wp_remote_retrieve_body($response)), 422);
            case 500:
                throw new Exception(__('Mandrill server error', 'falcon'), 500);
            default:
                throw new Exception(__('Unknown error', 'falcon'), (int) $code);
        }
        $data = json_decode(wp_remote_retrieve_body($response));
        if (empty($data)) {
            throw new Exception(__('Invalid response from Mandrill', 'falcon'));
        }
        return $data[0]->_id;
    }