wwo 0.3.4 → 0.3.5
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/wwo.rb +52 -1
- data/lib/wwo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a076a4d5c336c3d2e63e0ab8e7400dd089264d1
|
4
|
+
data.tar.gz: ea747d1cfaf4f52eda78ed741b0aff8905e54457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 228ff65f744f58bb7820bca7779aca3ebc261ef6313b9fa2c28e1ea00c8c657579848a909a4c4c08bf69d2dbd387264734289156070a10910d260a428c0dc357
|
7
|
+
data.tar.gz: 6ae0e0b0a6ae53794acf559e459c0536c4e7d7b4389a160b8d7491eddb4580667e8d0c1d39bfe0614ab582eba40063457677a58df51933e0ad7e56b7aec368cd
|
data/lib/wwo.rb
CHANGED
@@ -14,10 +14,61 @@ module Wwo
|
|
14
14
|
|
15
15
|
class << self
|
16
16
|
|
17
|
+
def date_range(start_date, end_date, latitude, longitude, forecast_compat = false)
|
18
|
+
start_date_string = start_date.strftime('%F')
|
19
|
+
end_date_string = end_date.strftime('%F')
|
20
|
+
today_date_string = Time.now.strftime('%F')
|
21
|
+
|
22
|
+
if start_date_string == today_date_string || range_in_future?(start_date, end_date)
|
23
|
+
uri = "#{Wwo.api_endpoint}/weather.ashx?q=#{latitude},#{longitude}&format=json&num_of_days=7&date=today&cc=no&mca=no&tp=24&key=#{Wwo.api_key}"
|
24
|
+
response = Hashie::Mash.new(api_call(uri))
|
25
|
+
if forecast_compat
|
26
|
+
return make_into_forecast_response(response)
|
27
|
+
else
|
28
|
+
return response
|
29
|
+
end
|
30
|
+
|
31
|
+
elsif starts_in_past_but_ends_in_future?(start_date, end_date)
|
32
|
+
yesterday_date_string = (Time.now - (24 *(60 * 60))).strftime('%F')
|
33
|
+
|
34
|
+
uri = "#{Wwo.api_endpoint}/past-weather.ashx?q=#{latitude},#{longitude}&format=json&extra=utcDateTime&date=#{start_date_string}&enddate=#{yesterday_date_string}&show_comments=no&tp=24&key=#{Wwo.api_key}&mca=false&show_comments=false"
|
35
|
+
past_response = Hashie::Mash.new(api_call(uri))
|
36
|
+
uri = "#{Wwo.api_endpoint}/weather.ashx?q=#{latitude},#{longitude}&format=json&num_of_days=7&date=today&cc=no&mca=no&tp=24&key=#{Wwo.api_key}"
|
37
|
+
future_response = Hashie::Mash.new(api_call(uri))
|
38
|
+
|
39
|
+
if forecast_compat
|
40
|
+
past = make_into_forecast_response(past_response)
|
41
|
+
future = make_into_forecast_response(future_response)
|
42
|
+
past[:daily][:data] = (past[:daily][:data] + future[:daily][:data]).flatten.uniq
|
43
|
+
|
44
|
+
return past
|
45
|
+
else
|
46
|
+
return past_response.deep_merge(future_response)
|
47
|
+
end
|
48
|
+
|
49
|
+
else
|
50
|
+
uri = "#{Wwo.api_endpoint}/past-weather.ashx?q=#{latitude},#{longitude}&format=json&extra=utcDateTime&date=#{start_date_string}&enddate=#{end_date_string}&show_comments=no&tp=24&key=#{Wwo.api_key}&mca=false&show_comments=false"
|
51
|
+
response = Hashie::Mash.new(api_call(uri))
|
52
|
+
if forecast_compat
|
53
|
+
return make_into_forecast_response(response)
|
54
|
+
else
|
55
|
+
return response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def starts_in_past_but_ends_in_future?(start_date, end_date)
|
61
|
+
start_date.to_i < Time.now.to_i && end_date.to_i >= Time.now.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def range_in_future?(start_date, end_date)
|
65
|
+
end_date.to_i >= Time.now.to_i && start_date.to_i >= Time.now.to_i
|
66
|
+
end
|
67
|
+
|
17
68
|
# Returns a daily breakdown for weather for the provided start and end data at the
|
18
69
|
# specified location.
|
19
70
|
#
|
20
|
-
def
|
71
|
+
def old_date_range(start_date, end_date, latitude, longitude, forecast_compat = false)
|
21
72
|
starting = start_date.strftime('%F')
|
22
73
|
ending = end_date.strftime('%F')
|
23
74
|
|
data/lib/wwo/version.rb
CHANGED