CGaskell / MetOfficeDataPoint

A .NET Core class library for accessing the Met Office DataPoint API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MetOfficeDataPoint

.NET wrapper to query the Met Office DataPoint API for weather data.

Installation

To use MetOfficeDataPoint in your C# project, you can either download the MetOfficeDataPoint C# .NET libraries directly from the Github repository or, if you have the NuGet package manager installed, you can grab them automatically.

PM> Install-Package MetOfficeDataPoint

Once you have the MetOfficeDataPoint libraries properly referenced in your project, you can include calls to them in your code.

Add the following namespaces to use the library:

using MetOfficeDataPoint;
using MetOfficeDataPoint.Models;
using MetOfficeDataPoint.Models.GeoCoordinate;

Usage

The below code can be used in a .NET Core project, a test project is also included in the GitHub solution.

    public class Program
    {
        public static void Main(string[] args)
        {
            // Create client
            MetOfficeDataPointClient client = new MetOfficeDataPointClient("[TOKEN}");

            // Get all sites
            SiteListResponse siteListResponse = client.GetAllSites().Result;

            // Get available forcasts
            AvailableTimeStampsResponse availableTimeStampsResponse = client.GetAvailableTimestamps().Result;

            // Get all 3 hourly forecasts
            ForecastResponse3Hourly forecastResponse3Hourly = client.GetForecasts3Hourly().Result;

            // Get daily forecasts for site 14
            ForecastResponseDaily forecastResponseDaily = client.GetForecastsDaily(14).Result;

            // Get historical observations
            ForecastResponse3Hourly historicalResponse = client.GetHistoricalObservations().Result;

            // Get closest site
            GeoCoordinate coordinate = new GeoCoordinate(51.508363, -0.163006);
            Location location = client.GetClosestSite(coordinate).Result;
        }
    }

Example

See here for an example of this in action with the weather status matched to corresponding weather icons.

About

A .NET Core class library for accessing the Met Office DataPoint API

License:GNU General Public License v3.0


Languages

Language:C# 100.0%