From 82878d2bbc934d7bf16d399117ebecda6ed17835 Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Thu, 19 May 2016 15:18:30 -0500 Subject: [PATCH 1/3] content-type necessary in POST request --- lib/forcex.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/forcex.ex b/lib/forcex.ex index a343835..6ce3aa3 100644 --- a/lib/forcex.ex +++ b/lib/forcex.ex @@ -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) From 60618d34c4b8d4e252a67f8d7f76199e819fb271 Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Thu, 19 May 2016 16:13:30 -0500 Subject: [PATCH 2/3] two helper calls for creating arbitrary SObjects --- lib/forcex/client.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/forcex/client.ex b/lib/forcex/client.ex index 4a82822..cbff70f 100644 --- a/lib/forcex/client.ex +++ b/lib/forcex/client.ex @@ -61,6 +61,20 @@ defmodule Forcex.Client do services = Forcex.services(client) %{client | services: services} 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) + end defp handle_login_response(%{"access_token" => token, "token_type" => token_type, "instance_url" => endpoint}) do %__MODULE__{access_token: token, token_type: token_type, endpoint: endpoint} From 61a182dcd6bbb474daa2c15afd413c4a20e30e65 Mon Sep 17 00:00:00 2001 From: Sebastian Bean Date: Thu, 19 May 2016 16:16:25 -0500 Subject: [PATCH 3/3] almost pointless cleanup --- lib/forcex/client.ex | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/forcex/client.ex b/lib/forcex/client.ex index cbff70f..2ebc208 100644 --- a/lib/forcex/client.ex +++ b/lib/forcex/client.ex @@ -49,17 +49,18 @@ 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 \\ %{})