Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Add option to configure temperature units.
Browse files Browse the repository at this point in the history
Fixes #3.
  • Loading branch information
kejadlen committed Dec 14, 2014
1 parent 0c228fa commit 86d3a83
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.6 - 2014.12.13
### Added
- Add option to force Celsius/Fahrenheit using `FORECAST_UNITS`.

## 0.0.5 - 2014.11.22
### Changed
- Use `forecast-config` for managing API keys.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Run `forecast-config VALUE` to set API keys and the default location:
- `DEFAULT_LOCATION`: Ex. "Seattle, WA".
- `DEFAULT_LAT_LONG`: Only required if `GOOGLE_API_KEY` is unavailable, since
`DEFAULT_LOCATION` can't be geocoded. Format: `lat,long`.
- `FORECAST_UNITS`: Defaults to `auto`, which sets the units based on the
location. Use `si` for Celsius and `us` for Fahrenheit.

[forecast-api-key]: https://developer.forecast.io/register
[google-api-key]: https://developers.google.com/maps/documentation/geocoding/#api_key
Expand Down
3 changes: 2 additions & 1 deletion alfred.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def self.config
@config = self.new(bundle_id)
end

DEFAULTS = { 'FORECAST_UNITS' => 'auto' }
WORKFLOW_DATA = '~/Library/Application Support/Alfred 2/Workflow Data/'

attr_reader :path
Expand All @@ -78,7 +79,7 @@ def initialize(bundle_id)
end

def [](key)
config.fetch(key) { '' }
config.fetch(key) { DEFAULTS.fetch(key) { '' } }
end

def []=(key, value)
Expand Down
3 changes: 2 additions & 1 deletion config-forecast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
OPTIONS = %w[ FORECAST_API_KEY
GOOGLE_API_KEY
DEFAULT_LOCATION
DEFAULT_LAT_LONG ]
DEFAULT_LAT_LONG
FORECAST_UNITS ]

input = ARGV.shift || ''

Expand Down
3 changes: 2 additions & 1 deletion forecaster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def self.forecaster

def forecast(location)
lat, long = location.lat, location.long
url = "https://api.forecast.io/forecast/#{api_key}/#{lat},#{long}?units=auto"
units = Alfred::Config['FORECAST_UNITS']
url = "https://api.forecast.io/forecast/#{api_key}/#{lat},#{long}?units=#{units}"
response = JSON.load(open(url))
end
end
Expand Down

0 comments on commit 86d3a83

Please sign in to comment.