diff --git a/GitSwitch.php b/GitSwitch.php index 33c1c22..425cd01 100644 --- a/GitSwitch.php +++ b/GitSwitch.php @@ -76,10 +76,10 @@ public static function fetchIssues() /** * Create request URL based on properties and current mode to fetch data from GitHub Issues API. */ - // List Mode - Format: http://github.com/api/v2/json/issues/list/:user/:repo/open + // List Mode - Format: https://api.github.com/repos/:user/:repo/issues?state=open if($mode == "list") { - $requestURL = "http://github.com/api/v2/json/issues/list/" . $username . "/" . $repo . "/" . $state; + $requestURL = "https://api.github.com/repos/" . $username . "/" . $repo . "/issues?state=" . $state; } // Label Mode - Format: http://github.com/api/v2/json/issues/list/:user/:repo/label/:label else if($mode == "label") { $requestURL = "http://github.com/api/v2/json/issues/list/" . $username . "/" . $repo . "/label/" . $label; @@ -91,21 +91,22 @@ public static function fetchIssues() /** * Create array of issues returned from the API query */ - $issuesArray = self::query($requestURL); + $getJsonData = self::query($requestURL); + $issuesArray = @json_decode($getJsonData); /** * Parse JSON from array and format into PivotalTracker ready XML */ $xmlOutput = "\n"; $xmlOutput .= "\n"; - foreach($issuesArray['issues'] as &$issue) { + foreach($issuesArray as $issue) { $xmlOutput .= " \n"; - $xmlOutput .= " " . $issue['number'] . "\n"; - $xmlOutput .= " BUG " . $issue['title'] . "\n"; - $xmlOutput .= " " . $issue['body'] . " GitHub URL: " . $issue['html_url'] . "\n"; + $xmlOutput .= " " . $issue->number . "\n"; + $xmlOutput .= " BUG " . $issue->title . "\n"; + $xmlOutput .= " " . $issue->body . " GitHub URL: " . $issue->html_url . "\n"; $xmlOutput .= " " . $requester . "\n"; - $xmlOutput .= " " . $issue['created_at'] . "\n"; - $xmlOutput .= " BUG\n"; + $xmlOutput .= " " . $issue->created_at . "\n"; + $xmlOutput .= " bug\n"; $xmlOutput .= " 1\n"; $xmlOutput .= " \n"; } @@ -122,22 +123,16 @@ public static function fetchIssues() */ private static function query($url) { - /** - * Initializes the class. - */ - self::init(); - - /** - * Catch the JSON Data - */ - $jsonData = file_get_contents($url); - - /** - * Create data array from JSON data - */ - $jsonArray = json_decode($jsonData, true); - - return $jsonArray; + $userAgent = "Awesome-Octocat-App"; // Provide an default userAgent. If you want you can replace it with your user agent name. + $ch = curl_init(); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + curl_setopt($ch, CURLOPT_URL,$url); + $jsonData=curl_exec($ch); + curl_close($ch); + + return $jsonData; } }