Skip to content

Commit

Permalink
Merge 61a182d into cd8b4d2
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbean committed May 19, 2016
2 parents cd8b4d2 + 61a182d commit d1e532d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
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)
end

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

0 comments on commit d1e532d

Please sign in to comment.