Coder Social home page Coder Social logo

osmapiclient's Introduction

DEPRECATED

Development has moved to https://github.com/OsmSharp/io-api


OsmApiClient

This is a simple C# client to allow using OSM API easily. Please read the API's documentation and use it responsibly. Misuse can have an adverse affect on the OSM ecosystem. Pull requests are welcome. You will need VisualStudio or VS Code to modify this project.

Features

  • Supports Logging using ILogger
  • Supports BasicAuth, OAuth 1 and OAuth 2
  • Supports every documented operation of the Osm Api v0.6
  • Has a nuget package
  • Is thread safe

Example Usage

using OsmSharp.IO.API;
// Create a client factory (pointing at the dev server)
var clientFactory = new ClientsFactory(null, new HttpClient(),
	"https://master.apis.dev.openstreetmap.org/api/");
// After testing, use "https://www.openstreetmap.org/api/" for production

Get a Node

var client = clientFactory.CreateNonAuthClient();
var node = await client.GetNode(100);

Delete a Node (map changes require BasicAuth or OAuth)

var authClient = clientFactory.CreateBasicAuthClient("username", "password");
var changeSetTags = new TagsCollection() { new Tag("comment", "Deleting a node.") };
var changeSetId = await client.CreateChangeset(changeSetTags);
node.Version = await client.DeleteElement(changeSetId, node);
await client.CloseChangeset(changeSetId);

See the functional tests for examples of each operation.

Supported Operations

๐ŸŒ• = Does not use authentication

๐ŸŒ— = With or without authentication (behavior may differ)

๐ŸŒ‘ = Requires authentication

General Api Stuff

  • ๐ŸŒ• Get Api versions
  • ๐ŸŒ• Get Api capabilities
  • ๐ŸŒ• Get a map section

Change Sets

  • ๐ŸŒ• Get a specific changeset's metadata
  • ๐ŸŒ• Get a specific changeset's changes
  • ๐ŸŒ• Search for changesets
  • ๐ŸŒ‘ Create a new changeset with metadata
  • ๐ŸŒ‘ Add changes to an open changeset
  • ๐ŸŒ‘ Update an open changeset's metadata
  • ๐ŸŒ‘ Close an open changeset
  • ๐ŸŒ‘ Add comments to a changeset
  • ๐ŸŒ‘ Subscribe to a changeset
  • ๐ŸŒ‘ UnSubscribe to a changeset

Map Elements

  • ๐ŸŒ• Get an element
  • ๐ŸŒ• Get an element's version history
  • ๐ŸŒ• Get a specific version of an element
  • ๐ŸŒ• Search for elements
  • ๐ŸŒ• Get relations containing a specific element
  • ๐ŸŒ• Get ways containing a specific node
  • ๐ŸŒ• Get a relation and all of its elements
  • ๐ŸŒ• Get a way and all of its nodes
  • ๐ŸŒ‘ Create a new element
  • ๐ŸŒ‘ Update an element
  • ๐ŸŒ‘ Delete an element

Gpx Files

  • ๐ŸŒ• Get trackpoints in an area
  • ๐ŸŒ— Get a gpx file's metadata
  • ๐ŸŒ— Get a gpx file's original upload data
  • ๐ŸŒ‘ Get current user's gpx files
  • ๐ŸŒ‘ Create a new gpx file
  • ๐ŸŒ‘ Update a gpx file's metadata
  • ๐ŸŒ‘ Delete a gpx file

User Info

  • ๐ŸŒ• Get details about a user
  • ๐ŸŒ• Get details about many users
  • ๐ŸŒ‘ Get current user's permissions
  • ๐ŸŒ‘ Get current user's details
  • ๐ŸŒ‘ Get current user's preferences
  • ๐ŸŒ‘ Update current user's preferences
  • ๐ŸŒ‘ Get a current user's preference
  • ๐ŸŒ‘ Update a current user's preference
  • ๐ŸŒ‘ Delete a current user's preference

Notes

  • ๐ŸŒ• Search for notes
  • ๐ŸŒ• Get an RSS feed of notes in an area
  • ๐ŸŒ• Get a note
  • ๐ŸŒ— Create a new note
  • ๐ŸŒ‘ Comment on a note
  • ๐ŸŒ‘ Close a note
  • ๐ŸŒ‘ ReOpen a note

Contribute

Issues and pull requests are welcome.

osmapiclient's People

Contributors

blackboxlogic avatar harelm avatar shabalinlev01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

osmapiclient's Issues

Which URL to use for production

I have setup client like in docs and shown in the tests. I create a bounding box with:


// lat lon
max
57.7118, 11.93443

min
57.69379, 11.90072

Screen Shot 2022-01-25 at 18 40 47

This area has places in when I use overpass turbo to get nodes etc.


I suspect something might be wrong with the url. I also don't understand which one to use - especially not in production?

Some further information is that I am running from an iPhone device in a Xamarin app. It should not really matter though

Constraints for Bounds.[Min|Max]Latitude in Validate are wrong

Valid latitude values are in the Range [-90, 90]:

if (bounds.MinLongitude < -180 || bounds.MinLongitude > 180
|| bounds.MinLatitude < -180 || bounds.MinLatitude > 180
|| bounds.MaxLongitude < -180 || bounds.MaxLongitude > 180
|| bounds.MaxLatitude < -180 || bounds.MaxLatitude > 180
|| bounds.MinLatitude >= bounds.MaxLatitude)
{
throw new ArgumentException("Those Bounds are not valid.");
}

Improve tests

Use the MSTest and split every operation to its own test by using [TestInitialize] and [TestCleanup] so that you can test every part of the API separately.

Originally posted by @HarelM in #8 (comment)

Support fetching trace file data by url

Looking back at the original code the client derives from BaseFileFetcher.
I tried to remember why I did it and the only reason that came to my mind is the ability to get the data of a private trace you uploaded - i.e. when getting the traces list you only get the metadata, but in order to get the gpx file content you need to do another http request.
This is currently handled in my code partially on the client side and partially on the server side - the client get the list of traces, and creates the trace url, when the user clicks on the link the url is sent to the server.
This is less than ideal and a utility method is probably needed in this library to create full url from trace data.
This code basically:
https://github.com/IsraelHikingMap/Site/blob/af5d5d65f4485999571883ebf8315811af79f664/IsraelHiking.Web/sources/application/services/traces.service.ts#L30
And the server code to fetch the file:
https://github.com/IsraelHikingMap/Site/blob/af5d5d65f4485999571883ebf8315811af79f664/IsraelHiking.DataAccess/BaseFileFetcherGateway.cs#L19

Unable to Use Nuget to Install OsmApiClient

Hi, I am trying to use Nuget PM to install OsmApiClient. However, even after I try NuGet\Install-Package OsmApiClient -Version 0.0.8, OsmApiClient is unrecognized.

I get this error: The type or namespace 'OsmApiClient' could not be found (are you missing a using directive or assembly reference?)
I am calling the assembly like so: using OsmApiClient;

The installation does not throw any errors:

PM> NuGet\Install-Package OsmApiClient -Version 0.0.8
Restoring packages for C:\Users\steph\source\repos\unity_map_test\unity_map_test\unity_map_test.csproj...
Installing NuGet package OsmApiClient 0.0.8.
Assets file has not changed. Skipping assets file writing. Path: C:\Users\steph\source\repos\unity_map_test\unity_map_test\obj\project.assets.json
Restored C:\Users\steph\source\repos\unity_map_test\unity_map_test\unity_map_test.csproj (in 18 ms).
Executing nuget actions took 34 ms
Time Elapsed: 00:00:00.0904549

I am using Visual Studio 2022.

Advice would be greatly appreciated! Thank you for your time and help!

Add Functional Tests

Add a new project which tests each function in the client, including OAuth and BasicAuth.
It should output the success/failure of the tests.
It should get credentials and api url from a config file.

Broken parameters in URL request when change CultureInfo

When I Change CultureInfo in my application from en-US to ru-RU/fr-FR/es-ES. I catch the error "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat."
Coordinates change format from "0.####" to "0,####". I think the problem in ToString(Bounds), when Double Value converts to string with a mask.

Test OAuth

Create OAuth tests in the functional test project.

Add Factories and intefaces

For testing and IOC it is required that this library has more interfaces and a factory to create the right client.

Add Documentation

When the interfaces and classes settles down we should add some examples to the readme.md file instructing how to use this library.

Default xml deserialization potentially unsafe

The Problem

The default serializer code uses the stream directly to deserialize xml to target type:

protected async Task<T> Get<T>(string address, Action<HttpRequestMessage> auth = null) where T : class
{
    var content = await Get(address, auth);
    var stream = await content.ReadAsStreamAsync();
    var serializer = new XmlSerializer(typeof(T));
    var element = serializer.Deserialize(stream) as T;
    return element;
}

This does not conform with (CA5369) which states that

Deserializing untrusted XML input with XmlSerializer.Deserialize instantiated without an XmlReader object can potentially lead to denial of service, information disclosure, and server-side request forgery attacks. These attacks are enabled by untrusted DTD and XML schema processing, which allows for the inclusion of XML bombs and malicious external entities in the XML. Only with XmlReader is it possible to disable DTD. Inline XML schema processing as XmlReader has the ProhibitDtd and ProcessInlineSchema property set to false by default in .NET Framework version 4.0 and later. The other options such as Stream, TextReader, and XmlSerializationReader cannot disable DTD processing.

The Solution

Create an xml reader and use it for deserialization:

protected async Task<T> Get<T>(string address, Action<HttpRequestMessage> auth = null) where T : class
{
    using var content = await Get(address, auth);
    using var stream = await content.ReadAsStreamAsync();
    using var xmlReader = await XmlReader.Create(stream);
    var serializer = new XmlSerializer(typeof(T));
    var element = serializer.Deserialize(xmlReader) as T;
    return element;
}

But there is a problem when deserializing OsmChange the create,modify and delete members are empty, I think this has to do with the custom xml reading from OsmSharp.

Archive this repo

Should we archive this repo?
If so we need to change the readme to link to the new location of this repo and only afterwards archive it.
I've got a notification from NuGet that my token is about to expire, which makes sense, since it wasn't used for almost a year.
@blackboxlogic what do you think?

Add request address to response logging

There are situations where multiple requests are sent, some may fail.
If request are sent in parallel there's no way to know which request failed and which didn't.
Adding the address and method to the logging should solve this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.