Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/forcex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ defmodule Forcex do
@user_agent [{"User-agent", "forcex"}]
@accept [{"Accept", "application/json"}]
@accept_encoding [{"Accept-Encoding", "gzip,deflate"}]
@content_type [{"Content-Type", "application/json; charset=UTF-8"}]

def process_request_headers(headers), do: headers ++ @user_agent ++ @accept ++ @accept_encoding
def process_request_headers(headers), do: headers ++ @user_agent ++ @accept ++ @accept_encoding ++ @content_type

def process_headers(headers), do: Map.new(headers)

Expand Down
27 changes: 21 additions & 6 deletions lib/forcex/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,32 @@ defmodule Forcex.Client do
end

def login(conf, starting_struct) do
login_payload =
conf
|> Map.put(:password, "#{conf.password}#{conf.security_token}")
|> Map.put(:grant_type, "password")
login_payload = conf
|> Map.merge(%{
password: "#{conf.password}#{conf.security_token}",
grant_type: "password"
})

Forcex.post("/services/oauth2/token?#{URI.encode_query(login_payload)}", starting_struct)
|> handle_login_response
end

def locate_services(client) do
services = Forcex.services(client)
%{client | services: services}
%{client | services: Forcex.services(client)}
end

def create_sobject(client \\ %__MODULE__{}, name \\ "SOBject", map \\ %{})

def create_sobject(client, name, map) when is_atom(name) do
name = name
|> Atom.to_string
|> String.capitalize

client
|> create_sobject(name, map)
end
def create_sobject(client, name, map) do
Forcex.post("/services/data/v20.0/sobjects/#{name}", map, client)
Copy link
Author

@sebbean sebbean May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffweiss curious why you chose to have Forcex module methods use a trailing client param rather than leading (for pipeline operator)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebbean the reason that I have client as the trailing param is that for most of the calls, it is the least relevant to the name of the function. True, moving client to the first parameter would make it more cases of using |> possible, but client isn't the focus of many of the functions, nor is it transformed by many of the functions (the obvious exception is Forcex.Client).

end

defp handle_login_response(%{"access_token" => token, "token_type" => token_type, "instance_url" => endpoint}) do
Expand Down