Skip to content

Instantly share code, notes, and snippets.

@dmendek
Forked from anonymous/tumblrClass.php
Last active December 31, 2022 21:33
Show Gist options
  • Save dmendek/3139246 to your computer and use it in GitHub Desktop.
Save dmendek/3139246 to your computer and use it in GitHub Desktop.
[PHP/OOP/Nostalgic] Tumblr API communication attempts
<?php
/**
* User: dmendek
* Date: 18.07.12
* Time: 16:09
*/
class tumblrClass {
// ----------------------------------------------------------#
// ----------------------------------------------------------#
// ----------------------------------------------------------#
// Blog-Details
public static $apikey = 'x';
public static $nameBlog = 'mendavify';
// Wichtig innerhalb der Klasse
private static $errorContainer;
public $jsonArray;
// ----------------------------------------------------------#
// ----------------------------------------------------------#
// ----------------------------------------------------------#
public static function readInfo() {
return self::jsonToArray(self::jsonGet('http://api.tumblr.com/v2/blog/'.self::$nameBlog.'.tumblr.com/info?api_key='.self::$apikey));
}
public static function readPosts() {
return self::jsonToArray(self::jsonGet('http://api.tumblr.com/v2/blog/'.self::$nameBlog.'.tumblr.com/posts/text?api_key='.self::$apikey));
}
private function jsonGet($url) {
return json_decode(file_get_contents($url), true);
}
private function jsonToArray($json) {
// short conditionals -> http://tinyurl.com/cl6ru4t
return (!$json) ? self::throwException(__FUNCTION__, __LINE__) : $json;
}
private static function throwException($functionName, $exLine) {
self::$errorContainer[] = 'Error in function <strong>'.$functionName.'</strong> on line <strong>'.$exLine.'</strong>';
}
// Destructor der Klasse, falls Fehler auftraten werden diese ausgegeben
public function __destruct() {
if(!empty(self::$errorContainer)) print_r(self::$errorContainer);
}
}
$tumblr = new tumblrClass();
$tumblr->readInfo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment