Skip to content

Create a New Provider

johnluetke edited this page Mar 27, 2013 · 3 revisions

Creating a new provider is very straight-forward. These steps presume you have already forked the repository.

  1. Create a new package (Java) or Namespace (.NET) for your provider in the WeatherAPI.Providers parent namespace. For example, if you are creating a provider for the Awesome Weather Service, the new namespace would be named WeatherAPI.Providers.AwesomeWeather. The class name inside this package does not matter. We will use AwesomeWeatherProvider in this example.

  2. Ensure that the AwesomeWeatherProvider class inherits from WeatherProvider and implements IWeather.

  3. Start by implementing the abstract methods inherited from WeatherProvider:

  • IsAvailable: returns true or false depending on whether or not the service that the provider uses is available to some code using this library. For example, if the service requires and API Key, this method should make sure that the API key have been specified in configuration. It should not go out and ping the service to make sure that it is responsive.
  • Supports: Weather data can be requested for a number of different "types" of locations, such as an airport code, a postal code, latitude / longitude, etc. One of these types will be passed to this method, and it should return true or false based on weather or nor the service can support retrieving data for that type of location. See the LocationType enumeration for the possibilities.
  • Update: Is the big kahuna. This method is what goes out to the service and fetches data.
  1. Next, implement the methods specified by the IWeather interface. These methods return details about the weather retrieved from the service, such as the current temperature, humidity, conditions, cloud cover, etc.

Clone this wiki locally