/[drupal]/contributions/modules/votesmart/votesmart.api.inc
ViewVC logotype

Contents of /contributions/modules/votesmart/votesmart.api.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Aug 17 15:36:33 2008 UTC (15 months, 1 week ago) by vauxia
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +9 -2 lines
File MIME type: text/x-php
Latest batch of changes -
 - When linked to a Vote Smart record, all CCK, body, and title fields can be
   populated with values from the remote records.
 - Added format callbacks for certain fields, e.g. 't'/'f' can become 1/0
   boolean values, newline-delimited lists can become multivalued fields, etc.
 - Handling of "list" values, such as office type, office branch, state, etc.
 - Reformatted API input array, which should hopefully make things clearer.
 - Continued populating 'tables', to include candidate records.
 - Experimental factory/bulk import working.  For example, you can now import
   all candidates for a particular state election.
1 <?php // $Id: votesmart.api.inc,v 1.2 2008/08/10 01:42:51 vauxia Exp $
2
3 function _votesmart_api($request, $args = array(), $item = null) {
4 $key = variable_get('votesmart_key', '');
5 $url = variable_get('votesmart_host', 'http://api.votesmart.org/');
6
7 // Convert arguments into a request string.
8 $args = array_merge($args, array('key' => $key));
9 $url .= $request . '?';
10 foreach ($args as $k => $v) {
11 $url .= check_plain($k) . '=' . check_plain($v) . '&';;
12 }
13
14 // Contact the REST API.
15 $res = drupal_http_request($url);
16 $ret = (array) new SimpleXMLElement($res->data, LIBXML_NOCDATA);
17
18 // TODO check $ret['errorMessage']
19 if (isset($ret['errorMessage'])) {
20 drupal_set_message(t('Vote Smart API error: %err', array('%err' => $ret['errorMessage'])), 'error');
21 }
22
23 // Return specified element (e.g. 'details', 'list', etc.);
24 if ($item) {
25 foreach (explode('.', $item) as $key) {
26 $ret = (array) $ret[$key];
27 }
28 }
29
30 // Nothing specified, return the entire object.
31 return $ret;
32 }

  ViewVC Help
Powered by ViewVC 1.1.2