lita-onewheel-forecast-io 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lita/handlers/utils.rb +21 -3
- data/lita-onewheel-forecast-io.gemspec +1 -1
- data/spec/lita/handlers/forecast_io_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4b44a03d3d25a90686c1988820639d662f072cd
|
4
|
+
data.tar.gz: a523d787ccd37b49e40658bd372383eec8033735
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d88668247347f49f22d655b7b9b18d9e18038f6751afa8773a55d2fb20fcd890235e3f362fe71e67244f6e052caa794624066799a75831fe536ca8247ce995ee
|
7
|
+
data.tar.gz: 03b5fa29ac34e836735a63374322e895fc6475ee329b8e1d7e82f88e873e354cf8fd0909a56e2b51cda4bc4f391db4ac6888d19e2d173cd7627823f19605acc8
|
data/lib/lita/handlers/utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'geocoder'
|
1
2
|
module ForecastIo
|
2
3
|
module Utils
|
3
4
|
REDIS_KEY = 'forecast_io'
|
@@ -55,8 +56,21 @@ module ForecastIo
|
|
55
56
|
geocoded
|
56
57
|
end
|
57
58
|
|
59
|
+
# Perform a geocoder lookup based on a) the query or b) the user's serialized state.
|
60
|
+
# If neither of those exist, default to Portland.
|
58
61
|
def geo_lookup(user, query)
|
59
62
|
Lita.logger.debug "Performing geolookup for '#{user.name}' for '#{query}'"
|
63
|
+
|
64
|
+
default_location = {
|
65
|
+
'formatted_address' => 'Portland, OR',
|
66
|
+
'geometry' => {
|
67
|
+
'location' => {
|
68
|
+
'lat' => 45.5230622,
|
69
|
+
'lng' => -122.6764816
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
60
74
|
if query.nil? or query.empty?
|
61
75
|
Lita.logger.debug "No query specified, pulling from redis #{REDIS_KEY}, #{user.name}"
|
62
76
|
serialized_geocoded = redis.hget(REDIS_KEY, user.name)
|
@@ -67,9 +81,6 @@ module ForecastIo
|
|
67
81
|
end
|
68
82
|
|
69
83
|
Lita.logger.debug "q & g #{query.inspect} #{geocoded.inspect}"
|
70
|
-
if (query.nil? or query.empty?) and geocoded.nil?
|
71
|
-
query = 'Portland, OR'
|
72
|
-
end
|
73
84
|
|
74
85
|
unless geocoded
|
75
86
|
Lita.logger.debug "Redis hget failed, performing lookup for #{query}"
|
@@ -78,6 +89,13 @@ module ForecastIo
|
|
78
89
|
redis.hset(REDIS_KEY, user.name, geocoded.to_json)
|
79
90
|
end
|
80
91
|
|
92
|
+
# Let's set up the defaults in the event that the geocoder fails.
|
93
|
+
# See https://github.com/onewheelskyward/lita-onewheel-forecast-io/issues/34
|
94
|
+
unless geocoded
|
95
|
+
Lita.logger.debug "Geocoded was #{geocoded.inspect}, setting to default."
|
96
|
+
geocoded = default_location
|
97
|
+
end
|
98
|
+
|
81
99
|
Lita.logger.debug "geocoded: '#{geocoded}'"
|
82
100
|
|
83
101
|
loc = Location.new(
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-forecast-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.
|
221
|
+
rubygems_version: 2.5.1
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: A text-based interactive query engine for http://forecast.io's api.
|