Class WeatherReport
In: lib/weather_report.rb
Parent: Object

Class containing weather observations and forecasts for the location specified by id in the constructor.

Methods

Classes and Modules

Class WeatherReport::WeatherReportFormatError
Class WeatherReport::WeatherReportNoResponseError

Constants

VERSION = '0.0.4'

Attributes

id  [R]  The id is the number (1..9999) the BBC uses to identify cities for weather reports

Public Class methods

Requires a valid BBC Backstage weather id (or any call to the API will return a FormatError)

[Source]

# File lib/weather_report.rb, line 24
  def initialize(location_id)
    @id = location_id
  end

Public Instance methods

Returns the weather forecast for the current id. If one is not currently loaded then this will go to the BBC Backstage API and download it. Alternatively, by specifying force_reload = true the observation will be loaded from the BBC regardless of whether one has already been downloaded.

[Source]

# File lib/weather_report.rb, line 37
  def forecast(force_reload = false) 
    @forecast = WeatherReportForecasts.new(fetch(forecast_url())) if force_reload or @forecast.nil?
    @forecast
  end

Returns the weather observation for the current id. If one is not currently loaded then this will go to the BBC Backstage API and download it. Alternatively, by specifying force_reload = true the observation will be loaded from the BBC regardless of whether one has already been downloaded.

[Source]

# File lib/weather_report.rb, line 30
  def observation(force_reload = false) 
    @observation = WeatherReportObservation.new(fetch(observation_url())) if force_reload or @observation.nil?
    @observation
  end

Protected Instance methods

Fetch Response from the api

[Source]

# File lib/weather_report.rb, line 45
  def fetch(url)
    response = Net::HTTP.get_response(URI.parse(url)).body
    
    # Check if a response was returned at all
    raise(WeatherReport::WeatherReportNoResponseError, "WeatherReport Error: No Response.") unless response
     
    response
  end

The url for getting weather forecasts from BBC Backstage

[Source]

# File lib/weather_report.rb, line 61
  def forecast_url() 
    "http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/#{@id}.xml"
    #"http://newsrss.bbc.co.uk/weather/forecast/#{@id}/Next3DaysRSS.xml"
  end

The url for getting current weather observations from BBC Backstage

[Source]

# File lib/weather_report.rb, line 55
  def observation_url() 
    "http://feeds.bbc.co.uk/weather/feeds/rss/obs/world/#{@id}.xml"
    #"http://newsrss.bbc.co.uk/weather/forecast/#{@id}/ObservationsRSS.xml"
  end

[Validate]