Daniel Doubrovkine bio photo

Daniel Doubrovkine

aka dB., @awscloud, former CTO @artsy, +@vestris, NYC

Email Twitter LinkedIn Github Strava
Creative Commons License

I have been writing Ruby clients for various services for a few years now using the same pattern described in Writing a New Strava API Ruby Client. That itself was built on the experience of slack-ruby-client and iex-ruby-client.

A couple of weeks ago I took to OpenWeatherMap.org’s with open-weather-ruby-client. I’m now using it in Slava to fetch weather during a Strava activity.

client = OpenWeather::Client.new(api_key: "...")

data = client.current_weather(city: 'London')
# => OpenWeather::Models::City::Weather

Returns basic weather information.

data.name # => 'London'
data.dt # => Time
data.main.feels_like # => 277.73
data.main.humidity # => 81
data.main.pressure # => 1005
data.main.temp # => 283.15, degrees Kelvin

Has built-in temperature conversion.

data.main.temp_c # => 10, degrees Celcius
data.main.temp_f # => 50.0, degrees Farenheit

And can return some weather history via the OneCall API.

data = client.one_call(
  lat: 33.441792,
  lon: -94.037689,
  dt: Time.now - 24 * 60 * 60
) # => OpenWeather::Models::OneCall::Weather

data.lat # => 33.44
data.lon # => -94.04
data.timezone # => 'America/Chicago'
data.current # => OpenWeather::Models::OneCall::CurrentWeather
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]