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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wwo.rb +52 -1
  3. data/lib/wwo/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cec9c308673d100b324ac161fd5417c94917dc5
4
- data.tar.gz: 15e89edc4574ea9ecb1358454671642280116973
3
+ metadata.gz: 3a076a4d5c336c3d2e63e0ab8e7400dd089264d1
4
+ data.tar.gz: ea747d1cfaf4f52eda78ed741b0aff8905e54457
5
5
  SHA512:
6
- metadata.gz: cd0b1dfd6df7c88c429cb643add5b39f17bc6ec2d2e051b85beaed3cae7d54e9e08225dae5e0ec44bb4ae7888e0bf6552d69effcd1fd056091d612ee0fb720de
7
- data.tar.gz: 0e59dfcd54c73f5baf6f428f26919fd245c5c1aaef95c5a01725eb1430d8c637ec7b8be16d3e4dbbcd4877878c4e2cc9134299ffcbe967e3d70b4b83a4e3560a
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 date_range(start_date, end_date, latitude, longitude, forecast_compat = false)
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
@@ -1,3 +1,3 @@
1
1
  module Wwo
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wwo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 株式会社アルム Allm Inc