Created
July 18, 2012 22:10
-
-
Save anonymous/3139241 to your computer and use it in GitHub Desktop.
I want to work with the tumblr API, however it looks like I failed at it yet.
Do you have any clues for me?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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