Class: KNMI::HttpService
- Inherits:
-
Object
- Object
- KNMI::HttpService
- Includes:
- HTTParty
- Defined in:
- lib/knmi/httpservice.rb
Instance Attribute Summary collapse
-
#data ⇒ Array<Hash>
readonly
Parsed HTTP request.
-
#query ⇒ Array<string>
readonly
Returns query string used in HTTP get request.
Class Method Summary collapse
-
.get_daily(station_object, parameters_object, starts = nil, ends = nil, seasonal = false) ⇒ KNMI::HttpService
Requests Daily data.
-
.get_hourly(station_object, parameters_object, starts = nil, ends = nil, seasonal = false) ⇒ KNMI::HttpService
Requests Hourly data.
Instance Method Summary collapse
-
#initialize(properties) ⇒ HttpService
constructor
A new instance of HttpService.
Constructor Details
#initialize(properties) ⇒ HttpService
Returns a new instance of HttpService.
144 145 146 147 148 |
# File 'lib/knmi/httpservice.rb', line 144 def initialize(properties) @query, @data = %w(query data).map do |p| properties[p] end end |
Instance Attribute Details
#data ⇒ Array<Hash> (readonly)
Parsed HTTP request
142 143 144 |
# File 'lib/knmi/httpservice.rb', line 142 def data @data end |
#query ⇒ Array<string> (readonly)
Returns query string used in HTTP get request
134 135 136 |
# File 'lib/knmi/httpservice.rb', line 134 def query @query end |
Class Method Details
.get_daily(station_object, parameters_object, starts = nil, ends = nil, seasonal = false) ⇒ KNMI::HttpService
Requests Daily data
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/knmi/httpservice.rb', line 17 def get_daily(station_object, parameters_object, starts = nil, ends = nil, seasonal = false) # select YYYYMMDD (drops hour term) query = [station(station_object), parameters(parameters_object), start_date(starts)[0..13], end_date(ends)[0..11], seasonal(seasonal)].compact result = get('http://www.knmi.nl/climatology/daily_data/getdata_day.cgi', { :query => "#{query * "&"}" } ) data = parse(station_object, parameters_object, result) return new({"query" => query, "data" => data}) end |
.get_hourly(station_object, parameters_object, starts = nil, ends = nil, seasonal = false) ⇒ KNMI::HttpService
Requests Hourly data
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/knmi/httpservice.rb', line 38 def get_hourly(station_object, parameters_object, starts = nil, ends = nil, seasonal = false) query = [station(station_object), parameters(parameters_object), start_date(starts), end_date(ends), seasonal(seasonal)].compact result = get('http://www.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi', { :query => "#{query * "&"}" } ) data = parse(station_object, parameters_object, result) return new({"query" => query, "data" => data}) end |