Skip to content

Instantly share code, notes, and snippets.

@dreeves
Created September 30, 2014 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreeves/dc077334d6cd1b4e66d9 to your computer and use it in GitHub Desktop.
Save dreeves/dc077334d6cd1b4e66d9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
$path = '/Users/dreeves/prj/beeminder-php-api';
$usr = 'test1602';
$key = 'gpNE1uWHVLq2Erbn4cCH';
$slug = 'test';
function roadtighten($api, $goal) {
$road = $goal->roadall;
$init = reset($road);
$dial = end($road);
try {
$api->getGoalApi()->editGoal($goal->slug,
array('roadall'=>json_encode(array($init,$dial))));
} catch (Exception $e) {
return 1;
}
return 0;
}
require_once $path.'/lib/Beeminder/Autoloader.php';
Beeminder_Autoloader::register();
$api = new Beeminder_Client();
$api->login($usr, $key, Beeminder_Client::AUTH_PRIVATE_TOKEN);
# In case you want to iterate over all goals like foreach($goals as $g)...
# $goals = $api->getGoalApi()->getGoals();
$g = $api->getGoalApi()->getGoal($slug);
echo "Tightening the yellow brick road: {$g->slug} ($g->title)\n";
if(roadtighten($api, $g) == 0) {
echo "Tightened the road!\n";
} else {
echo "Failed to tighten the road (probably not enough safety buffer)!\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment