public function testOauth() { global $keys; // We can only do oauth if secret is present if (empty($keys->secret)) { $this->markTestSkipped('testOauth: Missing oAuth secret'); } // oAuth test messes with trello object, create a new one for testing here $trello = new Trello($keys->key, $keys->secret); // Get an authorize URL (or true if we're already auth'd) $authorizeUrl = $trello->authorize(array('scope' => array('read' => true, 'write' => true, 'account' => true), 'redirect_uri' => 'http://127.0.0.1:23456', 'name' => 'php-trello Testing', 'expiration' => '1hour'), true); // Need to get authorized if ($authorizeUrl !== true) { $server = stream_socket_server('tcp://127.0.0.1:23456', $errno, $errmsg); if (!$server) { $this->markTestIncomplete("testOauth: Could not create a socket at 127.0.0.1:23456: {$errmsg}"); } // Fire off the browser `xdg-open "{$authorizeUrl}" >/dev/null 2>&1 &`; //echo "Waiting for authorization from Trello...\n"; $client = @stream_socket_accept($server, -1); if (!$client) { $this->markTestIncomplete('testOauth: Failed to receive Trello response.'); } $query = fgets($client, 1024); // Received a response, let's send back a message $msg = "Please close this browser window and return to the test to continue."; fputs($client, "HTTP/1.1 200 OK\r\n"); fputs($client, "Connection: close\r\n"); fputs($client, "Content-Type: text/html; charset=UTF-8\r\n"); fputs($client, "Content-Length: " . strlen($msg) . "\r\n\r\n"); fputs($client, $msg); fclose($client); // Wait to continue the test until the browser returns. //readline("Press [Enter] to continue..."); // Lets parse the query and pull out the oauth stuff if (!preg_match('~GET (.*?) HTTP~', $query, $match)) { $this->markTestIncomplete('testOauth: Could not read response from Trello.'); } // Parse the query portion of the URL into the GET variable parse_str(parse_url($match[1], PHP_URL_QUERY), $_GET); $this->assertTrue(self::$trello->authorize()); } }
* Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ require "config.php"; require "vendor/autoload.php"; use Trello\Trello; // Step One: Check bitbucket params $req_body = file_get_contents('php://input'); if (!strlen($req_body)) { die("No input"); } $trello = new Trello(TRELLO_API_KEY, null, TRELLO_API_TOKEN); $find = "https://trello.com/c/"; $payload = json_decode($req_body); if (!isset($payload->commits)) { die("Invalid payload."); } $total_commits_used = 0; $total_cards_used = 0; // Step two: Go through each commit and create the cards for each foreach ($payload->commits as $commit) { // Check the commit message for card references. Should be full URLs to card or the share URL. $msg = $commit->message; $cards = array(); while (stristr($msg, $find)) { $msg = substr($msg, strpos($msg, $find)); $a = explode($find, $msg);
<?php require __DIR__ . '/vendor/autoload.php'; date_default_timezone_set('America/Vancouver'); error_reporting(0); use Trello\Trello; require_once __DIR__ . '/config.php'; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $cardsToKeep = ''; $trello = new Trello($key, null, $token); $boardsOptions = array(); $boardsOptions['boards'] = 'all'; $cardOptions = array(); $cardOptions['filter'] = 'all'; $cardOptions['fields'] = 'id,name,shortUrl,due,dateLastActivity,closed,desc,idBoard,idList,labels,pos'; $cardOptions['limit'] = $cardsLimit; $labelOptions = array(); $labelOptions['limit'] = 1000; $labelOptions['fields'] = 'color,idBoard,name,uses'; $listOptions = array(); $listOptions['filter'] = 'all'; $listOptions['fields'] = 'closed,idBoard,name,pos'; $me = $trello->members->get('me', $boardsOptions); $partialCardsToKeep = ''; foreach ($me->idBoards as $boardId) { $board = $trello->boards->get($boardId);