Skip to content

MrBasque/YahooWeatherNET

 
 

Repository files navigation

YahooWeatherNET

Build Status

An easy-to-use .NET wrapper for the Yahoo Weather API. Now with OAuth Support!

IMPORTANT: Yahoo APIs ToS and Yahoo Attribution Guidelines apply if you use this library/the API within your application!

You can use the YahooWeatherNET library for accessing online weather data from within your .NET application. The library makes use of the new Async/Await functionality offered by the .NET Framework, therefore the target Framework for this library is version 4.0 (asynchronous programming is available in version 4 when using the AsyncTargetingPack).

Usage Instructions

IMPORTANT: As of version 2.0, the weather data can only be fetched asynchronously. If you still need synchronous access, you may use version 1.2. Instructions for version 1.2 can be found in the wiki.

The following snippet will get you started:

using YahooWeatherNET;

public class Main
{
  private YahooWeatherProvider m_weatherProvider;

  public Main()
  {
    m_weatherProvider = new YahooWeatherProvider();
  }
  
  public async Task GetWeatherAsync()
  {
    // Create a new weather report for the desired location. Note that this call has to be made asynchronously,
    // because the location lookup is a call to the weather API. If you already have a WOEID, use .CreateReport("the woeid");
    WeatherReport report = await YahooWeatherProvider.CreateReportFromLocation("Cologne");
    
    // Query the current weather conditions.
    // This call can throw an UnknownWoeidException and a WeatherParsingException. These should be caught.
    WeatherItem wItem = await report.Query();
  }

  public async Task<string> ResolveLocationToWoeid()
  {
    // To manually resolve a location (town, POI or weather station) to a WOEID consumable by the API, use the LocationResolver class.
    return await LocationResolver.ResolveLocationToWoeid("Cologne");
  } 
}

Currently, Yahoo does not enforce OAuth authentication for the weather and location API. If this changes, you can pass your consumer key and secret to the YahooWeatherProvider constructor. See also OAuth setup

Class Diagram

class diagram

Version History & Changelog

  • 2.0.0.0
    • API redesign
      • Added WeatherReport abstraction
      • Switched to YQL queries
      • OAuth no longer mandatory
      • Removed all synchronous methods
  • 1.2.0.0
    • Added OAuth authentication
  • 1.1.0.0
    • Fixed typos
    • Changed location to GeoCoordinates

About

An easy-to-use .NET wrapper for the Yahoo Weather API **OAuth Support**

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%