Module: OpenWeather::Endpoints::Stations

Included in:
Client
Defined in:
lib/open_weather/endpoints/stations.rb

Instance Method Summary collapse

Instance Method Details

#create_measurements(measurements, options = {}) ⇒ Object



33
34
35
36
# File 'lib/open_weather/endpoints/stations.rb', line 33

def create_measurements(measurements, options = {})
  post('3.0/measurements', options.merge(body: measurements))
  nil
end

#delete_station(id) ⇒ Object



26
27
28
29
30
31
# File 'lib/open_weather/endpoints/stations.rb', line 26

def delete_station(id)
  validate_id(id)

  delete("3.0/stations/#{id}")
  nil
end

#get_measurements(options) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
# File 'lib/open_weather/endpoints/stations.rb', line 38

def get_measurements(options)
  required_keys = %i[station_id type limit from to]
  missing_keys = required_keys - options.keys
  raise ArgumentError, "Missing params: #{missing_keys.join(', ')}" if missing_keys.any?

  get('3.0/measurements', options).map { |m| OpenWeather::Models::Stations::Measurement.new(m) }
end

#get_station(id) ⇒ Object



14
15
16
17
18
# File 'lib/open_weather/endpoints/stations.rb', line 14

def get_station(id)
  validate_id(id)

  OpenWeather::Models::Station.new(get("3.0/stations/#{id}"))
end

#list_stationsObject



10
11
12
# File 'lib/open_weather/endpoints/stations.rb', line 10

def list_stations
  get('3.0/stations').map { |data| OpenWeather::Models::Station.new(data) }
end

#register_station(options = {}) ⇒ Object



6
7
8
# File 'lib/open_weather/endpoints/stations.rb', line 6

def register_station(options = {})
  OpenWeather::Models::Station.new(post('3.0/stations', options))
end

#update_station(id, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/open_weather/endpoints/stations.rb', line 20

def update_station(id, options = {})
  validate_id(id)

  OpenWeather::Models::Station.new(put("3.0/stations/#{id}", options))
end