Skip to content

Commit

Permalink
Added required api key field. See: http://openweathermap.org/appid (#15)
Browse files Browse the repository at this point in the history
* Added api key now required. See: http://openweathermap.org/appid

* Added readme info for api key
  • Loading branch information
Josh Morrissey authored and schneiderderek committed Aug 23, 2016
1 parent 8902c8e commit 08f802a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Displays the temperature and other weather related information in the status bar

More features coming soon, feel free to put in requests or contribute!

## Api Key

Registration for a free api key at [openweathermap.org](http://openweathermap.org/appid) is required. Click the "Sign Up" button and then copy your unique api key into your atom-weather configuration.

If you are getting the error message "cannot load weather", check that the api key entered in configuration matches the one you were provided by openweathermap.org.


## Configuration

Configuration for weather can be found by going to: settings > packages > weather and click on settings.
Expand All @@ -16,6 +23,7 @@ The following configuration options are available, shown in the order they appea

| Name | Description | Default |
| ------------- | ------------- | ----------- |
| Api Key | Obtain from http://openweathermap.org/appid. | |
| Latitude | Latitude (ignored if zipcode location method choosen) | 0 |
| Location Method | Whether to use zipcode or lat/long | zipcode |
| Longitude | Longitude (ignored if zipcode location method choosen) | 0 |
Expand Down
7 changes: 5 additions & 2 deletions lib/weather-data.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ class WeatherData
latitude: ->
atom.config.get('weather.latitude')

apikey: ->
atom.config.get('weather.apikey')

currentWeatherUrl: ->

if @locationMethod() == 'zipcode'
location = "zip=#{@apiZipcodeFormat()}"
else
location = "lon=#{@longitude()}&lat=#{@latitude()}"

"http://api.openweathermap.org/data/2.5/weather?units=#{@units()}&#{location}"
"http://api.openweathermap.org/data/2.5/weather?units=#{@units()}&#{location}&APPID=#{@apikey()}"

forecastWeatherUrl: ->
lat = @location.lat
lon = @location.lon
return null unless lat? && lon?
"http://api.openweathermap.org/data/2.5/forecast/daily?lat=#{lat}&lon=#{lon}&units=#{@units()}&cnt=1"
"http://api.openweathermap.org/data/2.5/forecast/daily?lat=#{lat}&lon=#{lon}&units=#{@units()}&cnt=1&APPID=#{@apikey()}"

parseUnixTimestamp: (timestamp) ->
new Date(timestamp * 1000)
Expand Down
3 changes: 3 additions & 0 deletions lib/weather.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ module.exports = Weather =
longitude:
type: 'number'
default: 0.0
apikey:
type: 'string'
default: "http://openweathermap.org/appid"

consumeStatusBar: (statusBar) ->
@statusBarTile = statusBar.addRightTile(item: @weatherView, priority: 100)
Expand Down

0 comments on commit 08f802a

Please sign in to comment.