Giter Club home page Giter Club logo

overcast's Introduction

Overcast

SensioLabsInsight

Latest Unstable Version Latest Stable Version

License Total Downloads

An easy to use wrapper for the Forecast.io API v2.

Overcast will query the Forecast.io API for weather information for the longitude and latitude you specify. Additionally you may specify the specific time, past or present.

See the Forecast.io API documentation for more information.

Installation

Installation is as simple as using Composer:

{
    "require": {
        "vertigolabs/overcast": "dev-master"
    }
}

Client Adapters

Overcast uses client adapters to connect to the Forecast.io API. This gives you the ability to create your own adapter for whatever HTTP client you'd like to use. This is especially useful for people who have special needs when dealing with retrieving data from third parties (firewalls, proxies, etc)

Overcast comes with two client adapters ready for use, FileGetContentsClientAdapter and GuzzleClientAdapter. You can also create your own by simply implementing the ClientAdapterInterface

By default, you do not have to specify which adapter to use. Overcast will automatically use the best client adapter available. If Guzzle is installed, it will use the GuzzleClientAdaptor, otherwise it will fallback to the FileGetContentsClientAdapter.

If you do wish to specify the client adapter, you'd do this with the second parameter when instancing the Overcast class:

$overcast = new \VertigoLabs\Overcast\Overcast('YOUR API KEY', new \VertigoLabs\Overcast\ClientAdapters\FileGetContentsClientAdapter());
// or
$overcast = new \VertigoLabs\Overcast\Overcast('YOUR API KEY', new MyAwesomeClientAdapter());

Example

Since the Forecast.io API is simple, Overcast is equally easy to use. Simply create an instance of the Overcast class, then call the getForecast() method.

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.

$overcast = new \VertigoLabs\Overcast\Overcast('YOUR API KEY');
$forecast = $overcast->getForecast(37.8267,-122.423);

// check the number of API calls you've made with your API key for today
echo $overcast->getApiCalls().' API Calls Today'."\n";

// temperature current information
echo 'Current Temp: '.$forecast->getCurrently()->getTemperature()->getCurrent()."\n";
echo 'Feels Like: '.$forecast->getCurrently()->getApparentTemperature()->getCurrent()."\n";
echo 'Min Temp: '.$forecast->getCurrently()->getTemperature()->getMin()."\n";
echo 'Max Temp: '.$forecast->getCurrently()->getTemperature()->getMax()."\n";

// get daily summary
echo 'Daily Summary: '.$forecast->getDaily()->getSummary()."\n";

// loop daily data points
foreach($forecast->getDaily()->getData() as $dailyData) {
	echo 'Date: '.$dailyData->getTime()->format('D, M jS y')."\n";
	// get daily temperature information
	echo 'Min Temp: '.$dailyData->getTemperature()->getMin()."\n";
	echo 'Max Temp: '.$dailyData->getTemperature()->getMax()."\n";

	// get daily precipitation information
	echo 'Precipitation Probability: '.$dailyData->getPrecipitation()->getProbability()."\n";
	echo 'Precipitation Intensity: '.$dailyData->getPrecipitation()->getIntensity()."\n";

	// get other general daily information
	echo 'Wind Speed: '.$dailyData->getWindSpeed()."\n";
	echo 'Wind Direction: '.$dailyData->getWindBearing()."\n";
	echo 'Visibility: '.$dailyData->getVisibility()."\n";
	echo 'Cloud Coverage: '.$dailyData->getCloudCover()."\n";
}

This will output:

18 API Calls Today

Current Temp: 61.05
Feels Like: 61.05
Min Temp: 
Max Temp: 

Daily Summary: Drizzle on Tuesday, with temperatures peaking at 65°F on Thursday.

Date: Tue, Mar 31st 15
Min Temp: 53.83
Max Temp: 61.81
Precipitation Probability: 0
Precipitation Intensity: 0
Wind Speed: 12.77
Wind Direction: 308
Visibility: 8.93
Cloud Coverage: 0.25

Date: Wed, Apr 1st 15
Min Temp: 48.72
Max Temp: 60.08
Precipitation Probability: 0
Precipitation Intensity: 0
Wind Speed: 14.47
Wind Direction: 321
Visibility: 10
Cloud Coverage: 0.06

Date: Thu, Apr 2nd 15
Min Temp: 48.96
Max Temp: 65.46
Precipitation Probability: 0
Precipitation Intensity: 0
Wind Speed: 10.02
Wind Direction: 346
Visibility: 10
Cloud Coverage: 0

Date: Fri, Apr 3rd 15
Min Temp: 49.17
Max Temp: 63.68
Precipitation Probability: 0
Precipitation Intensity: 0
Wind Speed: 6.03
Wind Direction: 292
Visibility: 10
Cloud Coverage: 0.07

Date: Sat, Apr 4th 15
Min Temp: 47.14
Max Temp: 58.44
Precipitation Probability: 0
Precipitation Intensity: 0
Wind Speed: 11.48
Wind Direction: 288
Visibility: 
Cloud Coverage: 0.3

Date: Sun, Apr 5th 15
Min Temp: 47.95
Max Temp: 56.2
Precipitation Probability: 0.09
Precipitation Intensity: 0.0017
Wind Speed: 14.35
Wind Direction: 285
Visibility: 
Cloud Coverage: 0.06

Date: Mon, Apr 6th 15
Min Temp: 44.63
Max Temp: 57.25
Precipitation Probability: 0.01
Precipitation Intensity: 0.0005
Wind Speed: 8.06
Wind Direction: 281
Visibility: 
Cloud Coverage: 0

Date: Tue, Apr 7th 15
Min Temp: 51.23
Max Temp: 60.55
Precipitation Probability: 0.32
Precipitation Intensity: 0.0022
Wind Speed: 8.06
Wind Direction: 258
Visibility: 
Cloud Coverage: 0.24

Todo

  • Accept additional API options

overcast's People

Contributors

jaimz22 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.