Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JOpenstreetmap package with tests added

  • Loading branch information...
commit 79c63e0a1ac703feb74018066b7818f22d738c1a 1 parent 8477998
@Buddhima Buddhima authored buddhima committed
View
330 libraries/joomla/openstreetmap/changesets.php
@@ -0,0 +1,330 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Openstreetmap API Changesets class for the Joomla Platform
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+class JOpenstreetmapChangesets extends JOpenstreetmapObject
+{
+ /**
+ * Method to create a changeset
+ *
+ * @param array $changesets array which contains changeset data
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function createChangeset($changesets=array())
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key'],
+ 'oauth_token_secret' => $token['secret']
+ );
+
+ // Set the API base
+ $base = 'changeset/create';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">';
+
+ if (!empty($changesets))
+ {
+ // Create Changeset element for every changeset
+ foreach ($changesets as $tags)
+ {
+ $xml .= '<changeset>';
+ $tag_list = '';
+
+ if (!empty($tags))
+ {
+ // Create a list of tags for each changeset
+ foreach ($tags as $key => $value)
+ {
+
+ $xml .= '<tag k="' . $key . '" v="' . $value . '"/>';
+
+ }
+ }
+ $xml .= '</changeset>';
+ }
+ }
+
+ $xml .= '</osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ return $response->body;
+
+ }
+
+ /**
+ * Method to read a changeset
+ *
+ * @param int $id identifier of the changeset
+ *
+ * @return array The xml response about a changeset
+ *
+ * @since 12.3
+ */
+ public function readChangeset($id)
+ {
+
+ // Set the API base
+ $base = 'changeset/' . $id;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->changeset;
+
+ }
+
+ /**
+ * Method to update a changeset
+ *
+ * @param int $id identifier of the changeset
+ * @param array $tags array of tags to update
+ *
+ * @return array The xml response of updated changeset
+ *
+ * @since 12.3
+ */
+ public function updateChangeset($id, $tags=array() )
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'changeset/' . $id;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Create a list of tags to update changeset
+ $tag_list = '';
+
+ if (!empty($tags))
+ {
+ foreach ($tags as $key => $value)
+ {
+
+ $tag_list .= '<tag k="' . $key . '" v="' . $value . '"/>';
+
+ }
+ }
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <changeset>'
+ . $tag_list .
+ '</changeset>
+ </osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string->changeset;
+ }
+
+ /**
+ * Method to close a changeset
+ *
+ * @param int $id identifier of the changeset
+ *
+ * @return No value returns
+ *
+ * @since 12.3
+ */
+ public function closeChangeset($id)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'changeset/' . $id . '/close';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $header['format'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $header);
+
+ }
+
+ /**
+ * Method to download a changeset
+ *
+ * @param int $id identifier of the changeset
+ *
+ * @return array The xml response of requested changeset
+ *
+ * @since 12.3
+ */
+ public function downloadChangeset($id)
+ {
+
+ // Set the API base
+ $base = 'changeset/' . $id . '/download';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->create;
+ }
+
+ /**
+ * Method to expand the bounding box of a changeset
+ *
+ * @param int $id identifier of the changeset
+ * @param array $nodes list of lat lon about nodes
+ *
+ * @return array The xml response of changed changeset
+ *
+ * @since 12.3
+ */
+ public function expandBBoxChangeset($id, $nodes)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'changeset/' . $id . '/expand_bbox';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Create a list of tags to update changeset
+ $node_list = '';
+
+ if (!empty($nodes))
+ {
+ foreach ($nodes as $node)
+ {
+
+ $node_list .= '<node lat="' . $node[0] . '" lon="' . $node[1] . '"/>';
+
+ }
+ }
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <changeset>'
+ . $node_list .
+ '</changeset>
+ </osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string->changeset;
+ }
+
+ /**
+ * Method to Query on changesets
+ *
+ * @param string $param parameters for query
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function queryChangeset($param)
+ {
+ // Set the API base
+ $base = 'changesets/' . $param;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->osm;
+ }
+
+ /**
+ * Method to upload a diff to a changeset
+ *
+ * @param string $xml diff data to upload
+ * @param int $id identifier of the changeset
+ *
+ * @return array The xml response of result
+ *
+ * @since 12.3
+ */
+ public function diffUploadChangeset($xml, $id)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'changeset/' . $id . '/upload';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string->diffResult;
+ }
+}
View
551 libraries/joomla/openstreetmap/elements.php
@@ -0,0 +1,551 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Openstreetmap API Elements class for the Joomla Platform
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+class JOpenstreetmapElements extends JOpenstreetmapObject
+{
+ /**
+ * Method to create a node
+ *
+ * @param int $changeset change set id
+ * @param float $latitude latitude of the node
+ * @param float $longitude longitude of the node
+ * @param arary $tags array of tags for a node
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function createNode($changeset,$latitude,$longitude,$tags)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'node/create';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $tag_list = "";
+
+ // Create XML node
+ if (!empty($tags))
+ {
+ foreach ($tags as $key => $value)
+ {
+ $tag_list .= '<tag k="' . $key . '" v="' . $value . '"/>';
+ }
+ }
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <node changeset="' . $changeset . '" lat="' . $latitude . '" lon="' . $longitude . '">'
+ . $tag_list .
+ '</node>
+ </osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to create a way
+ *
+ * @param int $changeset change set id
+ * @param array $tags array of tags for a way
+ * @param array $nds node ids to refer
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function createWay($changeset,$tags,$nds)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'way/create';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $tag_list = "";
+
+ // Create XML node
+ if (!empty($tags))
+ {
+ foreach ($tags as $key => $value)
+ {
+ $tag_list .= '<tag k="' . $key . '" v="' . $value . '"/>';
+ }
+ }
+
+ $nd_list = "";
+
+ if (!empty($nds))
+ {
+ foreach ($nds as $value)
+ {
+ $nd_list .= '<nd ref="' . $value . '"/>';
+ }
+ }
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <way changeset="' . $changeset . '">'
+ . $tag_list
+ . $nd_list .
+ '</way>
+ </osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to create a relation
+ *
+ * @param int $changeset change set id
+ * @param array $tags array of tags for a relation
+ * @param array $members array of members for a relation
+ * eg:$members=array(array("type"=>"node","role"=>"stop","ref"=>"123"),array("type"=>"way","ref"=>"123"))
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function createRelation($changeset,$tags,$members)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'relation/create';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $tag_list = "";
+
+ // Create XML node
+ if (!empty($tags))
+ {
+ foreach ($tags as $key => $value)
+ {
+ $tag_list .= '<tag k="' . $key . '" v="' . $value . '"/>';
+ }
+ }
+
+ // Members
+ $member_list = "";
+
+ if (!empty($members))
+ {
+ foreach ($members as $member)
+ {
+ if ($member['type'] == "node")
+ {
+ $member_list .= '<member type="' . $member['type'] . '" role="' . $member['role'] . '" ref="' . $member['ref'] . '"/>';
+ }
+ elseif ($member['type'] == "way")
+ {
+ $member_list .= '<member type="' . $member['type'] . '" ref="' . $member['ref'] . '"/>';
+ }
+ }
+ }
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <relation relation="' . $changeset . '" >'
+ . $tag_list
+ . $member_list .
+ '</relation>
+ </osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to read an Element [node|way|relation]
+ *
+ * @param string $element [node|way|relation]
+ * @param int $id element identifier
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function readElement($element, $id)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ // Set the API base
+ $base = $element . '/' . $id;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->$element;
+ }
+
+ /**
+ * Method to update an Element [node|way|relation]
+ *
+ * @param string $element [node|way|relation]
+ * @param string $xml full reperentation of the element with a version number
+ * @param int $id element identifier
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function updateElement($element, $xml, $id)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = $element . '/' . $id;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to delete an element [node|way|relation]
+ *
+ * @param string $element [node|way|relation]
+ * @param int $id element identifier
+ * @param int $version element versioln
+ * @param int $changeset changeset identifier
+ * @param float $latitude latitude of the element
+ * @param float $longitude longitude of the element
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function deleteElement($element, $id, $version, $changeset, $latitude=null, $longitude=null)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = $element . '/' . $id;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Create xml
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <' . $element . ' id="' . $id . '" version="' . $version . '" changeset="' . $changeset . '"';
+
+ if (!empty($latitude) && !empty($longitude))
+ {
+ $xml .= ' lat="' . $latitude . '" lon="' . $longitude . '"';
+ }
+ $xml .= '/></osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'DELETE', $parameters, $xml, $header);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to get history of an element [node|way|relation]
+ *
+ * @param string $element [node|way|relation]
+ * @param int $id element identifier
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function historyOfElement($element, $id)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ // Set the API base
+ $base = $element . '/' . $id . '/history';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->$element;
+ }
+
+ /**
+ * Method to get details about a version of an element [node|way|relation]
+ *
+ * @param string $element [node|way|relation]
+ * @param int $id element identifier
+ * @param int $version element version
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function versionOfElement($element, $id ,$version)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ // Set the API base
+ $base = $element . '/' . $id . '/' . $version;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->$element;
+ }
+
+ /**
+ * Method to get data about multiple ids of an element [node|way|relation]
+ *
+ * @param string $element [nodes|ways|relations] - use plural word
+ * @param string $params Comma separated list ids belongto type $element
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function multiFetchElements($element, $params)
+ {
+ if ($element != 'nodes' && $element != 'ways' && $element != 'relations')
+ {
+ throw new DomainException("Element should be nodes, ways or relations");
+ }
+
+ // Get singular word
+ $single_element = substr($element, 0, strlen($element) - 1);
+
+ // Set the API base, $params is a string with comma seperated values
+ $base = $element . '?' . $element . "=" . $params;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->$single_element;
+ }
+
+ /**
+ * Method to get relations for an Element [node|way|relation]
+ *
+ * @param string $element [node|way|relation]
+ * @param int $id element identifier
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function relationsForElement($element, $id)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ // Set the API base
+ $base = $element . '/' . $id . '/relations';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->$element;
+ }
+
+ /**
+ * Method to get ways for a Node element
+ *
+ * @param int $id node identifier
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function waysForNode($id)
+ {
+ // Set the API base
+ $base = 'node/' . $id . '/ways';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->way;
+ }
+
+ /**
+ * Method to get full information about an element [way|relation]
+ *
+ * @param string $element [way|relation]
+ * @param int $id identifier
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function fullElement($element, $id)
+ {
+ if ($element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a way or a relation");
+ }
+
+ // Set the API base
+ $base = $element . '/' . $id . '/full';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path);
+
+ return $xml_string->node;
+ }
+
+ /**
+ * Method used by the DWG to hide old versions of elements containing data privacy or copyright infringements
+ *
+ * @param string $element [node|way|relation]
+ * @param int $id element identifier
+ * @param int $version element version
+ * @param int $redaction_id redaction id
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function redaction($element, $id, $version, $redaction_id)
+ {
+ if ($element != 'node' && $element != 'way' && $element != 'relation')
+ {
+ throw new DomainException("Element should be a node, a way or a relation");
+ }
+
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = $element . '/' . $id . '/' . $version . '/redact?redaction=' . $redaction_id;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters);
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string;
+ }
+}
View
145 libraries/joomla/openstreetmap/gps.php
@@ -0,0 +1,145 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Openstreetmap API Gps class for the Joomla Platform
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+class JOpenstreetmapGps extends JOpenstreetmapObject
+{
+ /**
+ * Method to retrieve GPS points
+ *
+ * @param float $left left boundary
+ * @param float $bottom bottom boundary
+ * @param float $right right boundary
+ * @param float $top top boundary
+ * @param int $page page number
+ *
+ * @return array The xml response containing GPS points
+ *
+ * @since 12.3
+ */
+ public function retrieveGps($left,$bottom,$right,$top,$page=0)
+ {
+ // Set the API base
+ $base = 'trackpoints?bbox=' . $left . ',' . $bottom . ',' . $right . ',' . $top . '&page=' . $page;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'GET', array());
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string;
+ }
+
+ /**
+ * Method to upload GPS Traces
+ *
+ * @param string $file file name that contains trace points
+ * @param string $description description on trace points
+ * @param string $tags tags for trace
+ * @param int $public 1 for public, 0 for private
+ * @param string $visibility One of the following: private, public, trackable, identifiable
+ * @param string $username username
+ * @param string $password password
+ *
+ * @return JHttpResponse the response
+ *
+ * @since 12.3
+ */
+ public function uploadTrace($file, $description, $tags, $public, $visibility, $username, $password)
+ {
+ // Set parameters.
+ $parameters = array(
+ 'file' => $file,
+ 'description' => $description,
+ 'tags' => $tags,
+ 'public' => $public,
+ 'visibility' => $visibility
+ );
+
+ // Set the API base
+ $base = 'gpx/create';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $header['Content-Type'] = 'multipart/form-data';
+
+ $header = array_merge($header, $parameters);
+ $header = array_merge($header, array('Authorization' => 'Basic ' . base64_encode($username . ':' . $password)));
+
+ // Send the request.
+ $response = $this->sendRequest($path, 'POST', $header, array());
+
+ return $response;
+ }
+
+ /**
+ * Method to download Trace details
+ *
+ * @param int $id trace identifier
+ * @param string $username username
+ * @param string $password password
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function downloadTraceMetadetails($id, $username, $password)
+ {
+ // Set the API base
+ $base = 'gpx/' . $id . '/details';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path, 'GET', array('Authorization' => 'Basic ' . base64_encode($username . ':' . $password)));
+
+ return $xml_string;
+ }
+
+ /**
+ * Method to download Trace data
+ *
+ * @param int $id trace identifier
+ * @param string $username username
+ * @param string $password password
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function downloadTraceMetadata($id, $username, $password)
+ {
+ // Set the API base
+ $base = 'gpx/' . $id . '/data';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ $client = JHttpFactory::getHttp();
+
+ // Send the request.
+ $xml_string = $this->sendRequest($path, 'GET', array('Authorization' => 'Basic ' . base64_encode($username . ':' . $password)));
+
+ return $xml_string;
+ }
+}
View
100 libraries/joomla/openstreetmap/info.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Openstreetmap API Info class for the Joomla Platform
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+*/
+class JOpenstreetmapInfo extends JOpenstreetmapObject
+{
+ /**
+ * Method to get capabilities of the API
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function getCapabilities()
+ {
+ // Set the API base
+ $base = 'capabilities';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'GET', array());
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string;
+ }
+
+ /**
+ * Method to retrieve map data of a bounding box
+ *
+ * @param float $left left boundary
+ * @param float $bottom bottom boundary
+ * @param float $right right boundary
+ * @param float $top top boundary
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function retrieveMapData($left, $bottom, $right, $top)
+ {
+ // Set the API base
+ $base = 'map?bbox=' . $left . ',' . $bottom . ',' . $right . ',' . $top;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'GET', array());
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string;
+ }
+
+ /**
+ * Method to retrieve permissions for current user
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function retrievePermissions()
+ {
+ if ($this->oauth != null)
+ {
+ $token = $this->oauth->getToken();
+ }
+
+ // Set the API base
+ $base = 'permissions';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'GET', array());
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string;
+ }
+}
View
87 libraries/joomla/openstreetmap/oauth.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Joomla Platform class for generating Openstreetmap API access token.
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+class JOpenstreetmapOauth extends JOAuth1Client
+{
+ /**
+ * @var JRegistry Options for the JOpenstreetmapOauth object.
+ * @since 12.3
+ */
+ protected $options;
+
+ /**
+ * Constructor.
+ *
+ * @param JRegistry $options JOpenstreetmapOauth options object.
+ * @param JHttp $client The HTTP client object.
+ * @param JInput $input The input object
+ *
+ * @since 12.3
+ */
+ public function __construct(JRegistry $options = null, JHttp $client = null, JInput $input = null)
+ {
+ $this->options = isset($options) ? $options : new JRegistry;
+
+ $this->options->def('accessTokenURL', 'http://www.openstreetmap.org/oauth/access_token');
+ $this->options->def('authoriseURL', 'http://www.openstreetmap.org/oauth/authorize');
+ $this->options->def('requestTokenURL', 'http://www.openstreetmap.org/oauth/request_token');
+
+ /*
+ $this->options->def('accessTokenURL', 'http://api06.dev.openstreetmap.org/oauth/access_token');
+ $this->options->def('authoriseURL', 'http://api06.dev.openstreetmap.org/oauth/authorize');
+ $this->options->def('requestTokenURL', 'http://api06.dev.openstreetmap.org/oauth/request_token');
+ */
+
+ // Call the JOauth1Client constructor to setup the object.
+ parent::__construct('1.0', $this->options, $client, $input);
+ }
+
+ /**
+ * Method to verify if the access token is valid by making a request to an API endpoint.
+ *
+ * @return boolean Returns true if the access token is valid and false otherwise.
+ *
+ * @since 12.3
+ */
+ public function verifyCredentials()
+ {
+ return true;
+ }
+
+ /**
+ * Method to validate a response.
+ *
+ * @param string $url The request URL.
+ * @param JHttpResponse $response The response to validate.
+ *
+ * @return void
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function validateResponse($url, $response)
+ {
+ if ($response->code != 200)
+ {
+ $error = htmlspecialchars($response->body);
+
+ throw new DomainException($error, $response->code);
+ }
+ }
+}
View
127 libraries/joomla/openstreetmap/object.php
@@ -0,0 +1,127 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Openstreetmap API object class for the Joomla Platform
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+
+abstract class JOpenstreetmapObject
+{
+
+ /**
+ * @var JRegistry Options for the Openstreetmap object.
+ * @since 12.3
+ */
+ protected $options;
+
+ /**
+ * @var JHttp The HTTP client object to use in sending HTTP requests.
+ * @since 12.3
+ */
+ protected $client;
+
+ /**
+ * @var JOpenstreetmapOauth The OAuth client.
+ * @since 12.3
+ */
+ protected $oauth;
+
+ /**
+ * Constructor.
+ *
+ * @param JRegistry &$options Openstreetmap options object.
+ * @param JHttp $client The HTTP client object.
+ * @param JOpenstreetmapOauth $oauth Openstreetmap oauth client
+ *
+ * @since 12.3
+ */
+ public function __construct(JRegistry &$options = null, JHttp $client = null, JOpenstreetmapOauth $oauth = null)
+ {
+ $this->options = isset($options) ? $options : new JRegistry;
+ $this->client = isset($client) ? $client : new JHttp($this->options);
+ $this->oauth = $oauth;
+ }
+
+ /**
+ * Get an option from the JOpenstreetmapObject instance.
+ *
+ * @param string $key The name of the option to get.
+ *
+ * @return mixed The option value.
+ *
+ * @since 12.3
+ */
+ public function getOption($key)
+ {
+ return $this->options->get($key);
+ }
+
+ /**
+ * Set an option for the JOpenstreetmapObject instance.
+ *
+ * @param string $key The name of the option to set.
+ * @param mixed $value The option value to set.
+ *
+ * @return JOpenstreetmapObject This object for method chaining.
+ *
+ * @since 12.3
+ */
+ public function setOption($key, $value)
+ {
+ $this->options->set($key, $value);
+
+ return $this;
+ }
+
+ /**
+ * Method to send the request which does not require authentication.
+ *
+ * @param string $path The path of the request to make
+ * @param string $method The request method.
+ * @param array $headers The headers passed in the request.
+ * @param mixed $data Either an associative array or a string to be sent with the post request.
+ *
+ * @return SimpleXMLElement The XML response
+ *
+ * @since 12.3
+ * @throws DomainException
+ */
+ public function sendRequest($path, $method='GET', $headers = array(), $data='')
+ {
+ // Send the request.
+ switch ($method)
+ {
+ case 'GET':
+ $response = $this->client->get($path, $headers);
+ break;
+ case 'POST':
+ $response = $this->client->post($path, $data, $headers);
+ break;
+ }
+
+ // Validate the response code.
+ if ($response->code != 200)
+ {
+ $error = htmlspecialchars($response->body);
+
+ throw new DomainException($error, $response->code);
+ }
+
+ $xml_string = simplexml_load_string($response->body);
+
+ return $xml_string;
+ }
+}
View
171 libraries/joomla/openstreetmap/openstreetmap.php
@@ -0,0 +1,171 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Joomla Platform class for interact with Openstreetmap API.
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+class JOpenstreetmap
+{
+ /**
+ * @var JRegistry Options for the Openstreetmap object.
+ * @since 12.3
+ */
+ protected $options;
+
+ /**
+ * @var JHttp The HTTP client object to use in sending HTTP requests.
+ * @since 12.3
+ */
+ protected $client;
+
+ /**
+ * @var JOpenstreetmapOauth The OAuth client.
+ * @since 12.3
+ */
+ protected $oauth;
+
+ /**
+ * @var JOpenstreetmapChangesets Openstreetmap API object for changesets.
+ * @since 12.3
+ */
+ protected $changesets;
+
+ /**
+ * @var JOpenstreetmapElements Openstreetmap API object for elements.
+ * @since 12.3
+ */
+ protected $elements;
+
+ /**
+ * @var JOpenstreetmapGps Openstreetmap API object for gps.
+ * @since 12.3
+ */
+ protected $gps;
+
+ /**
+ * @var JOpenstreetmapInfo Openstreetmap API object for info.
+ * @since 12.3
+ */
+ protected $info;
+
+ /**
+ * @var JOpenstreetmapUser Openstreetmap API object for user.
+ * @since 12.3
+ */
+ protected $user;
+
+ /**
+ * Constructor.
+ *
+ * @param JOpenstreetmapOauth $oauth Openstreetmap oauth client.
+ * @param JRegistry $options Openstreetmap options object.
+ * @param JOpenstreetmapHttp $client The HTTP client object.
+ *
+ * @since 12.3
+ */
+ public function __construct(JOpenstreetmapOauth $oauth = null, JRegistry $options = null, JHttp $client = null)
+ {
+ $this->oauth = $oauth;
+ $this->options = isset($options) ? $options : new JRegistry;
+ $this->client = isset($client) ? $client : new JHttp($this->options);
+
+ // Setup the default API url if not already set.
+ $this->options->def('api.url', 'http://api.openstreetmap.org/api/0.6/');
+
+ // $this->options->def('api.url', 'http://api06.dev.openstreetmap.org/api/0.6/');
+ }
+
+ /**
+ * Method to get object instances
+ *
+ * @param string $name Name of property to retrieve
+ *
+ * @return JOpenstreetmapObject Openstreetmap API object .
+ *
+ * @since 12.3
+ */
+ public function __get($name)
+ {
+ switch ($name)
+ {
+ case 'changesets':
+ if ($this->changesets == null)
+ {
+ $this->changesets = new JOpenstreetmapChangesets($this->options, $this->client, $this->oauth);
+ }
+ return $this->changesets;
+
+ case 'elements':
+ if ($this->elements == null)
+ {
+ $this->elements = new JOpenstreetmapElements($this->options, $this->client, $this->oauth);
+ }
+ return $this->elements;
+
+ case 'gps':
+ if ($this->gps == null)
+ {
+ $this->gps = new JOpenstreetmapGps($this->options, $this->client, $this->oauth);
+ }
+ return $this->gps;
+
+ case 'info':
+ if ($this->info == null)
+ {
+ $this->info = new JOpenstreetmapInfo($this->options, $this->client, $this->oauth);
+ }
+ return $this->info;
+
+ case 'user':
+ if ($this->user == null)
+ {
+ $this->user = new JOpenstreetmapUser($this->options, $this->client, $this->oauth);
+ }
+ return $this->user;
+ }
+ }
+
+ /**
+ * Get an option from the JOpenstreetmap instance.
+ *
+ * @param string $key The name of the option to get.
+ *
+ * @return mixed The option value.
+ *
+ * @since 12.3
+ */
+ public function getOption($key)
+ {
+ return $this->options->get($key);
+ }
+
+ /**
+ * Set an option for the Openstreetmap instance.
+ *
+ * @param string $key The name of the option to set.
+ * @param mixed $value The option value to set.
+ *
+ * @return JOpenstreetmap This object for method chaining.
+ *
+ * @since 12.3
+ */
+ public function setOption($key, $value)
+ {
+ $this->options->set($key, $value);
+
+ return $this;
+ }
+}
View
158 libraries/joomla/openstreetmap/user.php
@@ -0,0 +1,158 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Openstreetmap API User class for the Joomla Platform
+ *
+ * @package Joomla.Platform
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+*/
+class JOpenstreetmapUser extends JOpenstreetmapObject
+{
+ /**
+ * Method to get user details
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function getDetails()
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'user/details';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'GET', $parameters);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to get preferences
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function getPreferences()
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'user/preferences';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'GET', $parameters);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to replace user preferences
+ *
+ * @param array $preferences array of new preferences
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function replacePreferences($preferences)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'user/preferences';
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Create a list of preferences
+ $preference_list = '';
+
+ if (!empty($preferences))
+ {
+ foreach ($preferences as $key => $value)
+ {
+ $preference_list .= '<preference k="' . $key . '" v="' . $value . '"/>';
+ }
+ }
+
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <osm version="0.6" generator="JOpenstreetmap">
+ <preferences>'
+ . $preference_list .
+ '</preferences>
+ </osm>';
+
+ $header['Content-Type'] = 'text/xml';
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
+
+ return $response->body;
+ }
+
+ /**
+ * Method to change user preferences
+ *
+ * @param string $key key of the preference
+ * @param string $preference new value for preference
+ *
+ * @return array The xml response
+ *
+ * @since 12.3
+ */
+ public function changePreference($key, $preference)
+ {
+ $token = $this->oauth->getToken();
+
+ // Set parameters.
+ $parameters = array(
+ 'oauth_token' => $token['key']
+ );
+
+ // Set the API base
+ $base = 'user/preferences/' . $key;
+
+ // Build the request path.
+ $path = $this->getOption('api.url') . $base;
+
+ // Send the request.
+ $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $preference);
+
+ return $response->body;
+ }
+}
View
587 tests/suites/unit/joomla/openstreetmap/JOpenstreetmapChangesetsTest.php
@@ -0,0 +1,587 @@
+<?php
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Openstreetmap
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+/**
+ * Test class for JOpenstreetmapChangesets.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Openstreetmap
+ *
+ * @since 12.3
+ */
+class JOpenstreetmapChangesetsTest extends TestCase
+{
+ /**
+ * @var JRegistry Options for the Openstreetmap object.
+ * @since 12.3
+ */
+ protected $options;
+
+ /**
+ * @var JHttp Mock client object.
+ * @since 12.3
+ */
+ protected $client;
+
+ /**
+ * @var JInput The input object to use in retrieving GET/POST data.
+ * @since 12.3
+ */
+ protected $input;
+
+ /**
+ * @var JOpenstreetmapChangesets Object under test.
+ * @since 12.3
+ */
+ protected $object;
+
+ /**
+ * @var JOpenstreetmapOauth Authentication object for the Openstreetmap object.
+ * @since 12.3
+ */
+ protected $oauth;
+
+ /**
+ * @var string Sample XML.
+ * @since 12.3
+ */
+ protected $sampleXml = <<<XML
+<?xml version='1.0'?>
+<osm></osm>
+XML;
+
+ /**
+ * @var string Sample XML error message.
+ * @since 12.3
+ */
+ protected $errorString = <<<XML
+<?xml version='1.0'?>
+<osm>ERROR</osm>
+XML;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ *
+ * @access protected
+ *
+ * @return void
+ */
+ protected function setUp()
+ {
+ $_SERVER['HTTP_HOST'] = 'example.com';
+ $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0';
+ $_SERVER['REQUEST_URI'] = '/index.php';
+ $_SERVER['SCRIPT_NAME'] = '/index.php';
+
+ $key = "app_key";
+ $secret = "app_secret";
+
+ $access_token = array('key' => 'token_key', 'secret' => 'token_secret');
+
+ $this->options = new JRegistry;
+ $this->input = new JInput;
+ $this->client = $this->getMock('JHttp', array('get', 'post', 'delete', 'put'));
+ $this->oauth = new JOpenstreetmapOauth($this->options, $this->client, $this->input);
+ $this->oauth->setToken($access_token);
+
+ $this->object = new JOpenstreetmapChangesets($this->options, $this->client, $this->oauth);
+
+ $this->options->set('consumer_key', $key);
+ $this->options->set('consumer_secret', $secret);
+ $this->options->set('sendheaders', true);
+ }
+
+ /**
+ * Tests the createChangeset method
+ *
+ * @return array
+ *
+ * @since 12.3
+ */
+ public function testCreateChangeset()
+ {
+ $changeset = array
+ (
+ array
+ (
+ "comment" => "my changeset comment",
+ "created_by" => "Josm"
+ ),
+ array
+ (
+ "A" => "a",
+ "B" => "b"
+ )
+ );
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+
+ // $path = 'http://api.openstreetmap.org/api/0.6/changeset/create';
+ $path = 'changeset/create';
+
+ $this->client->expects($this->once())
+ ->method('put')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->createChangeset($changeset),
+ $this->equalTo($this->sampleXml)
+ );
+ }
+
+ /**
+ * Tests the createChangeset method - failure
+ *
+ * @return void
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testCreateChangesetFailure()
+ {
+ $changeset = array
+ (
+ array
+ (
+ "comment" => "my changeset comment",
+ "created_by" => "JOsm"
+ ),
+ array
+ (
+ "A" => "a",
+ "B" => "b"
+ )
+ );
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+
+ $path = 'changeset/create';
+
+ $this->client->expects($this->once())
+ ->method('put')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->createChangeset($changeset);
+ }
+
+ /**
+ * Tests the readChangeset method
+ *
+ * @return void
+ *
+ * @since 12.3
+ */
+ public function testReadChangeset()
+ {
+ $id = '14153708';
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+ $returnData->changeset = new SimpleXMLElement($this->sampleXml);
+
+ $path = 'changeset/' . $id;
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->readChangeset($id),
+ $this->equalTo(new SimpleXMLElement($this->sampleXml))
+ );
+ }
+
+ /**
+ * Tests the readChangeset method - failure
+ *
+ * @return void
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testReadChangesetFailure()
+ {
+ $id = '14153708';
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+ $returnData->changeset = new SimpleXMLElement($this->sampleXml);
+
+ $path = 'changeset/' . $id;
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->readChangeset($id);
+ }
+
+ /**
+ * Tests the updateChangeset method
+ *
+ * @return array
+ *
+ * @since 12.3
+ */
+ public function testUpdateChangeset()
+ {
+ $id = '14153708';
+ $tags = array
+ (
+ "comment" => "my changeset comment",
+ "created_by" => "JOsm (en)"
+ );
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+
+ $path = 'changeset/' . $id;
+
+ $this->client->expects($this->once())
+ ->method('put')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->updateChangeset($id, $tags),
+ $this->equalTo(new SimpleXMLElement($this->sampleXml))
+ );
+ }
+
+ /**
+ * Tests the updateChangeset method - failure
+ *
+ * @return array
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testUpdateChangesetFailure()
+ {
+ $id = '14153708';
+ $tags = array
+ (
+ "comment" => "my changeset comment",
+ "created_by" => "JOsm (en)"
+ );
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+
+ $path = 'changeset/' . $id;
+
+ $this->client->expects($this->once())
+ ->method('put')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->updateChangeset($id, $tags);
+ }
+
+ /**
+ * Tests the closeChangeset method
+ *
+ * @return array
+ *
+ * @since 12.3
+ */
+ public function testCloseChangeset()
+ {
+ $id = '14153708';
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+
+ $path = 'changeset/' . $id . '/close';
+
+ $this->client->expects($this->once())
+ ->method('put')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertNull($this->object->closeChangeset($id));
+ }
+
+ /**
+ * Tests the closeChangeset method - failure
+ *
+ * @return array
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testCloseChangesetFailure()
+ {
+ $id = '14153708';
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+
+ $path = 'changeset/' . $id . '/close';
+
+ $this->client->expects($this->once())
+ ->method('put')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->closeChangeset($id);
+ }
+
+ /**
+ * Tests the downloadChangeset method
+ *
+ * @return void
+ *
+ * @since 12.3
+ */
+ public function testDownloadChangeset()
+ {
+ $id = '123';
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+ $returnData->create = new SimpleXMLElement($this->sampleXml);
+
+ $path = 'changeset/' . $id . '/download';
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->downloadChangeset($id),
+ $this->equalTo(new SimpleXMLElement($this->sampleXml))
+ );
+ }
+
+ /**
+ * Tests the downloadChangeset method - failure
+ *
+ * @return void
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testDownloadChangesetFailure()
+ {
+ $id = '123';
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+ $returnData->create = new SimpleXMLElement($this->sampleXml);
+
+ $path = 'changeset/' . $id . '/download';
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->downloadChangeset($id);
+ }
+
+ /**
+ * Tests the expandBBoxChangeset method
+ *
+ * @return array
+ *
+ * @since 12.3
+ */
+ public function testExpandBBoxChangeset()
+ {
+ $id = '14153708';
+ $node_list = array(array(4,5),array(6,7));
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+
+ $path = 'changeset/' . $id . '/expand_bbox';
+
+ $this->client->expects($this->once())
+ ->method('post')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->expandBBoxChangeset($id, $node_list),
+ $this->equalTo(new SimpleXMLElement($this->sampleXml))
+ );
+ }
+
+ /**
+ * Tests the expandBBoxChangeset method - failure
+ *
+ * @return array
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testExpandBBoxChangesetFailure()
+ {
+ $id = '14153708';
+ $node_list = array(array(4,5),array(6,7));
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+
+ $path = 'changeset/' . $id . '/expand_bbox';
+
+ $this->client->expects($this->once())
+ ->method('post')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->expandBBoxChangeset($id, $node_list);
+ }
+
+ /**
+ * Tests the queryChangeset method
+ *
+ * @return void
+ *
+ * @since 12.3
+ */
+ public function testQueryChangeset()
+ {
+ $param = 'open';
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+ $returnData->osm = new SimpleXMLElement($this->sampleXml);
+
+ $path = 'changesets/' . $param;
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->queryChangeset($param),
+ $this->equalTo(new SimpleXMLElement($this->sampleXml))
+ );
+ }
+
+ /**
+ * Tests the queryChangeset method - failure
+ *
+ * @return void
+ *
+ * @since 12.3
+ * @expectedException DomainException
+ */
+ public function testQueryChangesetFailure()
+ {
+ $param = 'open';
+
+ $returnData = new stdClass;
+ $returnData->code = 500;
+ $returnData->body = $this->errorString;
+ $returnData->osm = new SimpleXMLElement($this->sampleXml);
+
+ $path = 'changesets/' . $param;
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->object->queryChangeset($param);
+ }
+
+ /**
+ * Tests the diffUploadChangeset method
+ *
+ * @return array
+ *
+ * @since 12.3
+ */
+ public function testDiffUploadChangeset()
+ {
+ $id = '123';
+ $xml = '<osmChange>
+ <modify>
+ <node id="12" timestamp="2012-12-02T00:00:00.0+11:00" lat="-33.9133118622908" lon="151.117335519304">
+ <tag k="created_by" v="JOsm"/>
+ </node>
+ </modify>
+ </osmChange>';
+
+ $returnData = new stdClass;
+ $returnData->code = 200;
+ $returnData->body = $this->sampleXml;
+
+ $path = 'changeset/' . $id . '/upload';
+
+ $this->client->expects($this->once())
+ ->method('post')
+ ->with($path)
+ ->will($this->returnValue($returnData));
+
+ $this->assertThat(
+ $this->object->diffUploadChangeset($xml, $id),
+ $this->equalTo(new SimpleXMLElement($this->sampleXml))
+ );
+ }
+
+ /**
+ * Tests the diffUploadChangeset method - failure
+ *
+ * @return array