Exemplo n.º 1
0
 public function testFactoryInitializesClientWithToken()
 {
     $client = BasecampClient::factory(array('auth' => 'oauth', 'token' => 'foo', 'version' => 'v2', 'user_id' => '999999999', 'app_name' => 'Fake', 'app_contact' => '*****@*****.**'));
     $this->assertEquals('https://basecamp.com/999999999/api/v2/', $client->getBaseUrl());
 }
Exemplo n.º 2
0
try {
    // last run file name
    $last_run_filename = dirname(__FILE__) . '/last_run_date.txt';
    // set the last run date
    $last_run_date = date('c');
    $since = $last_run_date;
    if (file_exists($last_run_filename)) {
        $since = file_get_contents($last_run_filename);
    }
    // persist the last run date
    $last_run_fp = fopen($last_run_filename, 'w');
    fwrite($last_run_fp, $last_run_date);
    fclose($last_run_fp);
    echo "\n" . 'getting global events since ' . $since . "\n";
    // initiate the basecamp service
    $service = \Basecamp\BasecampClient::factory(array('auth' => 'http', 'username' => BASECAMP_USERNAME, 'password' => BASECAMP_PASSWORD, 'user_id' => BASECAMP_ID, 'app_name' => 'slackcamp', 'app_contact' => 'http://github.com/jamescarlos/slackcamp'));
    // get the events
    $events = $service->getGlobalEvents(array('since' => $since));
    // reverse the array to send the older events first
    $events = array_reverse($events);
    // go through all of the events that are new since we last ran this
    foreach ($events as $event) {
        $message = $event['creator']['name'] . ' ' . strip_tags($event['action']) . ' <' . $event['html_url'] . '|' . $event['target'] . '>';
        $excerpt = isset($event['excerpt']) ? htmlspecialchars_decode($event['excerpt']) : '';
        $attachment = array();
        if ($excerpt) {
            $attachment = array('fallback' => $excerpt, 'fields' => array(array('title' => $event['creator']['name'], 'value' => $excerpt, 'short' => false)));
        }
        // see if a specific slack channel is set for notifications
        $channel = SLACK_DEFAULT_CHANNEL;
        if (isset($slack_channels[$event['bucket']['name']])) {