Use tutorial - VoiceBunny/php-carrot GitHub Wiki

Using the module

To do this tutorial, you need to have the class installed, we're gonna make a quick project showing you how to post a project in VoiceBunny.

First you need to import the PHP Carrot class

require_once('lib/VoiceBunnyCarrot.php');

You need to initialize the class, dont forget to add your email, API id and API token, need an API Token?

$vb_carrot = new VoiceBunnyCarrot('xx','xxxxXXXXxxxxXXXX');

Check your balance

Now you just need to call the class method that handles the balance requests and need to process the response, if you have any question on what information the API return, check the VoiceBunny API.

$balance = $vb_carrot->balance();
echo "Your account balance is: ". $balance['balance']['amount'] ." ". $balance['balance']['currency'];
$current_balance = floatval($balance['balance']['amount']);

Quoting a script

You're gonna check if the script you're gonna post is not higher than the amount of money you have, to do this, call the class quote method, if you have any doubt on what information the response return, check the VoiceBunny API.

$script = "What's up , folks?";
$language = "eng-us";
$quoteParams = array(
    "script" => $script,
    "language" => $language
);
$quote = $vb_carrot->quote($quoteParams);
echo "Posting this script will cost: ". $quote['quote']['price'] ." ". $quote['quote']['currency'];
$reward = floatval($quote['quote']['price']);

Add a project

After checking the balance and the suggested reward of the project you just need to post the project using the library

if ($current_balance >= $reward){
    $project = array(
        'title' => "Test project",
        'script' => $script,
        'remarks' => "I want the voice to be similar to Bugs Bunny.",
        'price' =>$reward,
        'test' => '1'
    );
    $vb_carrot->create_project($project)
    echo "Project successfully posted.";
}else{
    print "You dont have enough money to post this project.";
}

That's it! you have successfully posted your first project using the PHP Carrot.