Example Code HTTP POST

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

Example Code for HTTP post (XML)

PHP - HTTP post request (using cURL)

Sends XML contained in a file 'testActivity.xml'

<?php
function sendXmlOverPost($url, $xml) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
 
  // For xml, change the content-type.
  curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
 
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned
/*  if(CurlHelper::checkHttpsURL($url)) { 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  }
*/
  // Send to remote and return data to caller.
  $result = curl_exec($ch);
  curl_close($ch);
  return $result;
}
 
print sendXmlOverPost('http://feeds.plings.net/services/plings-in.php?APIKey=5A605302FC5BC5264473C6ABB4D9009BRQMKMLDM'
	, file_get_contents('testActivity.xml'));
 
?>


Example XML

Complete data set

updated 20/04/09
This dataset includes the one additional field that is required as of 20/04/09 - <ActivitySourceID>

It also includes the additional features introduced at the same time that allow easier reference of Venue data, and the ability to assign an activity to an organisation that is different to the data provider.

In the example below we assume you are telling us about both the Venue and the ActivityProvider for the first time.

<?xml version="1.0" encoding="UTF-8"?>
<Activities>
	<Activity>
	  <ActivitySourceID>dc2</ActivitySourceID>
		<Name>Artistic Dancing</Name>
		<Description>&lt;p&gt;Dance and paint at the same time!&amp;nbsp; a class environment, 
ensuring that the group grooves their way to a healthier and fitter lifestle while having plenty of fun.&lt;/p&gt;&lt;p&gt;Girls only
.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</Description>
                <Starts>2011-11-25 17:00:00</Starts>
		<Ends>2011-11-25 17:45:00</Ends>
 
		<Venue>
	          <ProviderVenueID>MyVenue5</ProviderVenueID>
		  <Name>The New Pool</Name>
		  <BuildingNameNo>The Local Swimming Pool2</BuildingNameNo>
		  <Postcode>SK7 5JW</Postcode>
		  <ContactForename>Bobb</ContactForename>
		  <ContactSurname>Hope</ContactSurname>
		  <ContactEmail>Pool@swim.com</ContactEmail>
		  <ContactPhone>01376 87543</ContactPhone>
		  <ContactFax>0123 567876</ContactFax>
		  <Description>A Swimming Pool</Description>
		  <Website>http://madeupURL</Website>
		  <ParkingSpaces>3</ParkingSpaces>
		  <CyclePark>Secure</CyclePark>
		  <DisabledFacilitiesNotes>2 steps up to the entrance</DisabledFacilitiesNotes>
		</Venue>
 
		<ActivityProvider>
                  <DPProviderID>MYID9879</DPProviderID>
                  <Name>Leisure Services 2</Name>
                  <ProjectDepartment>DanceArt Dept.</ProjectDepartment>
                  <BuildingNameNo>Dance HQ</BuildingNameNo>
                  <Street>Wet Street</Street>
                  <Town>Swim Town</Town>	
                  <PostTown>Leeds</PostTown>
                  <County>W.Yorks</County> 		
                  <Postcode/>
                  <ContactForename>Billy</ContactForename> 	
                  <ContactSurname>Fish</ContactSurname> 	
                  <ContactEmail/>
                  <ContactPhone>01234 56789</ContactPhone>
                  <ContactFax/> 		
                  <Description>We do lots of things around dancing for lots of people in lots of towns in the uk</Description>
                  <MinAge/>
                  <MaxAge/>
                  <Website/> 
                </ActivityProvider>
 
 
		<ContactName>General Enquiries</ContactName>
		<ContactNumber>0111 419 51221</ContactNumber>
		<ContactEmail>bob@email.com</ContactEmail>
		<MinAge>12</MinAge>
		<MaxAge>14</MaxAge>
		<Cost>2.00</Cost>
		<Categories>
			<Category>Music and Dance </Category>
			<Category>Art</Category>
		</Categories>
 
		<Keywords>
			<Keyword>Swim</Keyword>
		        <Keyword>Fitness</Keyword>
		</Keywords>
		<ECMCodes>
			<ECMCode>1</ECMCode>
			<ECMCode>3</ECMCode>
		</ECMCodes>
 
	</Activity>
</Activities>

Activity at existing Venue and Organisation

updated 20/04/09
If Plings already has data about the venue where the activity takes place, and/or the organisation delivering the activity, then sending your identifiers for those entities is enough:

<?xml version="1.0" encoding="UTF-8"?>
<Activities>
	<Activity>
	<ActivitySourceID>dc4</ActivitySourceID>
		<Name>Artistic Swimming</Name>
		<Description>&lt;p&gt;Swim and paint at the same time!&amp;nbsp; a class environment, 
ensuring that the group grooves their way to a healthier and fitter lifestle while having plenty of fun.&lt;/p&gt;&lt;p&gt;Girls only
.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</Description>
                <Starts>2011-12-26 17:00:00</Starts>
		<Ends>2011-12-26 17:45:00</Ends>
 
		<Venue>
			<ProviderVenueID>MyVenue1</ProviderVenueID>
		</Venue>
 
		<ActivityProvider>
                      <DPProviderID>XYZ987</DPProviderID>
                </ActivityProvider>
 
 
		<ContactName>General Enquiries</ContactName>
		<ContactNumber>0111 419 51221</ContactNumber>
		<ContactEmail>bob@email.com</ContactEmail>
	        <MinAge>12</MinAge>
		<MaxAge>14</MaxAge>
		<Cost>2.00</Cost>
		<Categories>
			<Category>Sport</Category>
		</Categories>
 
		<Keywords>
			<Keyword>Swim</Keyword>
		        <Keyword>Fitness</Keyword>
		</Keywords>
		<ECMCodes>
			<ECMCode>1</ECMCode>
			<ECMCode>3</ECMCode>
		</ECMCodes>
 
	</Activity>
</Activities>

Activity at existing Venue (Organisation not specified)

updated 20/04/09
There is no need to send 'organisation/ActivityProviderID' information. The activity will be assigned to the holder of the API key.

<?xml version="1.0" encoding="UTF-8"?>
<Activities>
	<Activity>
	<ActivitySourceID>dc5</ActivitySourceID>
		<Name>Artistic Swimming</Name>
		<Description>&lt;p&gt;Swim and paint at the same time!&amp;nbsp; a class environment, 
ensuring that the group grooves their way to a healthier and fitter lifestle while having plenty of fun.&lt;/p&gt;&lt;p&gt;Girls only
.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</Description>
                <Starts>2011-12-26 17:00:00</Starts>
		<Ends>2011-12-26 17:45:00</Ends>
 
		<Venue>
			<ProviderVenueID>MyVenue1</ProviderVenueID>
		</Venue>
 
		<ActivityProvider>
                      <DPProviderID>XYZ987</DPProviderID>
                </ActivityProvider>
 
 
		<ContactName>General Enquiries</ContactName>
		<ContactNumber>0111 419 51221</ContactNumber>
		<ContactEmail>bob@email.com</ContactEmail>
	        <MinAge>12</MinAge>
		<MaxAge>14</MaxAge>
		<Cost>2.00</Cost>
		<Categories>
			<Category>Sport</Category>
			<Category>Art</Category>
		</Categories>
 
		<Keywords>
			<Keyword>Swim</Keyword>
		        <Keyword>Fitness</Keyword>
		</Keywords>
		<ECMCodes>
			<ECMCode>1</ECMCode>
			<ECMCode>3</ECMCode>
		</ECMCodes>
 
	</Activity>
</Activities>

Grouped/Linked Activities

updated 20/04/09
In the examples above it would be possible to link/group those activities together. e.g. The activity is essentially the same week after week, e.g. Badminton every Tuesday 7pm-8:30pm for 6 weeks. We may want to group these together so that when we call them back later we can group them easily.

This is now much easier to do. Within the <Activity> tag:

<LinkWithActivitySourceID>dc2</LinkWithActivitySourceID>

Alternatively, if you know the unique PlingsActivityID (e.g.711432):

<LinkWithActivity>711432</LinkWithActivity>

Example Output

Successfully accepted the data

updated 20/04/09: Now also returns the data you supply: <ActivitySourceID>, <ProviderVenueID>, <DPProviderID>

<results>
    <result>
        <ErrorCount>0</ErrorCount>
        <ActivitySourceID>dc2</ActivitySourceID>
        <PlingsActivityID>52311</PlingsActivityID>
	<ProviderVenueID>MyVenue5</<ProviderVenueID>
        <PlingsVenueID>375</PlingsVenueID>
        <DPProviderID>MYID9879</DPProviderID>
        <PlingsActivityProviderID>350</PlingsActivityProviderID>
    </result>
</results>

Notes:

  1. Returned XML tells us that zero errors were encountered.
  2. The activity (that you reference as dc2) has been assigned a unique PlingsActivityID,
  3. The venue will EITHER match an existing venue in our data set, OR be created as a new venue in our data set. The unique PlingsVenueID we have assigned is returned (along with you're own identifier).
  4. The 'PlingsActivityProviderID' is linked to your API key. '1' is the developer key. However, if you have supplied a <DDProviderID> field then the <PlingsActivityProviderID> becomes a unique identifier in the plings dataset.

Old Examples

No value for VenueID

Sending data about an activity that takes place at a venue which is either:

  1. not already in the Plings data set, or
  2. is in the Plings data set, but you do not know the value of <VenueID> (Typically this is the case if it is the first time you have sent data about this venue.)

Special Instructions:

  1. Set the value of <VenueID> as '0' (i.e. zero)
  2. Provide data about the venue as well as the activity
<?xml version="1.0" encoding="UTF-8"?>
<Activities>
	<Activity>
		<Name>Team Jam</Name>
		<Description>&lt;p&gt;Dance based programme that has been designed using fresh choreography ideas tailored to teenagers.&amp;nbsp;
Instructors are trained to bring the excitement and energy of a nightclub dance floor into&amp;nbsp; a class environment, 
ensuring that the group grooves their way to a healthier and fitter lifestle while having plenty of fun.&lt;/p&gt;&lt;p&gt;Girls only
.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</Description>
                <Starts>2008-11-25 17:00:00</Starts>
		<Ends>2008-11-25 17:45:00</Ends>
		<MinAge>12</MinAge>
		<MaxAge>14</MaxAge>
		<Cost>2.00</Cost>
		<ContactName>General Enquiries</ContactName>
		<ContactNumber>0161 439 5221</ContactNumber>
		<ContactEmail>bob@stockport.gov.uk</ContactEmail>
		<VenueID>0</VenueID>
		<Categories>
			<Category>Music and Dance</Category>
			<Category>Sport</Category>
		</Categories>
		<ECMCodes>
			<ECMCode>1</ECMCode>
			<ECMCode>3</ECMCode>
		</ECMCodes>
		<Keywords>
			<Keyword>Dance</Keyword>
		        <Keyword>Fitness</Keyword>
		</Keywords>
		<Venue>
			<ProviderVenueID>123456</ProviderVenueID>
			<Name>Hazel Grove Pools and Target Fitness</Name>
			<BuildingNameNo>Hazel Grove Pool</BuildingNameNo>
			<Postcode>SK7 5JW</Postcode>
			<ContactForename>Bob</ContactForename>
			<ContactSurname>Hope</ContactSurname>
			<ContactEmail>Pool@swim.com</ContactEmail>
		        <ContactPhone>01976 987543</ContactPhone>
			<ContactFax>01924 567876</ContactFax>
			<GeoCoordSystem>WGS84DD</GeoCoordSystem>
			<GeoCoordX>53.371661</GeoCoordX>
			<GeoCoordY>-2.145762</GeoCoordY>
			<Description>A Swimming Pool</Description>
			<Website>http://places.plings.net/index.php/v/1958</Website>
			<ParkingSpaces>3</ParkingSpaces>
			<CyclePark>Secure</CyclePark>
			<DisabledFacilitiesNotes>2 steps up to the entrance</DisabledFacilitiesNotes>
		</Venue>
	</Activity>
</Activities>

With VenueID

The activity takes place at a venue with an existing VenueID value.

<?xml version="1.0" encoding="UTF-8"?>
<Activities>
    <Activity>
        <Name>Team Jam 2</Name>
        <Description>&lt;p&gt;Dance based programme that has been designed using fresh choreography ideas tailored to teenagers.&amp;nbsp; 
Instructors are trained to bring the excitement and energy of a nightclub dance floor into&amp;nbsp; a class environment, ensuring that the group 
grooves their way to a healthier and fitter lifestle while having plenty of fun.&lt;/p&gt;&lt;p&gt;Girls only.
&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</Description>
        <Starts>2008-11-25 17:00:00</Starts>
        <Ends>2008-11-25 17:45:00</Ends>
        <MinAge>12</MinAge>
        MaxAge>14</MaxAge>
        <Cost>2.00</Cost>
        <ContactName>General Enquiries</ContactName>
        <ContactNumber>0161 439 5221</ContactNumber>
        <ContactEmail>bob@stockport.gov.uk</ContactEmail>
        <VenueID>375</VenueID>
        <Categories>
            <Category>Music and Dance</Category>
            <Category>Sport</Category>
        </Categories>
 
        <ECMCodes>
            <ECMCode>1</ECMCode>
            <ECMCode>3</ECMCode>
        </ECMCodes>
 
        <Keywords>
            <Keyword>Dance</Keyword>
            <Keyword>Fitness</Keyword>
        </Keywords>
    </Activity>
</Activities>

Grouped Activities

e.g. The activity is essentially the same week after week, e.g. Badminton every Tuesday 7pm-8:30pm for 6 weeks. We may want to group these together so that when we call them back later we can group them easily. We do this using the Activity Source field.


There are 2 Scenarios.

1) An instance of the activity already exists.
In this case we can link our new activity directly to an existing one using the LinkWithActivity field – use an existing ActivityID

<?xml version="1.0" encoding="UTF-8"?>
<Activities>
    <Activity>
        <Name>Badminton</Name>
        <Description>Badminton – lots of fun</Description>
        <Starts>2008-11-25 19:00:00</Starts>
        <Ends>2008-11-25 20:30:00</Ends>
        <MinAge>13</MinAge>
        <MaxAge>19</MaxAge>
        <Cost>3.00</Cost>
        <ContactName>General Enquiries</ContactName>
        <ContactNumber>0161 439 5221</ContactNumber>
        <ContactEmail>badminton@stockport.gov.uk</ContactEmail>
        <VenueID>56748</VenueID>
        <Categories>
            <Category>Sport</Category>
        </Categories>
        <ECMCodes>
            <ECMCode>1</ECMCode>
        </ECMCodes>
        <Keywords>
            <Keyword>Badminton</Keyword>
            <Keyword>Sport</Keyword>
        </Keywords>
        <LinkWithActivity>51138</LinkWithActivity>
    </Activity>
</Activities>

2) You are creating this group of activities for the first time
First you need to provide your own unique reference for this group of activities and use that in the Activity Source field. Then using the LinkWithActivitySource field we can assign this particular activity to that group

<?xml version="1.0" encoding="UTF-8"?>
<Activities>
    <Activity>
        <Name>Badminton</Name>
        <Description>Badminton Club</Description>
        <Starts>2008-11-25 19:00:00</Starts>
        <Ends>2008-11-25 20:30:00</Ends>
        <MinAge>13</MinAge>
        <MaxAge>19</MaxAge>
        <Cost>3.00</Cost>
        <ContactName>General Enquiries</ContactName>
        <ContactNumber>0161 439 5221</ContactNumber>
        <ContactEmail>badminton@stockport.gov.uk</ContactEmail>
        <VenueID>56748</VenueID>
        <Categories>
            <Category>Sport</Category>
        </Categories>
        <ECMCodes>
            <ECMCode>1</ECMCode>
        </ECMCodes>
        <Keywords>
            <Keyword>Badminton</Keyword>
            <Keyword>Sport</Keyword>
        </Keywords>
        <ActivitySource>plings:a:51138</ActivitySource>
        <LinkWithActivitySource>plings:a:51138</LinkWithActivitySource>
    </Activity>
 
    <Activity>
        <Name>Badminton</Name>
        <Description>Badminton Club</Description>
        <Starts>2008-11-30 19:00:00</Starts>
        <Ends>2008-11-30 20:30:00</Ends>
        <MinAge>13</MinAge>
        <MaxAge>19</MaxAge>
        <Cost>3.00</Cost>
        <ContactName>General Enquiries</ContactName>
        <ContactNumber>0161 439 5221</ContactNumber>
        <ContactEmail>badminton@stockport.gov.uk</ContactEmail>
        <VenueID>56748</VenueID>
        <Categories>
            <Category>Sport</Category>
        </Categories>
        <ECMCodes>
            <ECMCode>1</ECMCode>
        </ECMCodes>
        <Keywords>
            <Keyword>Badminton</Keyword>
            <Keyword>Sport</Keyword>
        </Keywords>
        <ActivitySource>plings:a:51139</ActivitySource>
        <LinkWithActivitySource>plings:a:51138</LinkWithActivitySource>
    </Activity>
</Activities>

More Links

You might also like...

Personal tools