weatheruby 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0283bd7d80946986810371b2c1741cf1b3f1aae
4
- data.tar.gz: f585d3e0608e1570ccb6a6a860dd28bc743bf3bd
3
+ metadata.gz: 4df1b7c19c8e24f493a06d5e6d2e1a9e171d367f
4
+ data.tar.gz: b2bd0127cdbba81ef3fecf12948eafa3b598229d
5
5
  SHA512:
6
- metadata.gz: 58e8d51797597fed248965638dabae7ca2c7fadbab3b9165bc32fb640b4ecda62d03acfd791ed8a7be45f1ce744e1358fb1c4d52483921e80a95a6e5ae2131e0
7
- data.tar.gz: bf73efcea967133048b018e1210592030144c4db4033ff4a5d02869410a4ff63959fa05dd34fb53e7adc586d412983388d7ccc3ec5eb908fa082fbe1558b61fb
6
+ metadata.gz: 0864852867eed9f0f47ba5b67324e47fc725fef086d99e3ccc2b87369bd68d7bc3c992e4a2767a875ed21d5af2009f27b63a83583c10b283e41e608090a82f13
7
+ data.tar.gz: e4d13673968de97a6ce69e2c4b72659b000513fa7de5f0aee4f898ee4190484cfc46002b999674c2ce97375516a035594d2ba0ed471cd39a07d7bee79720722b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
  ## Version 0
3
+ ### Version 0.5.0
4
+ * Add support for all Weather Underground Planner APIs.
5
+
3
6
  ### Version 0.4.2
4
7
  * No longer fails with an ArgumentError if the CLI is passed no arguments. Instead it outputs the usage information, so that it is actually a useful thing.
5
8
 
data/bin/weatheruby CHANGED
@@ -8,6 +8,12 @@ require 'rainbow'
8
8
  require 'string-utility'
9
9
  require_relative '../lib/weatheruby'
10
10
 
11
+ # Planner not supported here because it will eventually get its own CLI. That
12
+ # would be way too many API calls for a single app, when most of the info
13
+ # provided by the Planner would not even be useful.
14
+ # TODO Write the Planner CLI: weatheruby_planner or something.
15
+
16
+
11
17
  @args = {
12
18
  help: false,
13
19
  verbose: false,
@@ -0,0 +1,250 @@
1
+ module Weather
2
+ module Planner
3
+ # Gets the chance of snow within the date range.
4
+ # @see #get_planner_response
5
+ def chance_of_snow(start_date, end_date, location)
6
+ get_chance_of('chanceofsnowday', start_date, end_date, location)
7
+ end
8
+
9
+ # Gets the chance of hail within the date range.
10
+ # @see #get_planner_response
11
+ def chance_of_hail(start_date, end_date, location)
12
+ get_chance_of('chanceofhailday', start_date, end_date, location)
13
+ end
14
+
15
+ # Gets the chance of temperatures above 0 C/32 F within the date range.
16
+ # @see #get_planner_response
17
+ def chance_of_not_freezing(start_date, end_date, location)
18
+ get_chance_of('tempoverfreezing', start_date, end_date, location)
19
+ end
20
+
21
+ # Gets the chance of temperatures below 0 C/32 F within the date range.
22
+ # @see #get_planner_response
23
+ def chance_of_freezing(start_date, end_date, location)
24
+ get_chance_of('tempbelowfreezing', start_date, end_date, location)
25
+ end
26
+
27
+ # Gets chance of sultry within the date range.
28
+ # @see #get_planner_response
29
+ def chance_of_sultry(start_date, end_date, location)
30
+ get_chance_of('chanceofsultryday', start_date, end_date, location)
31
+ end
32
+
33
+ # Gets the chance of a tornado within the date range.
34
+ # @see #get_planner_response
35
+ def chance_of_tornado(start_date, end_date, location)
36
+ get_chance_of('chanceoftornadoday', start_date, end_date, location)
37
+ end
38
+
39
+ # Gets the chance of snow on the ground within the date range.
40
+ # @see #get_planner_response
41
+ def chance_of_groundsnow(start_date, end_date, location)
42
+ get_chance_of('chanceofsnowonground', start_date, end_date, location)
43
+ end
44
+
45
+ # Gets the chance of thunderstorms within the date range.
46
+ # @see #get_planner_response
47
+ def chance_of_thunderstorms(start_date, end_date, location)
48
+ get_chance_of('chanceofthunderday', start_date, end_date, location)
49
+ end
50
+
51
+ # Gets the chance of temperatures above 32.2 C/90 F within the date range.
52
+ # @see #get_planner_response
53
+ def chance_of_heat(start_date, end_date, location)
54
+ get_chance_of('tempoverninety', start_date, end_date, location)
55
+ end
56
+
57
+ # Gets the chance of rain within the date range.
58
+ # @see #get_planner_response
59
+ def chance_of_rain(start_date, end_date, location)
60
+ get_chance_of('chanceofrainday', start_date, end_date, location)
61
+ end
62
+
63
+ # Gets the chance of precipitation within the date range.
64
+ # @see #get_planner_response
65
+ def chance_of_precipitation(start_date, end_date, location)
66
+ get_chance_of('chanceofprecip', start_date, end_date, location)
67
+ end
68
+
69
+ # Gets the chance of humidity within the date range.
70
+ # @see #get_planner_response
71
+ def chance_of_humid(start_date, end_date, location)
72
+ get_chance_of('chanceofhumidday', start_date, end_date, location)
73
+ end
74
+
75
+ # Gets the chance of fog within the date range.
76
+ # @see #get_planner_response
77
+ def chance_of_fog(start_date, end_date, location)
78
+ get_chance_of('chanceoffogday', start_date, end_date, location)
79
+ end
80
+
81
+ # Gets the chance of cloudy conditions within the date range.
82
+ # @see #get_planner_response
83
+ def chance_of_cloudy(start_date, end_date, location)
84
+ get_chance_of('chanceofcloudyday', start_date, end_date, location)
85
+ end
86
+
87
+ # Gets the chance of sunshine within the date range.
88
+ # @see #get_planner_response
89
+ def chance_of_sunny(start_date, end_date, location)
90
+ get_chance_of('chanceofsunnycloudyday', start_date, end_date, location)
91
+ end
92
+
93
+ # Gets the chance of partially cloudy conditions within the date range.
94
+ # @see #get_planner_response
95
+ def chance_of_partlycloudy(start_date, end_date, location)
96
+ get_chance_of('chanceofpartlycloudyday', start_date, end_date, location)
97
+ end
98
+
99
+ # Gets the chance of high winds within the date range.
100
+ # @see #get_planner_response
101
+ def chance_of_high_wind(start_date, end_date, location)
102
+ get_chance_of('chanceofwindyday', start_date, end_date, location)
103
+ end
104
+
105
+ # Gets the chance of a temperature of 15.5 C/60 F within the date range.
106
+ # @see #get_planner_response
107
+ def chance_of_warmth(start_date, end_date, location)
108
+ get_chance_of('tempoversixty', start_date, end_date, location)
109
+ end
110
+
111
+ # Gets the dewpoint highs and lows for the date range.
112
+ # @see #get_planner_response
113
+ # @return [Hash] Highs and lows minimum, average, and maximum for both
114
+ # metric and imperial systems.
115
+ # @return [String] The error if possible.
116
+ def get_dewpoints(start_date, end_date, location)
117
+ response = get_planner_response(start_date, end_date, location)
118
+ return response['response']['error'] unless
119
+ response['response']['error'].nil?
120
+ highs = response['trip']['dewpoint_high']
121
+ lows = response['trip']['dewpoint_low']
122
+
123
+ {
124
+ high: {
125
+ imperial: {
126
+ minimum: highs['min']['F'].to_i,
127
+ maximum: highs['max']['F'].to_i,
128
+ average: highs['avg']['F'].to_i
129
+ },
130
+ metric: {
131
+ minimum: highs['min']['C'].to_i,
132
+ maximum: highs['max']['C'].to_i,
133
+ average: highs['avg']['C'].to_i
134
+ }
135
+ },
136
+ low: {
137
+ imperial: {
138
+ minimum: lows['min']['F'].to_i,
139
+ maximum: lows['max']['F'].to_i,
140
+ average: lows['avg']['F'].to_i
141
+ },
142
+ metric: {
143
+ minimum: lows['min']['C'].to_i,
144
+ maximum: lows['max']['C'].to_i,
145
+ average: lows['avg']['C'].to_i
146
+ }
147
+ }
148
+ }
149
+ end
150
+
151
+ # Gets the precipitation amounts (not chance) for the date range.
152
+ # @see #get_planner_response
153
+ # @return [Hash] Minimum, maximum, and average precipitation quantities for
154
+ # the location in both inches and centimeters.
155
+ # @return [String] The error if possible.
156
+ def get_precipitation(start_date, end_date, location)
157
+ response = get_planner_response(start_date, end_date, location)
158
+ return response['response']['error'] unless
159
+ response['response']['error'].nil?
160
+ min = response['trip']['precip']['min']
161
+ avg = response['trip']['precip']['avg']
162
+ max = response['trip']['precip']['max']
163
+
164
+ {
165
+ minimum: {
166
+ inch: min['in'].to_i,
167
+ centimeter: min['cm'].to_i
168
+ },
169
+ maximum: {
170
+ inch: max['in'].to_i,
171
+ centimeter: max['cm'].to_i
172
+ },
173
+ average: {
174
+ inch: avg['in'].to_i,
175
+ centimeter: avg['cm'].to_i
176
+ }
177
+ }
178
+ end
179
+
180
+ # Gets the highs and lows for the date range.
181
+ # @see #get_planner_response
182
+ # @return [Hash] Highs and lows minimum, average, and maximum for both
183
+ # metric and imperial systems.
184
+ def get_temperatures(start_date, end_date, location)
185
+ response = get_planner_response(start_date, end_date, location)
186
+ return response['response']['error'] unless
187
+ response['response']['error'].nil?
188
+ highs = response['trip']['temp_high']
189
+ lows = response['trip']['temp_low']
190
+
191
+ {
192
+ high: {
193
+ imperial: {
194
+ minimum: highs['min']['F'].to_i,
195
+ maximum: highs['max']['F'].to_i,
196
+ average: highs['avg']['F'].to_i
197
+ },
198
+ metric: {
199
+ minimum: highs['min']['C'].to_i,
200
+ maximum: highs['max']['C'].to_i,
201
+ average: highs['avg']['C'].to_i
202
+ }
203
+ },
204
+ low: {
205
+ imperial: {
206
+ minimum: lows['min']['F'].to_i,
207
+ maximum: lows['max']['F'].to_i,
208
+ average: lows['avg']['F'].to_i
209
+ },
210
+ metric: {
211
+ minimum: lows['min']['C'].to_i,
212
+ maximum: lows['max']['C'].to_i,
213
+ average: lows['avg']['C'].to_i
214
+ }
215
+ }
216
+ }
217
+ end
218
+
219
+ private
220
+
221
+ # Gets the full planner API response.
222
+ # @param start_date [DateTime] The date to start at. Only month and day
223
+ # actually matter.
224
+ # @param end_date [DateTime] The date to end at. Only month and day actually
225
+ # matter.
226
+ # @param location [String] The location to get the planner data for.
227
+ # @since 0.5.0
228
+ # @return [Hash] (see {Weatheruby#get #get})
229
+ def get_planner_response(start_date, end_date, location)
230
+ start = start_date.strftime('%m%d')
231
+ final = end_date.strftime('%m%d')
232
+ get("planner_#{start}#{final}", location)
233
+ end
234
+
235
+ # Gets the chance of any given string key in the chance_of hash returned by
236
+ # get_planner_response.
237
+ # @param subject [String] The chance_of hash's key.
238
+ # @param start_date [DateTime] (see {#get_planner_response})
239
+ # @param end_date [DateTime] (see {#get_planner_response})
240
+ # @param location [String] (see {#get_planner_response})
241
+ # @since 0.5.0
242
+ # @return [Fixnum] The chance of the subject happening.
243
+ def get_chance_of(subject, start_date, end_date, location)
244
+ response = get_planner_response(start_date, end_date, location)
245
+ return unless response['response']['error'].nil?
246
+
247
+ response['trip']['chance_of'][subject]['percentage'].to_i
248
+ end
249
+ end
250
+ end
data/lib/weatheruby.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'httpclient'
2
2
  require 'json'
3
3
  require_relative 'weather/actions'
4
+ require_relative 'weather/planner'
4
5
  require_relative 'weather/exceptions'
5
6
 
6
7
  class Weatheruby
7
8
  include Weather::Actions
9
+ include Weather::Planner
8
10
 
9
11
  # Creates a new instance of Weatheruby.
10
12
  # @param api_key [String] Your personal API key obtained on sign up for
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weatheruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -63,6 +63,7 @@ files:
63
63
  - bin/weatheruby
64
64
  - lib/weather/actions.rb
65
65
  - lib/weather/exceptions.rb
66
+ - lib/weather/planner.rb
66
67
  - lib/weatheruby.rb
67
68
  homepage: https://github.com/elifoster/weatheruby
68
69
  licenses: