darksky_ruby_client 0.0.4 → 0.0.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/darksky_ruby_client/client.rb +66 -14
- data/lib/darksky_ruby_client/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: d5de6788b9b993237d23881ecffdf89613b0ed16
|
4
|
+
data.tar.gz: f1434deabeaf47eb81a65bd916d55cbe21266fe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d73402afe16116467f0aa979de67257d92a74b6879e762216d477f0fbb3ec33a147116dd00b07eb036def9c6d25af07bd02cfc4a1578009f4b9edebb18f0f9fa
|
7
|
+
data.tar.gz: acc5b8fb1c4f01f980d18d9d71de341e72f51436caf71da93a49a5fd5a924f9d3ef9b0103ae7b8d51a2cfe0d6d2ca1a03c91b5b5a3e2f3ae7a0f698c68d6674f
|
@@ -29,12 +29,12 @@ module DarkskyRubyClient
|
|
29
29
|
@responses = {}
|
30
30
|
end
|
31
31
|
|
32
|
-
#
|
32
|
+
# Single request for the forecast api.
|
33
33
|
# @param [String] lat The latitude of a location (in decimal degrees).
|
34
34
|
# @param [String] long The longitude of a location (in decimal degrees).
|
35
|
-
# @param [
|
35
|
+
# @param [String] options Use if you want to specify "explicit, extend, lang, units".
|
36
36
|
# Please check https://darksky.net/dev/docs#forecast-request for details.
|
37
|
-
# @option options [String]
|
37
|
+
# @option options [String] exclude
|
38
38
|
# exlude=[blocks] e.g. exclude: "currently,flags"
|
39
39
|
# Exclude some number of data blocks from the API response.
|
40
40
|
# This is useful for reducing latency and saving cache space.
|
@@ -45,17 +45,17 @@ module DarkskyRubyClient
|
|
45
45
|
# * daily
|
46
46
|
# * alerts
|
47
47
|
# * flags
|
48
|
-
# @option options [String]
|
49
|
-
# extend=[hourly] e.g.
|
48
|
+
# @option options [String] extend
|
49
|
+
# extend=[hourly] e.g. extend: "24"
|
50
50
|
# When present, return hour-by-hour data for the next 168 hours, instead of the next 48.
|
51
51
|
# When using this option, we strongly recommend enabling HTTP compression.
|
52
|
-
# @option options [String]
|
52
|
+
# @option options [String] lang
|
53
53
|
# e.g. lang: "en"
|
54
54
|
# Return summary properties in the desired language.
|
55
55
|
# (Note that units in the summary will be set according to the units parameter,
|
56
56
|
# so be sure to set both parameters appropriately.)
|
57
57
|
# Please check with https://darksky.net/dev/docs#forecast-request for available languages.
|
58
|
-
# @option options [String]
|
58
|
+
# @option options [String] units
|
59
59
|
# units=[units] e.g. units: "auto"
|
60
60
|
# Return weather conditions in the requested units.
|
61
61
|
# [units] should be one of the following:
|
@@ -71,11 +71,10 @@ module DarkskyRubyClient
|
|
71
71
|
unless options.empty? then
|
72
72
|
options.each {|key, value|
|
73
73
|
if [:exclude, :extend, :lang, :units].include?(key)
|
74
|
-
p @request_url[-1]
|
75
74
|
if @request_url[-1] == '/'
|
76
|
-
@request_url
|
75
|
+
@request_url << '?' + key.to_s + '=' + value
|
77
76
|
else
|
78
|
-
@request_url
|
77
|
+
@request_url << '&' + key.to_s + '=' + value
|
79
78
|
end
|
80
79
|
else
|
81
80
|
@log.warn("invalid options key \"#{key}\".")
|
@@ -83,10 +82,59 @@ module DarkskyRubyClient
|
|
83
82
|
}
|
84
83
|
end
|
85
84
|
init_client
|
86
|
-
|
85
|
+
unless @parallel_requests
|
86
|
+
run
|
87
|
+
JSON.parse(@res.body) if @res.code == 200
|
88
|
+
end
|
87
89
|
end
|
88
90
|
|
89
|
-
#
|
91
|
+
# Parallel request for the forecast api.
|
92
|
+
# @param [Hash] locations Must set it in two dimensional hash
|
93
|
+
# and must follow the specified format.
|
94
|
+
# {
|
95
|
+
# :place_name => {
|
96
|
+
# :latitude => "latitude value",
|
97
|
+
# :longitude => "longitude value"
|
98
|
+
# },
|
99
|
+
# :place_name => {
|
100
|
+
# :latitude => "latitude value",
|
101
|
+
# :longitude => "longitude value"
|
102
|
+
# }
|
103
|
+
# }
|
104
|
+
# @param [String] options Use if you want to specify "explicit, extend, lang, units".
|
105
|
+
# Please check https://darksky.net/dev/docs#forecast-request for details.
|
106
|
+
# @option options [String] exclude
|
107
|
+
# exlude=[blocks] e.g. exclude: "currently,flags"
|
108
|
+
# Exclude some number of data blocks from the API response.
|
109
|
+
# This is useful for reducing latency and saving cache space.
|
110
|
+
# The value blocks should be a comma-delimeted list (without spaces) of any of the following:
|
111
|
+
# * currently
|
112
|
+
# * minutely
|
113
|
+
# * hourly
|
114
|
+
# * daily
|
115
|
+
# * alerts
|
116
|
+
# * flags
|
117
|
+
# @option options [String] extend
|
118
|
+
# extend=[hourly] e.g. extend: "24"
|
119
|
+
# When present, return hour-by-hour data for the next 168 hours, instead of the next 48.
|
120
|
+
# When using this option, we strongly recommend enabling HTTP compression.
|
121
|
+
# @option options [String] lang
|
122
|
+
# e.g. lang: "en"
|
123
|
+
# Return summary properties in the desired language.
|
124
|
+
# (Note that units in the summary will be set according to the units parameter,
|
125
|
+
# so be sure to set both parameters appropriately.)
|
126
|
+
# Please check with https://darksky.net/dev/docs#forecast-request for available languages.
|
127
|
+
# @option options [String] units
|
128
|
+
# units=[units] e.g. units: "auto"
|
129
|
+
# Return weather conditions in the requested units.
|
130
|
+
# [units] should be one of the following:
|
131
|
+
# * auto: automatically select units based on geographic location
|
132
|
+
# * ca: same as si, except that windSpeed and windGust are in kilometers per hour
|
133
|
+
# * uk2: same as si, except that nearestStormDistance and visibility are in miles,
|
134
|
+
# and windSpeed and windGust in miles per hour
|
135
|
+
# * us: Imperial units (the default)
|
136
|
+
# * si: SI units
|
137
|
+
# Please check with https://darksky.net/dev/docs#forecast-request for available SI units.
|
90
138
|
def some_weather_forecast(locations, **options)
|
91
139
|
@parallel_requests = true
|
92
140
|
hydra = Typhoeus::Hydra.new
|
@@ -96,7 +144,11 @@ module DarkskyRubyClient
|
|
96
144
|
longitude = location[:longitude] if location.include?(:longitude)
|
97
145
|
weather_forecast(latitude, longitude, options)
|
98
146
|
@client.on_complete do |response|
|
99
|
-
|
147
|
+
if response.code == 200
|
148
|
+
@responses[place_name] = JSON.parse(response.body)
|
149
|
+
else
|
150
|
+
@log.error("HTTP request failed: " + response.code.to_s)
|
151
|
+
end
|
100
152
|
end
|
101
153
|
hydra.queue @client
|
102
154
|
@client
|
@@ -112,7 +164,7 @@ module DarkskyRubyClient
|
|
112
164
|
|
113
165
|
# Run a request.
|
114
166
|
def run
|
115
|
-
@client.run
|
167
|
+
@res = @client.run
|
116
168
|
end
|
117
169
|
end
|
118
170
|
end
|