Skip to content

Commit 8998ca4

Browse files
committed
Change location of ini file.
1 parent 3f664d4 commit 8998ca4

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

Cmfcmf/OpenWeatherMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ private function buildQueryUrlParameter($query)
444444
case is_string($query):
445445
return 'q='.urlencode($query);
446446
default:
447-
throw new \InvalidArgumentException('Error: $query has the wrong format. See the documentation of OpenWeatherMap::getRawData() to read about valid formats.');
447+
throw new \InvalidArgumentException('Error: $query has the wrong format. See the documentation of OpenWeatherMap::getWeather() to read about valid formats.');
448448
}
449449
}
450450

Examples.ini.tmpl

Lines changed: 0 additions & 3 deletions
This file was deleted.

Examples/ApiKey.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[OpenWeatherMap]
2+
# Get an API Key from http://home.openweathermap.org/
3+
api_key = 2f8796eefe67558dc205b09dd336d022
4+

Examples/Cache.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@ public function setCached($url, $content)
8181
}
8282
}
8383

84+
// Load the api key.
85+
$ini = parse_ini_file('ApiKey.ini');
86+
$myApiKey = $ini['api_key'];
87+
8488
// Language of data (try your own language here!):
8589
$lang = 'de';
8690

8791
// Units (can be 'metric' or 'imperial' [default]):
8892
$units = 'metric';
8993

9094
// Example 1: Use your own cache implementation. Cache for 10 seconds only in this example.
91-
$owm = new OpenWeatherMap(null, new ExampleCache(), 10);
95+
$owm = new OpenWeatherMap($myApiKey, null, new ExampleCache(), 10);
9296

9397
$weather = $owm->getWeather('Berlin', $units, $lang);
9498
echo "EXAMPLE 1<hr />\n\n\n";

Examples/CurrentWeather.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
require '../../../autoload.php';
2727
}
2828

29-
// Load the app configuration
30-
$ini = parse_ini_file('../Examples.ini');
29+
// Load the api key.
30+
$ini = parse_ini_file('ApiKey.ini');
3131
$myApiKey = $ini['api_key'];
3232

3333
// Language of data (try your own language here!):
@@ -235,9 +235,3 @@
235235
echo 'General exception: '.$e->getMessage().' (Code '.$e->getCode().').';
236236
echo "<br />\n";
237237
}
238-
239-
// Example 15: Using an api key:
240-
echo "<br /><br />\n\n\nEXAMPLE 15<hr />\n\n\n";
241-
$weather = $owm->getWeather('Berlin', $units, $lang, $myApiKey);
242-
echo $weather->temperature."\n";
243-
echo "<br />\n";

Examples/WeatherForecast.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
require('../../../autoload.php');
2727
}
2828

29-
// Load the app configuration
30-
$ini = parse_ini_file('../Examples.ini');
29+
// Load the api key.
30+
$ini = parse_ini_file('ApiKey.ini');
3131
$myApiKey = $ini['api_key'];
3232

3333
// Language of data (try your own language here!):
@@ -37,8 +37,7 @@
3737
$units = 'metric';
3838

3939
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
40-
$owm = new OpenWeatherMap();
41-
$owm->setApiKey($myApiKey);
40+
$owm = new OpenWeatherMap($myApiKey);
4241

4342
// Example 1: Get forecast for the next 10 days for Berlin.
4443
$forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 10);
@@ -71,4 +70,4 @@
7170
echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i') . "<br />";
7271
echo $weather->temperature . "<br />\n";
7372
echo "---<br />\n";
74-
}
73+
}

Examples/WeatherHistory.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
require '../../../autoload.php';
2626
}
2727

28-
// Load the app configuration
29-
$ini = parse_ini_file('../Examples.ini');
28+
// Load the api key.
29+
$ini = parse_ini_file('ApiKey.ini');
3030
$myApiKey = $ini['api_key'];
3131

3232
// Language of data (try your own language here!):
@@ -36,12 +36,11 @@
3636
$units = 'metric';
3737

3838
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
39-
$owm = new OpenWeatherMap();
40-
$owm->setApiKey($myApiKey);
39+
$owm = new OpenWeatherMap($myApiKey);
4140

4241
// Example 1: Get hourly weather history between 2014-01-01 and today.
4342
$history = $owm->getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang);
4443

4544
foreach ($history as $weather) {
4645
echo 'Average temperature at '.$weather->time->format('d.m.Y H:i').': '.$weather->temperature."\n\r<br />";
47-
}
46+
}

0 commit comments

Comments
 (0)