-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add client for holding authentication info
- Loading branch information
Jeff Weiss
committed
Apr 6, 2016
1 parent
657ac0f
commit 74677e9
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |