better serialization of arrays and booleans in config output

darcs-hash:20081230211957-84dde-ea044934e16bb8ef89e762159ecea1fa008b65b9.gz
This commit is contained in:
Evan Prodromou 2008-12-30 16:19:57 -05:00
parent 91a41242ef
commit 76d91a358b
5 changed files with 32 additions and 46 deletions

View File

@ -108,4 +108,6 @@ Evan Prodromou <evan@prodromou.name>**20081230205939]
[add some breaks so that switch statement works [add some breaks so that switch statement works
Evan Prodromou <evan@prodromou.name>**20081230210114] Evan Prodromou <evan@prodromou.name>**20081230210114]
[implement the api/laconica/config method [implement the api/laconica/config method
Evan Prodromou <evan@prodromou.name>**20081230211444] Evan Prodromou <evan@prodromou.name>**20081230211444]
[better serialization of arrays and booleans in config output
Evan Prodromou <evan@prodromou.name>**20081230211957]

View File

@ -119,7 +119,15 @@ class TwitapilaconicaAction extends TwitterapiAction
foreach ($keys as $section => $settings) { foreach ($keys as $section => $settings) {
common_element_start($section); common_element_start($section);
foreach ($settings as $setting) { foreach ($settings as $setting) {
common_element($setting, null, common_config($section, $setting)); $value = common_config($section, $setting);
if (is_array($value)) {
$value = implode(',', $value);
} else if ($value === false) {
$value = 'false';
} else if ($value === true) {
$value = 'true';
}
common_element($setting, null, $value);
} }
common_element_end($section); common_element_end($section);
} }

View File

@ -1,43 +1,11 @@
hunk ./actions/twitapilaconica.php 92 hunk ./actions/twitapilaconica.php 122
+ * URL: http://identi.ca/api/laconica/config.(xml|json) - common_element($setting, null, common_config($section, $setting));
+ * Formats: xml, json + $value = common_config($section, $setting);
hunk ./actions/twitapilaconica.php 105 + if (is_array($value)) {
+ static $keys = array('site' => array('name', 'server', 'theme', 'path', 'fancy', 'language', + $value = implode(',', $value);
+ 'email', 'broughtby', 'broughtbyurl', 'closed', + } else if ($value === false) {
+ 'inviteonly', 'private'), + $value = 'false';
+ 'license' => array('url', 'title', 'image'), + } else if ($value === true) {
+ 'nickname' => array('featured'), + $value = 'true';
+ 'throttle' => array('enabled', 'count', 'timespan'), + }
+ 'xmpp' => array('enabled', 'server', 'user')); + common_element($setting, null, $value);
+
hunk ./actions/twitapilaconica.php 114
- common_server_error(_('API method under construction.'), 501);
+
+ switch ($apidata['content-type']) {
+ case 'xml':
+ $this->init_document('xml');
+ // XXX: check that all sections and settings are legal XML elements
+ foreach ($keys as $section => $settings) {
+ common_element_start($section);
+ foreach ($settings as $setting) {
+ common_element($setting, null, common_config($section, $setting));
+ }
+ common_element_end($section);
+ }
+ $this->end_document('xml');
+ break;
+ case 'json':
+ $result = array();
+ foreach ($keys as $section => $settings) {
+ $result[$section] = array();
+ foreach ($settings as $setting) {
+ $result[$section][$setting] = common_config($section, $setting);
+ }
+ }
+ $this->init_document('json');
+ $this->show_json_objects($result);
+ $this->end_document('json');
+ break;
+ default:
+ $this->client_error(_('API method not found!'), $code=404);
+ }

View File

@ -119,7 +119,15 @@ class TwitapilaconicaAction extends TwitterapiAction
foreach ($keys as $section => $settings) { foreach ($keys as $section => $settings) {
common_element_start($section); common_element_start($section);
foreach ($settings as $setting) { foreach ($settings as $setting) {
common_element($setting, null, common_config($section, $setting)); $value = common_config($section, $setting);
if (is_array($value)) {
$value = implode(',', $value);
} else if ($value === false) {
$value = 'false';
} else if ($value === true) {
$value = 'true';
}
common_element($setting, null, $value);
} }
common_element_end($section); common_element_end($section);
} }