Skip to content

the-guitarman/elixir_weather_data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Code Climate Built with Spacemacs

ElixirWeatherData

This application provides the current weather data for the given geo coordinates (latitude/longitude). It uses openweathermap.org v2.5 and holds the information within a gen server process. You may ask the process as often as you like. It asks the openweathermap api every hour once only.

Installation

If available in Hex, the package can be installed as:

  1. Add elixir_weather_data to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:elixir_weather_data, "~> 0.2"}]
end
```
  1. Ensure elixir_weather_data is started before your application:
```elixir
def application do
  [applications: [:elixir_weather_data]]
end
```
  1. Provide your openweathermap api parameters:
config :elixir_weather_data, :api, 
  key: "<your openweathermap api key>",
  language: "<your openweathermap language: en, de or ...>",
  coordinates: [lat: 50.939583, lon: 12.886244]

In the production environment the app will request the api of openweathermap.org to get the data.

In the development environment you may want to dicide to use sandbox data or send requests to the api of openweathermap.org. There are to modes available:

  • :sandbox
  • :http_client It defaults to :sandbox.
config :elixir_weather_data, :dev,
  mode: :sandbox
  
# or

config :elixir_weather_data, :dev,
  mode: :http_client
  1. You may configure the gen server timeout:
config :elixir_weather_data, :gen_server,
  call_timeout: 2000

Usage

ElixirWeatherData.get
# => {:ok, %{
#  centigrade: 14, 
#  created_at: 1477595605, 
#  fahrenheit: 57,
#  humidity_in_percent: 97, 
#  icon: "04n",
#  icon_url: "http://openweathermap.org/img/w/04n.png",
#  pressure_in_hectopascal: 997, 
#  weather: "cloudy",
#  wind_direction_abbreviation: "WSW", 
#  wind_direction_in_degrees: 246,
#  wind_in_kilometers_per_hour: 11, 
#  wind_in_meters_per_second: 3
# }}

In case of an error at the first openweathermap api request, you will get {:error, <some error reason>}, otherwise it will return the last received data.

License

Everything may break everytime. Therefore this package is licensed under the LGPL 3.0. Do whatever you want with it, but please give improvements and bugfixes back so everyone can benefit.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages