Class: AirVisualApi::City

Inherits:
Object
  • Object
show all
Defined in:
lib/airvisual_api/city.rb

Instance Method Summary collapse

Instance Method Details

#city_by_name_and_state(city:, state:) ⇒ Object

Only going to support American states for an MVP Typical American exceptionalism, amirite? ;)



27
28
29
# File 'lib/airvisual_api/city.rb', line 27

def city_by_name_and_state(city:, state:)
  client.get(url: "/city?city=#{city}&state=#{state}&country=USA")
end

#nearest_city_by_gps(latitude:, longitude:) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/airvisual_api/city.rb', line 15

def nearest_city_by_gps(latitude:, longitude:)
  # coercing to float to ensure proper formatting
  # this should probably be a little smarter with some
  # regex checking coupled with some ruby errors, but
  # for time and prototyping sake I'm just going to coerce
  latitude = latitude.to_f
  longitude = longitude.to_f
  client.get(url: "/nearest_city?lat=#{latitude}&lon=#{longitude}")
end

#nearest_city_by_ip(ip:) ⇒ Object

Have to actually set the IP or we’ll get the server’s IP as a result.



11
12
13
# File 'lib/airvisual_api/city.rb', line 11

def nearest_city_by_ip(ip:)
  client.get(url: '/nearest_city', headers: { 'x-forwarded-for' => ip })
end