Skip to content

Instantly share code, notes, and snippets.

@riaf
Created February 7, 2009 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riaf/59955 to your computer and use it in GitHub Desktop.
Save riaf/59955 to your computer and use it in GitHub Desktop.
<?php
/**
* CapaAPI
* for http://gist.github.com/59952
*
* @author riaf <riafweb@gmail.com>
*/
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