Giter VIP home page Giter VIP logo

Ruby client for OpenMeteo

CI CodeCov Gem Version

This client library lets you easily connect to the OpenMeteo API.

NOTE: There is a plan to create official SDKs via FlatBuffers. However, I couldn't find a Ruby implementation of FlatBuffers in general. Hence, most likely, there won't be a Ruby SDK in the near future.

Usage

require "open_meteo"

location = OpenMeteo::Entities::Location.new(latitude: 52.52.to_d, longitude: 13.41.to_d)
variables = { current: %i[], hourly: %i[weather_code], daily: %i[] }
data = OpenMeteo::Forecast.new.get(location:, variables:)

data.hourly.items.each { |item| puts item.weather_code_symbol }

Forecast models

Forecast models in general request

The general forecast endpoint allows for models to be specified which adds suffixes to the response variables if multiple models are selected. You can make use of this by adding models to the forecast variables:

variables = {
  current: %i[],
  hourly: %i[weather_code],
  daily: %i[],
  models: %i[best_match ecmwf_ifs04],
}

Forecast models in separate requests

There are separate requests for certain weather models. You can make use of those by providing the model symbol to Forecast#get:

data = OpenMeteo::Forecast.new.get(location:, variables:, model: :dwd_icon)

Default is :general.

Available models:

Configuration

Global configuration

There is the possibility to configure OpenMeteo globally e.g. in an initializer:

# config/initializer/open_meteo.rb
require "open-meteo"

OpenMeteo.configure do |config|
  config.host = "api.my-own-open-meteo.com"
  config.logger = Rails.logger
  config.api_key = "your_open_meteo_api_key"
end
# some/other/file.rb
forecast = OpenMeteo::Forecast.new

location = OpenMeteo::Entities::Location.new(latitude: 52.52, longitude: 13.41)
variables = { current: %i[weather_code], hourly: %i[], daily: %i[] }
forecast_response = forecast.get(location:, variables:)
Config key Default value Remarks
host "api.open-meteo.com"
api_key ENV.fetch("OPEN_METEO_API_KEY", nil) } Use the host customer-api.open-meteo.com for the commercial version of OpenMeteo.
logger Logger.new($stdout)
timeouts { timeout: 5, open_timeout: 5} Uses Faraday configuration options

Configuration of a client instance

You can also create a client that takes a configuration that overwrites the global configuration.

The configuration sent to the client initializer will be shared with the dependent classes:

# some/other/file.rb
require "open-meteo"

config =
  OpenMeteo::Client::Config.new(logger: Logger.new($stdout), host: "api.my-own-open-meteo.com")
client = OpenMeteo::Client.new(config:)
forecast = OpenMeteo::Forecast.new(client:)

location = OpenMeteo::Entities::Location.new(latitude: 52.52, longitude: 13.41)
variables = { current: %i[weather_code], hourly: %i[], daily: %i[] }
forecast_response = forecast.get(location:, variables:)

Development

Useful commands are defined in the Justfile and can be listed with just.

E.g. execute an example request: just example.

open-meteo-ruby's Projects

open-meteo-ruby doesnโ€™t have any public repositories yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.