Skip to content

Commit 0227eaa

Browse files
committed
3.0.0 Release
1 parent 08e46aa commit 0227eaa

15 files changed

+322
-115
lines changed

CHANGESLOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## 3.0.0 - Upcoming
4+
## 3.0.0 - 2017-12-09
55

66
### Changed
77
Now that Climatempo provides a decent API for developers, we moved from
8-
scraping a xml to using said API.
9-
8+
scraping a xml file to using said API.
109

1110
The new API needs an access token, this token can be generated after creating
1211
an account in advisor.climatempo.com.br
1312

13+
It is no longer possible to get information for more than one city per request.
14+
15+
Now with the new API, a great deal more of data is available and the arrays that
16+
returned from the requests were replaced with objects.
17+
18+
Upon error, the requests to the API will throw Exceptions.
1419

1520
## 2.0.2 - 2017-09-02
1621

README.en.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
# Climatempo API
3+
4+
*Read this in other languages: [Portuguese](README.md)
5+
6+
[Climatempo](http://www.climatempo.com.br) is a weather forecast service for brazilian cities.
7+
They offer a REST API for developers and the goal of this library is to
8+
make it simple to request forecasts using said API.
9+
10+
## How to install
11+
12+
Use composer
13+
14+
```bash
15+
composer require adinan-cenci/climatempo-api
16+
```
17+
18+
## How can I acquire an access token?
19+
Access [advisor.climatempo.com.br](http://advisor.climatempo.com.br) and create an account.
20+
21+
## How to use it
22+
Let's say we want the forecast for São Paulo - SP.
23+
We'll need the id for this city:
24+
25+
```php
26+
27+
use AdinanCenci\Climatempo\Climatempo;
28+
29+
$token = 'insert-your-token-here';
30+
$id = 3477; /*São paulo*/
31+
32+
$climatempo = new Climatempo($token);
33+
$forecast = $climatempo->fifteenDays($id);
34+
35+
36+
foreach ($forecast->days as $dia) {
37+
echo
38+
"City: <b>$forecast->city ($dia->date)</b>: <br>
39+
Min. temperature: $dia->minTemp °C <br>
40+
Max. temperature: $dia->maxTemp °C <br>
41+
Probability of precipitation: $dia->pop % <br>
42+
Precipitation: $dia->mm mm <br>
43+
Phrase: $dia->textPt <hr>";
44+
}
45+
```
46+
47+
Vai resultar em:
48+
49+
City: **São Paulo (2017-12-06)**:
50+
Min. temperature: 21 °C
51+
Max. temperature: 32 °C
52+
Probability of precipitation: %
53+
Precipitation: mm
54+
Phrase: Sol com algumas nuvens
55+
___
56+
57+
City: **São Paulo (2017-12-07)**:
58+
Min. temperature: 18 °C
59+
Max. temperature: 24 °C
60+
Probability of precipitation: 75 %
61+
Precipitation: 2 mm
62+
Phrase: Sol e Chuva
63+
___
64+
65+
City: **São Paulo (2017-12-08)**:
66+
Min. temperature: 16 °C
67+
Max. temperature: 20 °C
68+
Probability of precipitation: 75 %
69+
Precipitation: 3 mm
70+
Phrase: Sol e Chuva
71+
___
72+
73+
74+
## How to get a city's forecast without it's ID?
75+
Unfortunately climatempo uses their own system, each city has it's own ID.
76+
But you can easily use the Search class to find the city you are looking for.
77+
78+
Let's say we want the forecast for Rio de Janeiro - RJ:
79+
80+
```php
81+
82+
use AdinanCenci\Climatempo\Search;
83+
84+
$searching = new Search();
85+
$searching->name('rio de janeiro');
86+
87+
$rio = $searching->find()[0]; // object City
88+
89+
```
90+
91+
Then you can get the forecast by using the methods below:
92+
93+
```php
94+
95+
$rio->fifteenDays($token); // returns the forecast for the next 15 days
96+
$rio->seventyTwoHours($token); // returns the forecast for the next 72 hours
97+
$rio->current($token); // returns the current state of the weather
98+
99+
$rio->today($token); // returns the forecast for today
100+
$rio->tomorow($token); // returns the forecast for tomorow
101+
$rio->afterTomorow($token); // returns the forecast for the day after tomorow
102+
103+
```
104+
105+
## Searching
106+
Speaking about searching, the Search class allow us to narrow down to the state.
107+
The example below will search for all the cities with "rio" in it's name, inside the Rio de Janeiro state.
108+
109+
```php
110+
111+
use AdinanCenci\Climatempo\Search;
112+
113+
$searching = new Search();
114+
$searching
115+
->name('rio')
116+
->state('RJ');
117+
118+
$searching->find(); // returns array
119+
120+
```
121+
122+
See other examples inside the directory "examples".
123+
124+
## License
125+
License MIT

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@ Use composer
1515
composer require adinan-cenci/climatempo-api
1616
```
1717

18+
## Aonde consigo o token de acesso?
19+
Acesse [advisor.climatempo.com.br](http://advisor.climatempo.com.br) e crie uma conta.
1820

1921
## Como usar
20-
2122
Digamos que nós queremos a previsão para São Paulo - SP.
2223
Nós vamos precisar do id para essa cidade:
2324

2425
```php
2526

2627
use AdinanCenci\Climatempo\Climatempo;
2728

28-
$token = 'seuTokenAqui';
29+
$token = 'seu-token-aqui';
2930
$id = 3477; /*São paulo*/
3031

3132
$climatempo = new Climatempo($token);
3233
$previsao = $climatempo->fifteenDays($id);
3334

3435

3536
foreach ($previsao->days as $dia) {
36-
echo "
37-
Cidade: <b>$previsao->city ($dia->date)</b>: <br>
37+
echo
38+
"Cidade: <b>$previsao->city ($dia->date)</b>: <br>
3839
Temp. mínima: $dia->minTemp °C <br>
3940
Temp. máxima: $dia->maxTemp °C <br>
40-
Probal. de precipitação: $dia->pop % <br>
41+
Probab. de precipitação: $dia->pop % <br>
4142
Precipitação: $dia->mm mm <br>
4243
Frase: $dia->textPt <hr>";
4344
}
@@ -48,30 +49,29 @@ Vai resultar em:
4849
Cidade: **São Paulo (2017-12-06)**:
4950
Temp. mínima: 21 °C
5051
Temp. máxima: 32 °C
51-
Probal. de precipitação: %
52+
Probab. de precipitação: %
5253
Precipitação: mm
5354
Frase: Sol com algumas nuvens
5455
___
5556

5657
Cidade: **São Paulo (2017-12-07)**:
5758
Temp. mínima: 18 °C
5859
Temp. máxima: 24 °C
59-
Probal. de precipitação: 75 %
60+
Probab. de precipitação: 75 %
6061
Precipitação: 2 mm
6162
Frase: Sol e Chuva
6263
___
6364

6465
Cidade: **São Paulo (2017-12-08)**:
6566
Temp. mínima: 16 °C
6667
Temp. máxima: 20 °C
67-
Probal. de precipitação: 75 %
68+
Probab. de precipitação: 75 %
6869
Precipitação: 3 mm
6970
Frase: Sol e Chuva
7071
___
7172

7273

7374
## Como ter a previsão de uma cidade sem saber o ID?
74-
7575
Infelizmente o climatempo usa seu próprio sistema, cada cidade brasileira tem seu próprio ID.
7676
Mas você pode facilmente usar a classe Search para encontrar a cidade que procura.
7777

@@ -93,13 +93,16 @@ Então você pode acessar a previsão através dos seguintes metodos:
9393
```php
9494

9595
$rio->fifteenDays($token); // retorna a previsão para os próximos 15 dias
96-
$rio->seventyTwoHours($token); // retorna a previsão para as próximas 72 dias
96+
$rio->seventyTwoHours($token); // retorna a previsão para as próximas 72 horas
9797
$rio->current($token); // retorna o estado do clima neste instante
9898

99+
$rio->today($token); // retorna a previsão para hoje
100+
$rio->tomorow($token); // retorna a previsão para amanhã
101+
$rio->afterTomorow($token); // retorna a previsão para depois de amanhã
102+
99103
```
100104

101105
## Pesquisando
102-
103106
Falando em pesquisa, a classe Search nos permite a restringir a busca à estados.
104107
O exemplo abaixo vai pesquisar por todas as cidades com "rio" no nome no estado do Rio de Janeiro.
105108

@@ -119,5 +122,4 @@ $pesquisa->find(); // retorna array
119122
Veja outros exemplos na pasta "examples".
120123

121124
## Licença
122-
123125
Licença MIT

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "library",
55
"keywords": ["api", "previsão do tempo", "weather", "forecast"],
66
"license": "MIT",
7-
"version": "2.0.2",
7+
"version": "3.0.0",
88
"authors": [
99
{
1010
"name": "Adinan Cenci",

examples/1-fifteen-days-forecast.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@
2121

2222
$id = 3477; // São Paulo - SP
2323

24-
$f = $climatempo->fifteenDays($id);
24+
try {
25+
$forecast = $climatempo->fifteenDays($id);
26+
} catch (Exception $e) {
27+
echo '<b>Error: </b>'.$e->getMessage();
28+
die();
29+
}
2530

2631
echo
27-
"<h2>$f->name / $f->state - $f->country</h2>";
32+
"<h2>$forecast->name / $forecast->state - $forecast->country</h2>";
2833

2934

30-
foreach ($f->data as $day) {
35+
foreach ($forecast->data as $day) {
3136
echo
3237
"<table class=\"forecast\">
3338
<caption>
34-
$day->date - $day->textPt - $day->dateBr
39+
$day->date - $day->textPt - $day->dateBr (Timestamp: $day->timestamp)
3540
</caption>
3641
<thead>
3742
<tr>
@@ -47,15 +52,15 @@
4752
<td rowspan=\"3\" class=\"resume\">
4853
<img src=\"resources/images/$day->dayIcon.png\" /> <br>
4954
50-
<b class=\"temp-min\">$day->minTemp °C</b> -
51-
<b class=\"temp-max\">$day->maxTemp °C</b> <br>
55+
<b class=\"temp-min\">$day->minTemperature °C</b> -
56+
<b class=\"temp-max\">$day->maxTemperature °C</b> <br>
5257
<br>
5358
Thermal Sensation <br>
5459
<br>
55-
<b class=\"temp-min\">$day->minThermal °C</b> -
56-
<b class=\"temp-max\">$day->maxThermal °C</b> <br>
60+
<b class=\"temp-min\">$day->minThermalSensation °C</b> -
61+
<b class=\"temp-max\">$day->maxThermalSensation °C</b> <br>
5762
58-
$day->reducedText
63+
$day->resume
5964
</td>
6065
<td>
6166
Min: $day->minHumidity% <br>
@@ -90,24 +95,24 @@
9095
<td>
9196
<img src=\"resources/images/$day->morningIcon.png\" /> <br>
9297
93-
<b class=\"temp-min\">$day->minMorningTemp °C</b> -
94-
<b class=\"temp-max\">$day->maxMorningTemp °C</b> <br>
98+
<b class=\"temp-min\">$day->minMorningTemperature °C</b> -
99+
<b class=\"temp-max\">$day->maxMorningTemperature °C</b> <br>
95100
96101
$day->morningText
97102
</td>
98103
<td>
99104
<img src=\"resources/images/$day->afternoonIcon.png\" /> <br>
100105
101-
<b class=\"temp-min\">$day->minAfternoonTemp °C</b> -
102-
<b class=\"temp-max\">$day->maxAfternoonTemp °C</b> <br>
106+
<b class=\"temp-min\">$day->minAfternoonTemperature °C</b> -
107+
<b class=\"temp-max\">$day->maxAfternoonTemperature °C</b> <br>
103108
104109
$day->afternoonText
105110
</td>
106111
<td>
107112
<img src=\"resources/images/$day->nightIcon.png\" /> <br>
108113
109-
<b class=\"temp-min\">$day->minNightTemp °C</b> -
110-
<b class=\"temp-max\">$day->maxNightTemp °C</b> <br>
114+
<b class=\"temp-min\">$day->minNightTemperature °C</b> -
115+
<b class=\"temp-max\">$day->maxNightTemperature °C</b> <br>
111116
112117
$day->nightText
113118
</td>
@@ -116,8 +121,4 @@
116121
</table>";
117122
}
118123

119-
120-
require 'resources/footer.html';
121-
?>
122-
123-
124+
require 'resources/footer.html';

examples/2-seventy-two-hours-forecast.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121

2222
$id = 3477; // São Paulo - SP
2323

24-
$f = $climatempo->seventyTwoHours($id);
24+
try {
25+
$forecast = $climatempo->seventyTwoHours($id);
26+
} catch (Exception $e) {
27+
echo '<b>Error: </b>'.$e->getMessage();
28+
die();
29+
}
2530

2631
echo
27-
"<h2>$f->name / $f->state - $f->country</h2>";
32+
"<h2>$forecast->name / $forecast->state - $forecast->country</h2>";
2833

2934

30-
foreach ($f->data as $day) {
35+
foreach ($forecast->data as $day) {
3136
echo
3237
"<table class=\"forecast\">
3338
<caption>
@@ -58,8 +63,4 @@
5863
</table>";
5964
}
6065

61-
6266
require 'resources/footer.html';
63-
?>
64-
65-

0 commit comments

Comments
 (0)