Coder Social home page Coder Social logo

bikeshareclient's Introduction

BikeshareClient

Dotnet client for the General Bikeshare Feed Specification (GBFS). Mainly used against Urban Infrastructure Partner, with Trondheim City Bike and Bergen City Bike.

For all available GBFS systems, see the system overview from the GBFS project.

Supports the required fields in the GBFS standard for now.

Basic Usage

// Create the client from a GBFS API URL.
IBikeshareClient client = new Client("http://gbfs.urbansharing.com/trondheim/gbfs.json");

// Or with an existing HTTPClient
IBikeshareClient client = new Client("http://gbfs.urbansharing.com/trondheim/gbfs.json", httpClient);

// All available stations, containing name, id, lat, long, address and capacity
var stations = await client.GetStationsAsync();

// All stations status, containing number of bikes and docks available, is renting, is returning etc.
var statuses = await client.GetStationsStatusAsync();

A simple dotnet-script test script for the client can be seen here.

Microsoft.Extensions.DependencyInjection integration

BikeshareClient can be registered to IServiceCollection by referencing the BikeshareClient.DependencyInjection NuGet package:

using BikeshareClient.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

services.AddBikeshareClient("http://gbfs.urbansharing.com/trondheim/gbfs.json");

Build and testscript

Simple build:

docker run --rm -it -v $(pwd):/app mcr.microsoft.com/dotnet/sdk:7.0 dotnet pack app/src/BikeshareClient -o /app

Run test script:

docker run --rm -it -v $(pwd)/src/TestScript/:/scripts  andmos/dotnet-script main.csx "Skansen"

CI / CD

codecov

NuGet BikeshareClient

NuGet BikeshareClient.DependencyInjection

Dependabot Status

GBFS is a standard backed by the North American Bike Share Association (NABSA).

bikeshareclient's People

Contributors

andmos avatar dependabot-preview[bot] avatar dependabot[bot] avatar hjerpbakk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ericsellers

bikeshareclient's Issues

Improve documentation in README

Some example code in the README demonstrating how to use the client would be nice.

Even if it is as simple as creating a client and providing a url ๐Ÿ˜…

Handle GBFS.json

The GBFS standard has a GBFS.json file that returns available feeds. The client should use this file, not just baseurl.

Create Microsoft.Extensions.DependencyInjection extention for client

It would be great to publish an BikeshareClient.Aspnet or something that implements

    public static class ServiceCollectionExtensions
    {
        public static IHttpClientBuilder AddBikeshareClient(this IServiceCollection services)
            => services.AddHttpClient<IClient, BikeshareClient>();
    }

As long as the client has a HTTPClient this should be rather straight forward.

Rewrite xUnit tests to remove warnings

After upgrading xUnit package, a couple of warnings shows up. The tests should be rewritten anyways, since some of the assert-usage is pointless in the first place.

TestBikeShareClient.cs(246,13): warning xUnit2002: Do not use Assert.NotNull() on value type 'DateTime'. [/app/TestBikeshareClient/TestBikeshareClient.csproj]
TestBikeShareClient.cs(258,13): warning xUnit2002: Do not use Assert.NotNull() on value type 'DateTime'. [/app/TestBikeshareClient/TestBikeshareClient.csproj]
TestBikeShareClient.cs(261,13): warning xUnit2002: Do not use Assert.NotNull() on value type 'int'. [/app/TestBikeshareClient/TestBikeshareClient.csproj]
TestBikeShareClient.cs(263,13): warning xUnit2002: Do not use Assert.NotNull() on value type 'int'. [/app/TestBikeshareClient/TestBikeshareClient.csproj]
TestBikeShareClient.cs(265,13): warning xUnit2002: Do not use Assert.NotNull() on value type 'int'. [/app/TestBikeshareClient/TestBikeshareClient.csproj]
TestBikeShareClient.cs(221,13): warning xUnit2012: Do not use Enumerable.Any() to check if a value exists in a collection. [/app/TestBikeshareClient/TestBikeshareClient.csproj]
TestBikeShareClient.cs(235,13): warning xUnit2012: Do not use Enumerable.Any() to check if a value exists in a collection. [/app/TestBikeshareClient/TestBikeshareClient.csproj]

Add dependabot config

The default dependabot "happy path" takes one csproj. Create a config also including the test-project.

Make HTTPClient injectable

public Client(string gbfsBaseUrl, HTTPClient httpClient = null) or something to avoid breaking changes in the client.

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.