Source for file user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Openstreetmap
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die();
  11.  
  12. /**
  13.  * Openstreetmap API User class for the Joomla Platform
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Openstreetmap
  17.  * @since       13.1
  18. */
  19. {
  20.     /**
  21.      * Method to get user details
  22.      *
  23.      * @return  array  The XML response
  24.      *
  25.      * @since   13.1
  26.      */
  27.     public function getDetails()
  28.     {
  29.         $token $this->oauth->getToken();
  30.  
  31.         // Set parameters.
  32.         $parameters array(
  33.             'oauth_token' => $token['key']
  34.         );
  35.  
  36.         // Set the API base
  37.         $base 'user/details';
  38.  
  39.         // Build the request path.
  40.         $path $this->getOption('api.url'$base;
  41.  
  42.         // Send the request.
  43.         $response $this->oauth->oauthRequest($path'GET'$parameters);
  44.  
  45.         return $response->body;
  46.     }
  47.  
  48.     /**
  49.      * Method to get preferences
  50.      *
  51.      * @return  array  The XML response
  52.      *
  53.      * @since   13.1
  54.      */
  55.     public function getPreferences()
  56.     {
  57.         $token $this->oauth->getToken();
  58.  
  59.         // Set parameters.
  60.         $parameters array(
  61.             'oauth_token' => $token['key']
  62.         );
  63.  
  64.         // Set the API base
  65.         $base 'user/preferences';
  66.  
  67.         // Build the request path.
  68.         $path $this->getOption('api.url'$base;
  69.  
  70.         // Send the request.
  71.         $response $this->oauth->oauthRequest($path'GET'$parameters);
  72.  
  73.         return $response->body;
  74.     }
  75.  
  76.     /**
  77.      * Method to replace user preferences
  78.      *
  79.      * @param   array  $preferences  Array of new preferences
  80.      *
  81.      * @return  array  The XML response
  82.      *
  83.      * @since   13.1
  84.      */
  85.     public function replacePreferences($preferences)
  86.     {
  87.         $token $this->oauth->getToken();
  88.  
  89.         // Set parameters.
  90.         $parameters array(
  91.             'oauth_token' => $token['key']
  92.         );
  93.  
  94.         // Set the API base
  95.         $base 'user/preferences';
  96.  
  97.         // Build the request path.
  98.         $path $this->getOption('api.url'$base;
  99.  
  100.         // Create a list of preferences
  101.         $preference_list '';
  102.  
  103.         if (!empty($preferences))
  104.         {
  105.             foreach ($preferences as $key => $value)
  106.             {
  107.                 $preference_list .= '<preference k="' $key '" v="' $value '"/>';
  108.             }
  109.         }
  110.  
  111.         $xml '<?xml version="1.0" encoding="UTF-8"?>
  112.             <osm version="0.6" generator="JOpenstreetmap">
  113.                 <preferences>'
  114.                 . $preference_list .
  115.                 '</preferences>
  116.             </osm>';
  117.  
  118.         $header['Content-Type''text/xml';
  119.  
  120.         // Send the request.
  121.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  122.  
  123.         return $response->body;
  124.     }
  125.  
  126.     /**
  127.      * Method to change user preferences
  128.      *
  129.      * @param   string  $key         Key of the preference
  130.      * @param   string  $preference  New value for preference
  131.      *
  132.      * @return  array  The XML response
  133.      *
  134.      * @since   13.1
  135.      */
  136.     public function changePreference($key$preference)
  137.     {
  138.         $token $this->oauth->getToken();
  139.  
  140.         // Set parameters.
  141.         $parameters array(
  142.             'oauth_token' => $token['key']
  143.         );
  144.  
  145.         // Set the API base
  146.         $base 'user/preferences/' $key;
  147.  
  148.         // Build the request path.
  149.         $path $this->getOption('api.url'$base;
  150.  
  151.         // Send the request.
  152.         $response $this->oauth->oauthRequest($path'PUT'$parameters$preference);
  153.  
  154.         return $response->body;
  155.     }
  156. }

Documentation generated on Tue, 19 Nov 2013 15:16:20 +0100 by phpDocumentor 1.4.3