Created
February 7, 2009 18:18
-
-
Save riaf/59955 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* CapaAPI | |
* for http://gist.github.com/59952 | |
* | |
* @author riaf <[email protected]> | |
*/ | |
Rhaco::import('lang.Variable'); | |
Rhaco::import('network.http.Http'); | |
Rhaco::import('tag.model.TemplateFormatter'); | |
Rhaco::constant('_CAPA_URL', 'http://example.com/'); | |
Rhaco::constant('_CAPA_SECRET', md5('secret')); | |
class CapaAPI | |
{ | |
var $domain; | |
function CapaAPI($domain='__uri'){ | |
$this->__init__($domain); | |
} | |
function __init__($domain){ | |
$this->domain = $domain; | |
} | |
function set($key, $value){ | |
return Http::post(Rhaco::constant('_CAPA_URL'), array( | |
'secret' => Rhaco::constant('_CAPA_SECRET'), | |
'key' => $key, | |
'domain' => $this->domain, | |
'value' => $value, | |
)); | |
} | |
function get($key=null){ | |
$params = array('secret' => Rhaco::constant('_CAPA_SECRET'), 'domain' => $this->domain); | |
if(!is_null($key)){ | |
$params['key'] = $key; | |
} | |
$r = Http::get(Rhaco::constant('_CAPA_URL'). '?'. TemplateFormatter::httpBuildQuery($params)); | |
return ($r != false) ? (function_exists('json_decode')? json_decode($r, true): Variable::parseJson($r)): false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment