dnsimple-elixir icon indicating copy to clipboard operation
dnsimple-elixir copied to clipboard

Client configuration requires library recompilation to take effect

Open adamkittelson opened this issue 5 years ago • 1 comments

Hi, thanks for creating an Elixir library for your API!

I noticed that when I make changes to my base_url in my application config:

config :dnsimple, base_url: "https://api.dnsimple.com"

(e.g. to change to/from the sandbox url) that my changes don't take effect when I reboot my application.

This is because you're setting the value to a module variable in lib/dnsimple.ex:

defmodule Client do
    @default_base_url Application.get_env(:dnsimple, :base_url, "https://api.dnsimple.com")
...

Since module variables are set at compile time rather than runtime it means any changes to that value in a user's config will not be reflected unless the library itself is recompiled.

The easiest way to rectify this would likely be to have a function for creating the client struct rather than default values on the struct. This would also allow you to tackle the note on #21 by @jacegu about wanting to handle access_token and user_agent in the config.

i.e. something like

defmodule Client do

  def new do
    base_url = Application.get_env(:dnsimple, :base_url, "https://api.dnsimple.com")
    access_token = Application.get_env(:dnsimple, :access_token)
    user_agent = Application.get_env(:dnsimple, :user_agent)

    %Dnsimple.Client{
      base_url: base_url,
      access_token: access_token,
      user_agent: format_agent(user_agent)
    }
  end
...

Thanks! Adam

adamkittelson avatar Mar 29 '19 01:03 adamkittelson

Thanks @adamkittelson. If you feel like providing a patch, it will definitely speed up the chance to get the change merged. 😉

weppos avatar Mar 29 '19 08:03 weppos