Created
September 30, 2014 23:23
-
-
Save dreeves/dc077334d6cd1b4e66d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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