/[drupal]/contributions/modules/userpoints/userpoints_service_test.php
ViewVC logotype

Contents of /contributions/modules/userpoints/userpoints_service_test.php

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Apr 2 23:41:08 2008 UTC (19 months, 3 weeks ago) by kbahey
Branch: MAIN
CVS Tags: DRUPAL-5--3-7, DRUPAL-5--3-6, DRUPAL-5--3-5, HEAD
Branch point for: DRUPAL-5--3
File MIME type: text/x-php
XML RPC for userpoints via integration with the services module.

This allows external applications and sites to retrieve and update
points on your site. Many things are possible with this, such as
a Drupal site acting as an award points or user reputation repository
for Joomla or Wordpress sites, or having user actions captured in
other systems (not necessarily web sites) updating the points on
your Drupal site. Use your imagination ...
1 <?php
2
3 function print_error() {
4 print_r(xmlrpc_errno());
5 print_r(xmlrpc_error_msg());
6 }
7
8 if ($_SERVER['SERVER_ADDR'] && $_SERVER['REMOTE_ADDR']) {
9 print "This script should be run from the command line\n";
10 exit(1);
11 }
12
13 require_once('./includes/bootstrap.inc');
14 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
15
16 if ($argc != 4) {
17 print "Usage: php $argv[0] uid server-URL API-key\n";
18 exit(2);
19 }
20
21 $uid = (int)$argv[1];
22 $s = $argv[2];
23 $k = $argv[3];
24
25 print "Querying points for user: $uid\n";
26 $result = xmlrpc($s, 'userpoints.get', $k, $uid, 0);
27 if ($result != FALSE) {
28 print "Points for user $uid = ". $result['points'] ."\n";
29 }
30 else {
31 print_error();
32 }
33
34 $points = 15;
35 print "Adding $points points for user: $uid\n";
36 $result = xmlrpc($s, 'userpoints.points', $k, $uid, $points, 0, NULL, NULL);
37 if ($result != FALSE) {
38 if ($result['status'] == TRUE) {
39 print "Success\n";
40 }
41 else {
42 print "Failed\n";
43 }
44 }
45 else {
46 print_error();
47 }
48
49 $result = xmlrpc($s, 'userpoints.get', $k, $uid, 0);
50 if ($result != FALSE) {
51 print "Points for user $uid = ". $result['points'] ."\n";
52 }
53 else {
54 print_error();
55 }
56
57 $points = -5;
58 print "Subtracting $points points for user: $uid\n";
59 $result = xmlrpc($s, 'userpoints.points', $k, $uid, $points, 0, NULL, NULL);
60 if ($result != FALSE) {
61 if ($result['status'] == TRUE) {
62 print "Success\n";
63 }
64 else {
65 print "Failed\n";
66 }
67 }
68 else {
69 print_error();
70 }
71
72 $result = xmlrpc($s, 'userpoints.get', $k, $uid, 0);
73 if ($result != FALSE) {
74 print "Points for user $uid = ". $result['points'] ."\n";
75 }
76 else {
77 print_error();
78 }
79

  ViewVC Help
Powered by ViewVC 1.1.2