Skip to content

Commit

Permalink
add client for holding authentication info
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Weiss committed Apr 6, 2016
1 parent 657ac0f commit 74677e9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/forcex/client.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule Forcex.Client do
defstruct auth: nil, endpoint: "https://login.salesforce.com"

def new do
[:username, :password, :security_token, :client_key, :client_secret]
|> Enum.map(&( {&1, get_val_from_env(&1)}))
|> Enum.into(%{})
|> new
end
def new(auth), do: %__MODULE__{auth: auth}
def new(auth, endpoint) do
endpoint = if String.ends_with?("/"), do: endpoint, else: endpoint <> "/"
%__MODULE__{auth: auth, endpoint: endpoint}
end

defp get_val_from_env(key) do
key
|> env_var
|> System.get_env
|> case do
nil ->
Application.get_env(:forcex, __MODULE__, [])
|> Keyword.get(key)
val -> val
end
end

defp env_var(key), do: "SALESFORCE_#{key |> to_string |> String.upcase}"
end

0 comments on commit 74677e9

Please sign in to comment.