|
1 | 1 | # Overcast |
2 | | -An easy to use API for Forecast.io |
| 2 | +An easy to use wrapper for the [Forecast.io](https://forecast.io) API v2. |
| 3 | + |
| 4 | +Overcast will query the Forecast.io API for weather information for the longitude and latitude you specify. Additionally |
| 5 | +you may specify the specific time, past or present. |
| 6 | + |
| 7 | +See the [Forecast.io API documentation](https://developer.forecast.io/docs/v2) for more information. |
| 8 | + |
| 9 | +## Installation |
| 10 | +Installation is as simple as using [Composer](http://getcomposer.org/): |
| 11 | + |
| 12 | +``` |
| 13 | +{ |
| 14 | + "require": { |
| 15 | + "vertigolabs/overcast": "dev-master" |
| 16 | + } |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +## Example |
| 21 | +Since the Forecast.io API is simple, Overcast is equally easy to use. |
| 22 | +Simply create an instance of the Overcast class, then call the getForecast() method. |
| 23 | + |
| 24 | +Overcast::getForecast() returns a nicely structured Forecast object which contains other data structures for handy access to all of the response data from Forecast.io. |
| 25 | + |
| 26 | +```php |
| 27 | +$overcast = new \VertigoLabs\Overcast\Overcast('YOUR API KEY'); |
| 28 | +$forecast = $overcast->getForecast(37.8267,-122.423); |
| 29 | + |
| 30 | +// check the number of API calls you've made with your API key for today |
| 31 | +echo $overcast->getApiCalls().' API Calls Today'."\n"; |
| 32 | + |
| 33 | +// temperature current information |
| 34 | +echo 'Current Temp: '.$forecast->getCurrently()->getTemperature()->getCurrent()."\n"; |
| 35 | +echo 'Feels Like: '.$forecast->getCurrently()->getApparentTemperature()->getCurrent()."\n"; |
| 36 | +echo 'Min Temp: '.$forecast->getCurrently()->getTemperature()->getMin()."\n"; |
| 37 | +echo 'Max Temp: '.$forecast->getCurrently()->getTemperature()->getMax()."\n"; |
| 38 | + |
| 39 | +// get daily summary |
| 40 | +echo 'Daily Summary: '.$forecast->getDaily()->getSummary()."\n"; |
| 41 | + |
| 42 | +// loop daily data points |
| 43 | +foreach($forecast->getDaily()->getData() as $dailyData) { |
| 44 | + echo 'Date: '.$dailyData->getTime()->format('D, M jS y')."\n"; |
| 45 | + // get daily temperature information |
| 46 | + echo 'Min Temp: '.$dailyData->getTemperature()->getMin()."\n"; |
| 47 | + echo 'Max Temp: '.$dailyData->getTemperature()->getMax()."\n"; |
| 48 | + |
| 49 | + // get daily precipitation information |
| 50 | + echo 'Precipitation Probability: '.$dailyData->getPrecipitation()->getProbability()."\n"; |
| 51 | + echo 'Precipitation Intensity: '.$dailyData->getPrecipitation()->getIntensity()."\n"; |
| 52 | + |
| 53 | + // get other general daily information |
| 54 | + echo 'Wind Speed: '.$dailyData->getWindSpeed()."\n"; |
| 55 | + echo 'Wind Direction: '.$dailyData->getWindBearing()."\n"; |
| 56 | + echo 'Visibility: '.$dailyData->getVisibility()."\n"; |
| 57 | + echo 'Cloud Coverage: '.$dailyData->getCloudCover()."\n"; |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +This will output: |
| 62 | + |
| 63 | +``` |
| 64 | +18 API Calls Today |
| 65 | +
|
| 66 | +Current Temp: 61.05 |
| 67 | +Feels Like: 61.05 |
| 68 | +Min Temp: |
| 69 | +Max Temp: |
| 70 | +
|
| 71 | +Daily Summary: Drizzle on Tuesday, with temperatures peaking at 65°F on Thursday. |
| 72 | +
|
| 73 | +Date: Tue, Mar 31st 15 |
| 74 | +Min Temp: 53.83 |
| 75 | +Max Temp: 61.81 |
| 76 | +Precipitation Probability: 0 |
| 77 | +Precipitation Intensity: 0 |
| 78 | +Wind Speed: 12.77 |
| 79 | +Wind Direction: 308 |
| 80 | +Visibility: 8.93 |
| 81 | +Cloud Coverage: 0.25 |
| 82 | +
|
| 83 | +Date: Wed, Apr 1st 15 |
| 84 | +Min Temp: 48.72 |
| 85 | +Max Temp: 60.08 |
| 86 | +Precipitation Probability: 0 |
| 87 | +Precipitation Intensity: 0 |
| 88 | +Wind Speed: 14.47 |
| 89 | +Wind Direction: 321 |
| 90 | +Visibility: 10 |
| 91 | +Cloud Coverage: 0.06 |
| 92 | +
|
| 93 | +Date: Thu, Apr 2nd 15 |
| 94 | +Min Temp: 48.96 |
| 95 | +Max Temp: 65.46 |
| 96 | +Precipitation Probability: 0 |
| 97 | +Precipitation Intensity: 0 |
| 98 | +Wind Speed: 10.02 |
| 99 | +Wind Direction: 346 |
| 100 | +Visibility: 10 |
| 101 | +Cloud Coverage: 0 |
| 102 | +
|
| 103 | +Date: Fri, Apr 3rd 15 |
| 104 | +Min Temp: 49.17 |
| 105 | +Max Temp: 63.68 |
| 106 | +Precipitation Probability: 0 |
| 107 | +Precipitation Intensity: 0 |
| 108 | +Wind Speed: 6.03 |
| 109 | +Wind Direction: 292 |
| 110 | +Visibility: 10 |
| 111 | +Cloud Coverage: 0.07 |
| 112 | +
|
| 113 | +Date: Sat, Apr 4th 15 |
| 114 | +Min Temp: 47.14 |
| 115 | +Max Temp: 58.44 |
| 116 | +Precipitation Probability: 0 |
| 117 | +Precipitation Intensity: 0 |
| 118 | +Wind Speed: 11.48 |
| 119 | +Wind Direction: 288 |
| 120 | +Visibility: |
| 121 | +Cloud Coverage: 0.3 |
| 122 | +
|
| 123 | +Date: Sun, Apr 5th 15 |
| 124 | +Min Temp: 47.95 |
| 125 | +Max Temp: 56.2 |
| 126 | +Precipitation Probability: 0.09 |
| 127 | +Precipitation Intensity: 0.0017 |
| 128 | +Wind Speed: 14.35 |
| 129 | +Wind Direction: 285 |
| 130 | +Visibility: |
| 131 | +Cloud Coverage: 0.06 |
| 132 | +
|
| 133 | +Date: Mon, Apr 6th 15 |
| 134 | +Min Temp: 44.63 |
| 135 | +Max Temp: 57.25 |
| 136 | +Precipitation Probability: 0.01 |
| 137 | +Precipitation Intensity: 0.0005 |
| 138 | +Wind Speed: 8.06 |
| 139 | +Wind Direction: 281 |
| 140 | +Visibility: |
| 141 | +Cloud Coverage: 0 |
| 142 | +
|
| 143 | +Date: Tue, Apr 7th 15 |
| 144 | +Min Temp: 51.23 |
| 145 | +Max Temp: 60.55 |
| 146 | +Precipitation Probability: 0.32 |
| 147 | +Precipitation Intensity: 0.0022 |
| 148 | +Wind Speed: 8.06 |
| 149 | +Wind Direction: 258 |
| 150 | +Visibility: |
| 151 | +Cloud Coverage: 0.24 |
| 152 | +``` |
| 153 | + |
| 154 | +## Todo |
| 155 | +* Accept additional API options |
0 commit comments