vue-weather-widget
Advanced tools
Comparing version 4.0.4 to 4.1.0
{ | ||
"name": "vue-weather-widget", | ||
"version": "4.0.4", | ||
"version": "4.1.0", | ||
"description": "Weather forecast widget for Vuejs using DarkSky api", | ||
@@ -5,0 +5,0 @@ "exportName": "vue-weather-widget", |
@@ -99,16 +99,17 @@ # Vue Weather Widget | ||
| Props | Type | Default | Description | | ||
| ----------------- | ------------------- | -------- | ------------------------------------------------------------------------------------------------------------------ | | ||
| api-key | String (_required_) | - | Your OpenWeatherMap or Dark Sky API key | | ||
| use-dark-sky-api | Boolean | `false` | Use DarkSky API instead of OpenWeatherMap | | ||
| address | String | current | An address of a location (By default, it will be use user's IP to find current location) | | ||
| latitude | String | current | The latitude of a location (By default, it will be use user's IP to find current location) | | ||
| longitude | String | current | The longitude of a location (By default, it will be use user's IP to find current location) | | ||
| language | String | `"en"` | A list of supported languages are given below. | | ||
| units | String | `"us"` | A list of supported units are given below. | | ||
| hide-header | Boolean | `false` | Whether to show or hide the title bar. | | ||
| update-interval | Number | `null` | Interval in _milliseconds_ to update weather data periodically. Seting it to `0` or `null` to disables autoupdate. | | ||
| disable-animation | Boolean | `false` | Use static icons when enabled. | | ||
| bar-color | String | `"#444"` | Color of the Temparature bar. | | ||
| text-color | String | `"#333"` | Color of the text. | | ||
| Props | Type | Default | Description | | ||
| ----------------- | ------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------- | | ||
| api-key | String (_required_) | - | Your OpenWeatherMap or Dark Sky API key | | ||
| use-dark-sky-api | Boolean | `false` | Use DarkSky API instead of OpenWeatherMap | | ||
| address | String | current | An address of a location (By default, it will use IP to find address) | | ||
| latitude | String | current | The latitude of a location (By default, it will use IP to find location) | | ||
| longitude | String | current | The longitude of a location (By default, it will use IP to find location) | | ||
| language | String | `"en"` | A list of supported languages are given below. | | ||
| units | String | `"us"` | A list of supported units are given below. | | ||
| hide-header | Boolean | `false` | Whether to show or hide the title bar. | | ||
| update-interval | Number | `null` | Interval in _milliseconds_ to update weather data periodically. Set it to `0` or `null` to disable autoupdate. | | ||
| disable-animation | Boolean | `false` | Use static icons when enabled. | | ||
| bar-color | String | `"#444"` | Color of the Temparature bar. | | ||
| text-color | String | `"#333"` | Color of the text. | | ||
| positionstack-api | String | `"c3bb8aa0a56b21122dea6a2a8ada70c8"` | (optional) You positionstack api key for geocoding. | | ||
@@ -115,0 +116,0 @@ ## Slots |
@@ -83,2 +83,8 @@ import Utils from "./utils"; | ||
}, | ||
// Your positionstack api key for geocoding | ||
positionstackApi: { | ||
type: String, | ||
default: "c3bb8aa0a56b21122dea6a2a8ada70c8", | ||
}, | ||
}, | ||
@@ -222,3 +228,3 @@ | ||
} else { | ||
return Utils.geocode(this.address).then((data) => { | ||
return Utils.geocode(this.positionstackApi, this.address).then((data) => { | ||
this.$set(this, "location", { | ||
@@ -232,9 +238,11 @@ lat: data.latitude, | ||
} else { | ||
return Utils.reverseGeocode(this.latitude, this.longitude).then((data) => { | ||
this.$set(this, "location", { | ||
lat: this.latitude, | ||
lng: this.longitude, | ||
name: `${data.region}, ${data.country}`, | ||
}); | ||
}); | ||
return Utils.reverseGeocode(this.positionstackApi, this.latitude, this.longitude).then( | ||
(data) => { | ||
this.$set(this, "location", { | ||
lat: this.latitude, | ||
lng: this.longitude, | ||
name: `${data.region}, ${data.country}`, | ||
}); | ||
} | ||
); | ||
} | ||
@@ -241,0 +249,0 @@ }, |
@@ -76,3 +76,3 @@ import jsonp from "jsonp"; | ||
geocode(query, reversed = false) { | ||
geocode(apiKey, query, reversed = false) { | ||
let cache = localStorage[GEOCODE_CACHE] || "{}"; | ||
@@ -84,7 +84,10 @@ cache = JSON.parse(cache); | ||
const apiKey = "c3bb8aa0a56b21122dea6a2a8ada70c8"; | ||
apiKey = apiKey || "c3bb8aa0a56b21122dea6a2a8ada70c8"; | ||
const apiType = reversed ? "reverse" : "forward"; | ||
return fetch(`http://api.positionstack.com/v1/${apiType}?access_key=${apiKey}&query=${query}`) | ||
return fetch(`//api.positionstack.com/v1/${apiType}?access_key=${apiKey}&query=${query}`) | ||
.then((resp) => resp.json()) | ||
.then((result) => { | ||
if (result.error) { | ||
throw new Error("(api.positionstack.com) " + result.error.message); | ||
} | ||
cache[query] = result.data[0]; | ||
@@ -97,4 +100,4 @@ localStorage[GEOCODE_CACHE] = JSON.stringify(cache); | ||
reverseGeocode(lat, lng) { | ||
return utils.geocode(`${lat},${lng}`, true); | ||
reverseGeocode(apiKey, lat, lng) { | ||
return utils.geocode(apiKey, `${lat},${lng}`, true); | ||
}, | ||
@@ -120,5 +123,5 @@ | ||
(err, data) => { | ||
console.log(err, data); | ||
if (err) reject(err); | ||
else resolve(data); | ||
console.error(err, data); | ||
} | ||
@@ -125,0 +128,0 @@ ); |
37856
519
171