Skip to content

Commit cf5e28c

Browse files
committed
initial commit
1 parent af7d208 commit cf5e28c

File tree

11 files changed

+1101
-2
lines changed

11 files changed

+1101
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 jaimz22
3+
Copyright (c) 2015 James Murray
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,155 @@
11
# 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

composer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "vertigolabs/overcast",
3+
"description": "An easy to use wrapper for the Forecast.io API",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "James Murray",
8+
"email": "jaimz@vertigolabs.org"
9+
}
10+
],
11+
"require": {}
12+
}

src/Entities/Alert.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* @author: James Murray <jaimz@vertigolabs.org>
4+
* @copyright:
5+
* @date: 3/31/2015
6+
* @time: 1:33 PM
7+
*/
8+
9+
namespace VertigoLabs\Overcast\Entities;
10+
11+
12+
class Alert
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $title;
18+
/**
19+
* @var \DateTime
20+
*/
21+
private $expires;
22+
/**
23+
* @var string
24+
*/
25+
private $description;
26+
/**
27+
* @var string
28+
*/
29+
private $uri;
30+
31+
public function __construct($data)
32+
{
33+
if (isset($data['title'])) {
34+
$this->title = $data['title'];
35+
}
36+
if (isset($data['expires'])) {
37+
$this->expires = (new \DateTime())->setTimestamp($data['expires']);
38+
}
39+
if (isset($data['description'])) {
40+
$this->description = $data['description'];
41+
}
42+
if (isset($data['uri'])) {
43+
$this->uri = $data['uri'];
44+
}
45+
}
46+
47+
/**
48+
* @return string
49+
*/
50+
public function getTitle()
51+
{
52+
return $this->title;
53+
}
54+
55+
/**
56+
* @return \DateTime
57+
*/
58+
public function getExpires()
59+
{
60+
return $this->expires;
61+
}
62+
63+
/**
64+
* @return string
65+
*/
66+
public function getDescription()
67+
{
68+
return $this->description;
69+
}
70+
71+
/**
72+
* @return string
73+
*/
74+
public function getUri()
75+
{
76+
return $this->uri;
77+
}
78+
}

src/Entities/DataBlock.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* @author: James Murray <jaimz@vertigolabs.org>
4+
* @copyright:
5+
* @date: 3/31/2015
6+
* @time: 1:24 PM
7+
*/
8+
9+
namespace VertigoLabs\Overcast\Entities;
10+
11+
12+
class DataBlock
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $summary;
18+
/**
19+
* @var string
20+
*/
21+
private $icon;
22+
/**
23+
* @var DataPoint[]
24+
*/
25+
private $data;
26+
27+
public function __construct($data)
28+
{
29+
if (isset($data['summary'])) {
30+
$this->summary = $data['summary'];
31+
}
32+
if (isset($data['icon'])) {
33+
$this->icon = $data['icon'];
34+
}
35+
if (isset($data['data'])) {
36+
foreach ($data['data'] as $dataPoint) {
37+
$this->data[] = new DataPoint($dataPoint);
38+
}
39+
}
40+
}
41+
42+
/**
43+
* @return string
44+
*/
45+
public function getSummary()
46+
{
47+
return $this->summary;
48+
}
49+
50+
/**
51+
* @return string
52+
*/
53+
public function getIcon()
54+
{
55+
return $this->icon;
56+
}
57+
58+
/**
59+
* @return DataPoint[]
60+
*/
61+
public function getData()
62+
{
63+
return $this->data;
64+
}
65+
}

0 commit comments

Comments
 (0)