Skip to content

Commit

Permalink
Allow input custom weather api key
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDam committed May 2, 2020
1 parent 1cf56c4 commit aed4edf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@
<property id="enable_buffering" type="boolean">false</property>

<property id="barometer_unit" type="number">0</property>

<property id="openweathermap_api" type="string"></property>
</properties>
5 changes: 4 additions & 1 deletion resources/settings/settings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<settings>

<setting propertyKey="@Properties.theme_code" title="@Strings.theme_code">
<settingConfig type="list">
<listEntry value="0">@Strings.theme_dark</listEntry>
Expand Down Expand Up @@ -419,4 +419,7 @@
<listEntry value="1">@Strings.barometer_unit_1</listEntry>
</settingConfig>
</setting>
<setting propertyKey="@Properties.openweathermap_api" title="@Strings.openweathermap_api">
<settingConfig type="alphaNumeric" />
</setting>
</settings>
2 changes: 2 additions & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@
<string id="barometer_unit">Barometer Unit</string>
<string id="barometer_unit_0">Hector Pascal (Pa)</string>
<string id="barometer_unit_1">Inches of Mercury (inHg)</string>

<string id="openweathermap_api">OpenWeatherMap API key, read FAQs section for more info</string>
</strings>
8 changes: 7 additions & 1 deletion source/BackgroundService.mc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ class BackgroundService extends Sys.ServiceDelegate {
(:background_method)
function onTemporalEvent() {
Sys.println("onTemporalEvent");

var pendingWebRequests = App.getApp().getProperty("PendingWebRequests");
if (pendingWebRequests != null) {
if (pendingWebRequests["OpenWeatherMapCurrent"] != null) {

var api_key = App.getApp().getProperty("openweathermap_api");
if (api_key.length() == 0) {
api_key = "333d6a4283794b870f5c717cc48890b5"; // default apikey
}
makeWebRequest(
"https://api.openweathermap.org/data/2.5/weather",
{
"lat" => App.getApp().getProperty("LastLocationLat"),
"lon" => App.getApp().getProperty("LastLocationLng"),
"appid" => "333d6a4283794b870f5c717cc48890b5",
"appid" => api_key,
"units" => "metric" // Celcius.
},
method(:onReceiveOpenWeatherMapCurrent)
Expand Down

0 comments on commit aed4edf

Please sign in to comment.