This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
weatherman / README.rdoc
| 039b635b » | jdpace | 2008-09-29 | 1 | = WeatherMan | |
| 1745a63a » | jdpace | 2008-09-29 | 2 | ||
| 3 | A Ruby Gem that wraps the Weather Channel, inc. XML data feed | ||||
| 4 | written by Jared Pace, Codeword: Studios (http://codewordstudios.com), | ||||
| 039b635b » | jdpace | 2008-09-29 | 5 | based on the rweather[http://github.com/ckozus/rweather] gem by Carlos Kozuszko - http://www.ckozus.com.ar/blog/. | |
| 1745a63a » | jdpace | 2008-09-29 | 6 | ||
| 039b635b » | jdpace | 2008-09-29 | 7 | == Dependencies | |
| dbf90f3b » | jdpace | 2008-09-29 | 8 | ||
| 039b635b » | jdpace | 2008-09-29 | 9 | 1. XmlSimple | |
| 700162a3 » | jdpace | 2008-09-29 | 10 | `gem install xml-simple` | |
| dbf90f3b » | jdpace | 2008-09-29 | 11 | ||
| 039b635b » | jdpace | 2008-09-29 | 12 | --------------------------- | |
| 13 | |||||
| 14 | == Installation | ||||
| 1745a63a » | jdpace | 2008-09-29 | 15 | ||
| 16 | |||||
| 700162a3 » | jdpace | 2008-09-29 | 17 | % sudo gem sources -a http://gems.github.com # (if you haven't already) | |
| 03b64e73 » | jdpace | 2008-09-29 | 18 | % sudo gem install jdpace-weatherman | |
| 1745a63a » | jdpace | 2008-09-29 | 19 | ||
| 039b635b » | jdpace | 2008-09-29 | 20 | --------------------------- | |
| 21 | |||||
| 22 | == Usage | ||||
| 23 | |||||
| 1745a63a » | jdpace | 2008-09-29 | 24 | ||
| 25 | Find or load a location: | ||||
| 26 | |||||
| 700162a3 » | jdpace | 2008-09-29 | 27 | require 'weather_man' | |
| 28 | WeatherMan.partner_id = '0123456789' | ||||
| 29 | WeatherMan.license_key = '0123456789abcdef' | ||||
| 30 | |||||
| 31 | # Search for a location | ||||
| 32 | # Returns an array of WeatherMan objects | ||||
| 33 | locations = WeatherMan.search('New York') | ||||
| 34 | |||||
| 35 | # or if you know the location id or just want to use a US Zip code | ||||
| 36 | ny = WeatherMan.new('USNY0996') | ||||
| 1745a63a » | jdpace | 2008-09-29 | 37 | ||
| 38 | Fetch the weather: | ||||
| 39 | |||||
| 700162a3 » | jdpace | 2008-09-29 | 40 | # Fetch the current conditions and 5 day forecast in 'standard' units | |
| 41 | weather = ny.fetch | ||||
| 42 | |||||
| 43 | # Fetch only current conditions in metric units | ||||
| 44 | weather = ny.fetch(:days => 0, :unit => 'm') | ||||
| 45 | |||||
| 46 | # Fetch a 3 day forecast only | ||||
| 47 | weather = ny.fetch(:days => 3, :current_conditions => false) | ||||
| 1745a63a » | jdpace | 2008-09-29 | 48 | ||
| 49 | Look at the Current Conditions: | ||||
| 50 | |||||
| 700162a3 » | jdpace | 2008-09-29 | 51 | # current temperature | |
| 52 | temp = weather.current_conditions.temperature | ||||
| 53 | |||||
| 54 | feels_like = weather.current_conditions.feels_like | ||||
| 55 | |||||
| 56 | wind_speed = weather.current_conditions.wind.speed | ||||
| 57 | wind_direction = weather.current_conditions.wind.direction | ||||
| 1745a63a » | jdpace | 2008-09-29 | 58 | ||
| 59 | Look at the forecast: | ||||
| 700162a3 » | jdpace | 2008-09-29 | 60 | ||
| 61 | # how many days? | ||||
| 62 | weather.forecast.size | ||||
| 63 | |||||
| 64 | # Some different forecasts | ||||
| 65 | weather.forecast.today | ||||
| 66 | weather.forecast.tomorrow | ||||
| 67 | weather.forecast.monday | ||||
| 68 | weather.forecast.for(Date.today) | ||||
| 69 | weather.forecast.for(3.days.from_now) # Note: using rails core extensions | ||||
| 70 | weather.forecast.for('Sep 1') | ||||
| 71 | |||||
| 72 | # data for a forecast | ||||
| 73 | friday = weather.forecast.friday | ||||
| 74 | |||||
| 75 | high_temp = friday.high | ||||
| 76 | low_temp = friday.low | ||||
| 77 | |||||
| 78 | # forecasts are split into 2 parts day/night | ||||
| 79 | friday.day.description # Partly Cloudy, Sunny... | ||||
| 80 | friday.day.chance_percipitation # 0..100 | ||||
| 81 | |||||
| 82 | night_wind_speed = friday.night.wind.speed | ||||
| 1745a63a » | jdpace | 2008-09-29 | 83 | ||
| dbf90f3b » | jdpace | 2008-09-29 | 84 | The Weather Channel requires that you 4 promotional links for them if you use their service. Here's how to access those links: | |
| 700162a3 » | jdpace | 2008-09-29 | 85 | ||
| 86 | # The array of pr links | ||||
| 87 | weather.links | ||||
| 88 | |||||
| 89 | # Getting the first links text and url | ||||
| 90 | weather.links.first.text | ||||
| 91 | weather.links.first.url | ||||
| dbf90f3b » | jdpace | 2008-09-29 | 92 | ||
| 039b635b » | jdpace | 2008-09-29 | 93 | TODO: Document all attributes | |







