Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://cloud.feedly.com/v3/subscriptions");
$headers = array("Authorization: OAuth [Add your dev token here]");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
curl_close($ch);
$subscriptions = json_decode($output);
class category {
public $label;
public $subscriptions = array();
}
class subscription {
public $title;
public $feed;
}
$categories = array();
$titleStr = "title";
$categoriesStr = "categories";
$catLabelStr = "label";
$feedStr = "id";
foreach($subscriptions as $subs) {
$categroyExists = false;
$catObj = $subs->$categoriesStr;
foreach($categories as $cat) {
if(strcmp($catObj[0]->$catLabelStr, $cat->label) == 0) {
//echo "category exists " . $catObj[0]->$catLabelStr . "<br>";
$categroyExists = true;
$tempSubscription = new subscription();
$tempSubscription->title = $subs->$titleStr;
$tempSubscription->feed = substr($subs->$feedStr, 5);
array_push($cat->subscriptions, $tempSubscription);
break;
}
}
if(!$categroyExists) {
// echo "new category " . $catObj[0]->$catLabelStr . "<br>";
$tempSubscription = new subscription();
$tempSubscription->title = $subs->$titleStr;
$tempSubscription->feed = substr($subs->$feedStr, 5);
$tempCategory = new category();
$tempCategory->label = $catObj[0]->$catLabelStr;
$tempCategory->subscriptions = array($tempSubscription);
array_push($categories, $tempCategory);
}
}
foreach($categories as $cat) {
echo "<h2>" . $cat->label . "</h2><ul>";
foreach($cat->subscriptions as $sub) {
echo "<li><a href=\"" . $sub->feed . "\" target=\"_blank\">" . $sub->title . "</a></li>";
}
echo "</ul>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment