Skip to content

.NET project to lookup current data of Belgian postal codes

License

Notifications You must be signed in to change notification settings

MichelMichels/BpostSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BpostSharp ✉️

This projects is a C# wrapper library to obtain Belgian city data from bpost (Belgian national mail service).

Table of Contents

Prerequisites

Building

Use Visual Studio 2022 to build the project.

Installation

Get the NuGet packages from nuget.org or search for MichelMichels.BpostSharp in the GUI package manager in Visual Studio.

You can also use the cli of the package manager with one of following commands:

Install-Package MichelMichels.BpostSharp.Excel
Install-Package MichelMichels.BpostSharp.Web

Above commands will also add a dependency to MichelMichels.BpostSharp. This nuget package contains the core code.


Getting started

There are 2 versions of BpostSharp:

Name Nuget Description
MichelMichels.BpostSharp.Excel Excel cache (offline)
MichelMichels.BpostSharp.Web Html cache (online)

These 2 versions have following dependency:

Name Nuget Description
MichelMichels.BpostSharp This is the core package which contains all interfaces and models.

To use the excel version, use any version of the files at the official bpost website. To use the web version, grab one of the HTML versions on the same page.

Example code

Creating a web instance:

ICacheBuilder<CityData> webCacheBuilder = new WebCacheBuilder(BpostWebConstants.DutchEndpoint);
ICityDataService cityDataService = new BelgianCityDataService(webCacheBuilder);

Creating an excel instance:

ICacheBuilder<CityData> webCacheBuilder = new ExcelCacheBuilder("excel-from-bpost.xls");
ICityDataService cityDataService = new BelgianCityDataService(webCacheBuilder);

Querying data:

// Querying by postal code
List<CityData> data = await cityDataService.GetByPostalCode("9000");

// Querying by city name
List<CityData> data = await cityDataService.GetByCityName("Gent");

Code explanation

The querying uses StartsWith(...) and ignores casing.

Data is saved into cache after executing Build() on the ICacheBuilder or after first query, whichever comes earlier. You can clear the cache with Clear().

Credits

Written by Michel Michels.

About

.NET project to lookup current data of Belgian postal codes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages