Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created September 9, 2015 15:17
Show Gist options
  • Save bcardarella/0c59378615779263798f to your computer and use it in GitHub Desktop.
Save bcardarella/0c59378615779263798f to your computer and use it in GitHub Desktop.
config :my_app, :twitter_api,
client: Twitter.SandboxClient
config :my_app, :twitter_api,
client: Twitter.TestClient
def index(conn, %{"username" => username}) do
client = Application.get_env(:my_app, :twitter_api)[:client]
client.get(username)
end
@josevalim
Copy link

Yes! You can configure it directly too if you prefer:

config :my_app, :twitter_api, Twitter.SandboxClient

And in your controller I would move it to a function:

def index(conn, %{"username" => username}) do
  twitter_api.get(username)
end

defp twitter_api do
  Application.get_env(:my_app, :twitter_api)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment