public static function twitter($title) { $twitter = new Twitter(); if ($twitter->tweet($title)) { return true; } return false; }
function newUpdate($data) { if (empty($data['incidents_id'])) { throw new Exception('An incident ID must be specified'); } if (empty($data['message'])) { throw new Exception('A message must be specified'); } if (empty($data['visible'])) { $data['visible'] = 1; } if (empty($data['twitterpost'])) { $data['twitterpost'] = false; } if (empty($data['timeadded'])) { $data['timeadded'] = time(); } $sql = $this->db->prepare("SELECT * FROM incidents WHERE id=:iid LIMIT 1"); $sql->bindValue(':iid', $data['incidents_id'], SQLITE3_INTEGER); $results = $sql->execute(); if ($results === false) { return new Exception('Database error attempting to locate incident'); } $incident = $results->fetchArray(SQLITE3_ASSOC); if (!isset($incident['timeopened'])) { throw new Exception('Invalid Incident ID provided'); } $sql = $this->db->prepare("INSERT INTO incidents_updates (incidents_id, timeadded, message, visible) VALUES (:iid, datetime(:timeadded, 'unixepoch'), :message, :visible)"); $sql->bindValue(':iid', $data['incidents_id'], SQLITE3_TEXT); $sql->bindValue(':timeadded', $data['timeadded'], SQLITE3_INTEGER); $sql->bindValue(':message', $data['message'], SQLITE3_TEXT); $sql->bindValue(':visible', $data['visible'], SQLITE3_INTEGER); $insert = $sql->execute(); if ($data['twitterpost']) { $twitter = new Twitter(); $twitter->tweet($data['message']); } if ($insert === false) { throw new Exception('Unexpected error when attempting to add new incident update'); } return $this->db->lastInsertRowID(); }
foreach ($replacements as $k => $v) { $entified_tweet = substr_replace($entified_tweet, $v, $k, strlen($keys[$k])); } return $entified_tweet; } } class Twitter { const CONSUMER_KEY = ''; const CONSUMER_SECRET = ''; const ACCESS_TOKEN = ''; const ACCESS_TOKEN_SECRET = ''; /** * Will post a tweet to the twitter account * @param string $text */ function tweet($text) { $connection = new tmhOAuth(array('consumer_key' => Twitter::CONSUMER_KEY, 'consumer_secret' => Twitter::CONSUMER_SECRET, 'user_token' => Twitter::ACCESS_TOKEN, 'user_secret' => Twitter::ACCESS_TOKEN_SECRET)); // Make the API call $connection->request('POST', $connection->url('1/statuses/update'), array('status' => $text)); return $connection->response['code']; } } printf('Send deploy notification to Twitter'); $cap_environment = $argv[1]; $cap_deploy_version = $argv[2]; $twitter = new Twitter(); $twitter->tweet("Deployed cap version {$cap_deploy_version} to {$cap_environment}"); return true; // exit(0);