Class: Yudachi::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/yudachi/runner.rb

Instance Method Summary collapse

Instance Method Details

#run(app_id:, location_name:, notifier:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/yudachi/runner.rb', line 3

def run(app_id:, location_name:, notifier:)
  client = Client.new(app_id: app_id)

  location_name, geo = client.location_name_and_coodinated_geometry(location_name)
  raise "geometry not found" unless geo
  datapoints = client.rainfall(geo)
  raise "something wrong" unless datapoints

  observation_threshold = Time.now - 30 * 60
  datapoints = datapoints.select do |data|
    # Drop too old data
    data['Date'] > observation_threshold
  end

  if beginning_of_rainfall?(datapoints)
    notifier.notify(datapoints: datapoints, location_name: location_name)
  end
end