Newsie v0.1.0 Newsie.ProviderConfig View Source

Get provider configuration from app config and ENV

Configuration for a provider can be set with app config or with environment variables that follow the naming convention. Environment variables always take precedence application config.

Environment variable naming

Given the application config:

config :newsie, Newsie.Providers.MyNewsProvider, api_key: "asdqwe123"

If you wanted to override that with an environment variable, it would be:

NEWSIE_MY_NEWS_PROVIDER_API_KEY="updated_key"

The provider name and parameter name are snake-cased and prefixed with NEWSIE_ thus taking on the format:

NEWSIE_<provider_name>_<param_name>

Link to this section Summary

Functions

Get configuration from application config.

Get configuration from ENV vars for the given provider.

Link to this section Functions

Link to this function

get_provider_config(provider)

View Source

Specs

get_provider_config(atom()) :: keyword()
Link to this function

provider_app_config(provider)

View Source

Specs

provider_app_config(atom()) :: keyword()

Get configuration from application config.

Given the app config:

config :newsie, Newsie.Providers.DocProvider, api_key: "mykey"

Fetching the config for the provider:

Newsie.ProviderConfig.provider_app_config(Newsie.Providers.DocProvider)
[api_key: "mykey"]
Link to this function

provider_env_vars(provider_name)

View Source

Specs

provider_env_vars(atom() | binary()) :: keyword()

Get configuration from ENV vars for the given provider.

Prefixes are stripped and only the parameter names are returned as values.

Example

iex> System.put_env("NEWSIE_DOC_PROVIDER_API_KEY", "mykey")
...> Newsie.ProviderConfig.provider_env_vars("DocProvider")
[api_key: "mykey"]