Example Code SOAP

From Plings Info

Jump to: navigation, search

Contents

HTTP or HTTPS

You have a choice about how you interact with the server. All examples below are shown of simple HTTP connections. You can substitute https for http in any of the calls, should you desire a more secure data transfer method

PHP NuSOAP

NuSOAP is a popular set of PHP classes - no PHP extensions required - that allow developers to create and consume web services based on SOAP 1.1, WSDL 1.1 and HTTP 1.0/1.1. The example below is as simple as it gets - you may want to add error checking etc to your use.

NOTE: in PHP5 - there is a class name conflict between the native PHP SOAP and NuSOAP (both use the same identifier 'soapclient'). There are fixes on the web including: http://code.google.com/p/nusoap-for-php5

Sending a minimum data set for a SimpleActivity

Please note: In this example we already the VenueID (54684) for the venue where this activity takes place

<?php
//
include ('../lib/nusoap.php');//substitute your own path to nusoap.php
 
//initiate a new SOAP client
$client = new soapclient("http://feeds.plings.net/services/activities.php?wsdl", true);
 
//Set the register/authentication parameters - this is the developer API key
$authenticate = array('Code'=>'5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM');
 
//Minimum parameters required for a SimpleActivity - VenueID relates to a real venue held in http://places.plings.net
$SimpleActivity = array('Name'=>'Computer Club',
                        'Description'=>'Computer game',
                        'Starts'=>'2009-11-27T16:00:00',
                        'Ends'=>'2009-11-27T18:00:00',
                        'ContactName'=>'David C',
                        'ContactNumber'=>'09876543',
                        'VenueID'=>'54684');
 
$result= $client->call('register',$authenticate);
print_r($result);
print_r($client->call('publishSimpleActivity',array($SimpleActivity)));
//Sample Output:
//173009 where the 1 means we authenticated ok (1=true, 0=false) and 73009 is the Activity Id returned by the service
?>

Adding Keyword(s)

<?php
include ('../lib/nusoap.php'); //include the NuSOAP class - substitute your own path.
 
//Initialise the SOAP client
$client = new soapclient("http://feeds.plings.net/services/activities.php?wsdl", true);
 
//Autenticate with the service
$authenticate = array('Code'=>'5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM'); //Developer API KEY
$result= $client->call('register',$authenticate);
print_r($result); //returns '1' on success, '0' on failure
 
//Set up an array of Keywords to add
$Keywords = array('hockey');
//$Keywords = array('hockey','keep fit'); //e.g. for more than one word
 
$ActivityID = '73012';//The unique id of the activity that we want to add our keywords to
 
foreach ($Keywords as $keyword) {
    $ActivityKeywords = array('ActivityID'=>$ActivityID,'Keyword'=>$keyword);
    print_r($client->call('addActivityKeyword',$ActivityKeywords));
}
//Sample Output:
//11 (1=true 0=false), First '1' is authentication ok, second '1' tells us the keyword has been accepted
?>

Adding Category and Taxonomy(s)

(new 06/08/09)

<?php
include ('../lib/nusoap.php'); //include the NuSOAP class - substitute your own path.
 
//Initialise the SOAP client
$client = new soapclient("http://feeds.plings.substance.everis.net/services/activities.php?wsdl", true);
 
//Autenticate with the service
$authenticate = array('Code'=>'5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM'); //Developer API KEY
$result= $client->call('register',$authenticate);
print_r($result); //returns '1' on success, '0' on failure
 
//Set up an values to add
//Plings Taxonomy - see http://www.plings.info/wiki/index.php/Plings_Input_API_-_XML_via_HTTP_POST#Categories
//Note if you just want to use the standard plings categories you can simply use the addActivityCategory method
//$Taxonomy = 'plings';
//$Category = 'Adventure';
//IPSV example
//If you use the IPSV already, then it should be easy to supply this data
//see: http://www.esd.org.uk/standards/ipsv/
$Taxonomy = 'ipsv:384';
$Category = 'Athletics';
 
$ActivityID = '73012';//The unique id of the activity that we want to Categorise
 
 
    $ActivityCategoryOfTaxonomy = array('ActivityID'=>$ActivityID,'Category'=>$Category, 'Taxonomy'=>$Taxonomy);
    print_r($client->call('addActivityCategoryOfTaxonomy',$ActivityCategoryOfTaxonomy));
 
//Sample Output:
//11 (1=true 0=false), First '1' is authentication ok, second '1' tells us the Categrory has been accepted
?>

Removing a Category supplied with a Taxonomy

(new 06/08/09)

<?php
include ('../lib/nusoap.php'); //include the NuSOAP class - substitute your own path.
 
//Initialise the SOAP client
$client = new soapclient("http://feeds.plings.substance.everis.net/services/activities.php?wsdl", true);
 
//Autenticate with the service
$authenticate = array('Code'=>'5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM'); //Developer API KEY
$result= $client->call('register',$authenticate);
print_r($result); //returns '1' on success, '0' on failure
 
//Set up values to remove
//Plings Taxonomy - see http://www.plings.info/wiki/index.php/Plings_Input_API_-_XML_via_HTTP_POST#Categories
//Note if you just want to use the standard plings categories you can simply use the addActivityCategory method
//$Taxonomy = 'pling';
//$Category = 'test';
//IPSV example
//If you use the IPSV already, then it should be easy to supply this data
//see: http://www.esd.org.uk/standards/ipsv/
$Taxonomy = 'ipsv:384';
$Category = 'Athletics';
 
$ActivityID = '73012';//The unique id of the activity that we want to remove our Category from
 
 
    $ActivityCategoryOfTaxonomy = array('ActivityID'=>$ActivityID,'Category'=>$Category, 'Taxonomy'=>$Taxonomy);
    print_r($client->call('removeActivityCategoryOfTaxonomy',$ActivityCategoryOfTaxonomy));
 
//Sample Output:
//11 (1=true 0=false), First '1' is authentication ok, second '1' tells us the Category has been removed
?>

Adding an Organisation

<?php
include ('../lib/nusoap.php');
 
//Initialise the SOAP client
$client = new soapclient("http://feeds.plings.substance.everis.net/services/activities.php?wsdl",true);
 
//Autenticate with the service
$authenticate = array('Code'=>'5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM'); //Developer API KEY
$result= $client->call('register',$authenticate);
print_r($result); //returns '1' on success, '0' on failure
 
$SimpleOrganisation = array('DPProviderID'=>'1',
                     'Name'=>'Made Up Organisation',
                     'ProjectDept' =>'Made up Department',
                     'BuildingNameNo'=>'New Made Up Place',                     
                     'Postcode'=>'M1 2JW',
                     'ContactForename'=>'Org Made Up Forename',
                     'ContactSurname'=>'Org Up Surname',
                     'ContactEmail'=>'madeupemail@madeupemail.com',
                     'Description'=>'A nice organisation');
print_r($client->call('addOrganisation',array($SimpleOrganisation)));
//Returns a Plings OrganisationID on success (> 0)
?>

Deleting an Activity

Please Note: You should use delete with care. Do you really need to delete? Would an update more appropriate? Remember people may want to go back to see data from the past.

<?php
include ('../lib/nusoap.php'); //include the NuSOAP class - substitute your own path.
 
//Initialise the SOAP client
$client = new soapclient("http://feeds.plings.substance.everis.net/services/activities.php?wsdl", true);
 
//Autenticate with the service
$authenticate = array('Code'=>'5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM'); //Developer API KEY
$result= $client->call('register',$authenticate);
print_r($result); //returns '1' on success, '0' on failure
 
 
$ActivityID = '74442';//The unique id of the activity that we want to add our keywords to
$DeleteActivity = array('ActivityID'=>$ActivityID);
   print_r($client->call('deleteActivity',$DeleteActivity));
 
//Sample Output:
//11 (1=true 0=false), First '1' is authentication ok, second '1' tells us the activity has been accepted
?>

PHP5 SOAP

Sending a minimum data set for a SimpleActivity

We're creating a new activity at Venue with ID 54684 (updated 28/04/09 - Added DPProviderID field)

<?php
//Initiate new SOAP Client
$client = new SoapClient("http://feeds.plings.net/services/activities.php?wsdl");
 
//Set the API key - in this case the developer API key - note this is simply a string
$authenticate = '5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM';
 
//Set the array of SimpleActivity parameters - *currently with PHP5 SOAP we need to supply every field*
$SimpleActivity = array('ID'=>'0',
                        'Name'=>'Computer Club',
                        'Description'=>'Computer game',
                        'Starts'=>'2009-11-27T16:00:00',
                        'Ends'=>'2009-11-27T18:00:00',
                        'MinAge'=>'13','MaxAge'=>'18',
                        'Cost'=>'10',
                        'ContactName'=>'David C',
                        'ContactNumber'=>'09876543',
                        'ContactEmail'=>'email@email.com',
                        'ContactAddress'=>'Address details here',
                        'LinkWithActivity'=>'1',
                        'ActivitySource'=>'http://plings.net',
                        'VenueID'=>'54684',
                        'DPProviderID'=>'0');
 
//Make the call to register/authenticate - print_r simply gives us some visual feedback
print_r($client->register($authenticate)); //returns 1 for success, 0 for failure
 
//Send the request to publish our data
print_r($client->publishSimpleActivity($SimpleActivity)); //will return a unique activity id
 
//Example Output:
//173009 where the 1 means we have authenticated ok (1=true, 0=false) and 73009 is the Activity Id returned by the service
?>

Adding Keyword(s)

<?php
//Set some variables
  $authenticate = '5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM';//Developer API Key
  $ActivityID= 73012; //The ID of the activity we want to add a keyword to
  $Keyword= 'Computers'; //The keyword
//$Keyword2 = 'Games'; //Additional keyword
 
//Initiate the SOAP Client
  $client = new SoapClient("http://feeds.plings.net/services/activities.php?wsdl"); 
      print($client->register($authenticate));
      print($client->addActivityKeyword($ActivityID,$Keyword));
    //print($client->addActivityKeyword($ActivityID,$Keyword2));
 
//Sample Output:
//11 (1=true 0=false), First '1' is authenitaction, Second '1' means keyword has been added.
//For more than one keyword at a time, simply make additional calls to:
// $client->addActivityKeyword($ActivityID,$Keyword)
?>

Adding an Organisation

<?php
$client = new soapclient("http://feeds.plings.net/services/activities.php?wsdl");
$authenticate = '5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM';
$SimpleOrganisation = array('ID'=>'0',
                     'DPProviderID'=>'2',
                     'Name'=>'Made Up Organisation',
                     'ProjectDept' =>'Made up Department',
                     'BuildingNameNo'=>'New Made Up Place',   
                     'Street'=>'Madeup Street',
                     'Town'=>'Bingley',
                     'PostTown'=>'Bradford',
                     'County'=>'West Yorkshire',                  
                     'Postcode'=>'M1 2JW',
                     'ContactForename'=>'Org Made Up Forename',
                     'ContactSurname'=>'Org Up Surname',
                     'ContactEmail'=>'madeupemail@madeupemail.com',
                     'ContactPhone'=>'098765432',
                     'ContactFax'=>'0',
                     'Description'=>'A nice organisation',
                     'Website'=>'http://madeupwebsite.com',
                     'MinAge'=>'3',
                     'MaxAge'=>'14');;
print_r($client->register($authenticate));
print_r($client->addOrganisation($SimpleOrganisation));
//Output I got:
//1364 where the 1 means I authenticated ok (1=true, 0=false) and 364 is the Plings OrganisationId returned by the service
?>

Deleting and Activity

Note: Before you delete you should ask if this is really necessary. Would and update be more appropriate?

<?php
//Initialise the SOAP client - PHP5
$client = new soapclient("http://feeds.plings.net/services/activities.php?wsdl");
$authenticate = '5A605302-FC5BC526-4473C6AB-B4D9009B-RQMKMLDM'; //your API key here!
 
//To Test - visit the url below - this is in dev and was created with the key above
//http://feeds.plings.net/activity.php/<YOUR_ACTIVITY_ID_HERE>.xml?APIKey=5A605302FC5BC5264473C6ABB4D9009BRQMKMLDM
//$ActivityID = <YOUR_ACTIVITY_ID_HERE>
//e.g.
$ActivityID = 74443;//The unique id of the activity that we want to add our keywords to
 
print_r($client->register($authenticate)); //returns '0' or '1' - (0=failure, 1=success) 
print_r($client->deleteActivity($ActivityID)); //returns '0' or '1' - (0=failure, 1=success) 
 
//Sample Output:
//11 (1=true 0=false), First '1' is authentication ok, second '1' tells us the item has been deleted.
?>
Personal tools