Class: Yudachi::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(app_id:) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/yudachi/client.rb', line 7

def initialize(app_id:)
  @app_id = app_id
end

Instance Method Details

#location_name_and_coodinated_geometry(query) ⇒ Object



11
12
13
14
15
16
# File 'lib/yudachi/client.rb', line 11

def location_name_and_coodinated_geometry(query)
  url = "https://map.yahooapis.jp/geocode/V1/geoCoder?appid=#{@app_id}&output=json&query=#{CGI.escape(query)}"
  response = get url
  feature = response["Feature"]&.first
  [feature&.dig('Name'), feature&.dig('Geometry', 'Coordinates')]
end

#rainfall(geometry) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/yudachi/client.rb', line 18

def rainfall(geometry)
  url = "https://map.yahooapis.jp/weather/V1/place\?appid\=#{@app_id}\&output=json&coordinates\=#{geometry}&past=1&interval=5"
  response = get url
  features = response["Feature"]

  features&.first&.dig("Property", "WeatherList", "Weather").each do |data|
    data['Date'] = Time.parse(data['Date'])
  end
end