Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch compile options #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ config :forcex, Forcex.Client,
password: "my_super_secret_password",
security_token: "EMAILED_FROM_SALESFORCE",
client_id: "CONNECTED_APP_OAUTH_CLIENT_ID",
client_secret: "CONNECTED_APP_OAUTH_CLIENT_SECRET"
client_secret: "CONNECTED_APP_OAUTH_CLIENT_SECRET",
endpoint: "https://test.salesforce.com",
modules: ["People"]
```

or these environment variables:
Expand All @@ -67,6 +69,8 @@ or these environment variables:
* `SALESFORCE_CLIENT_ID`
* `SALESFORCE_CLIENT_SECRET`

The endpoint (defaults to `https://login.salesforce.com`) and modules configurations are optional. The list of modules can be specified so that only particular Salesforce Objects are compiled instead of compiling entire Salesforce object.

HTTPoison request-specific options may also be configured:

```elixir
Expand Down
19 changes: 18 additions & 1 deletion lib/mix/tasks/compile.forcex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ defmodule Mix.Tasks.Compile.Forcex do
use Mix.Task

@recursive false
@default_endpoint "https://login.salesforce.com"

def run(_) do
{:ok, _} = Application.ensure_all_started(:forcex)

client = Forcex.Client.login
client = Forcex.Client.default_config
|> Forcex.Client.login(%Forcex.Client{endpoint: config[:endpoint] || @default_endpoint})

case client do
%{access_token: nil} -> IO.puts("Invalid configuration/credentials. Cannot generate SObjects.")
Expand All @@ -21,6 +23,7 @@ defmodule Mix.Tasks.Compile.Forcex do
client
|> Forcex.describe_global
|> Map.get("sobjects")
|> filter_modules

for sobject <- sobjects do
sobject
Expand All @@ -30,6 +33,18 @@ defmodule Mix.Tasks.Compile.Forcex do

end

defp filter_modules(sobjects) do
case config[:modules] |> is_list do
true ->
sobjects
|> Enum.filter(fn sobject ->
Map.get(sobject, "name", nil) in config[:modules]
end)
false ->
sobjects
end
end

defp generate_module(sobject, client) do
name = Map.get(sobject, "name")
urls = Map.get(sobject, "urls")
Expand Down Expand Up @@ -215,4 +230,6 @@ defmodule Mix.Tasks.Compile.Forcex do
" * `#{value}`\n"
end
defp docs_for_picklist_values(_), do: ""

defp config, do: Application.get_env(:forcex, Forcex.Client)
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ defmodule Forcex.Mixfile do
# Type `mix help deps` for more examples and options
defp deps do
[
{:httpoison, "~> 0.8"},
{:exjsx, "~> 3.1"},
{:httpoison, "~> 0.9"},
{:exjsx, "~> 3.2"},
{:timex, "~> 2.0"},
{:excoveralls, "~> 0.5", only: :test},
{:ex_doc, "~> 0.11.4", only: :docs},
Expand Down
32 changes: 16 additions & 16 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
%{"certifi": {:hex, :certifi, "0.4.0"},
"combine": {:hex, :combine, "0.7.0"},
"earmark": {:hex, :earmark, "0.2.1"},
"ex_doc": {:hex, :ex_doc, "0.11.4"},
"excoveralls": {:hex, :excoveralls, "0.5.2"},
"exjsx": {:hex, :exjsx, "3.2.0"},
"gettext": {:hex, :gettext, "0.10.0"},
"hackney": {:hex, :hackney, "1.6.0"},
"httpoison": {:hex, :httpoison, "0.8.3"},
"idna": {:hex, :idna, "1.2.0"},
"jsx": {:hex, :jsx, "2.6.2"},
"metrics": {:hex, :metrics, "1.0.1"},
"mimerl": {:hex, :mimerl, "1.0.2"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0"},
%{"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []},
"combine": {:hex, :combine, "0.9.2", "cd3c8721f378ebe032487d8a4fa2ced3181a456a3c21b16464da8c46904bb552", [:mix], []},
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.11.5", "0dc51cb84f8312162a2313d6c71573a9afa332333d8a332bb12540861b9834db", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
"excoveralls": {:hex, :excoveralls, "0.5.6", "35a903f6f78619ee7f951448dddfbef094b3a0d8581657afaf66465bc930468e", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
"gettext": {:hex, :gettext, "0.11.0", "80c1dd42d270482418fa158ec5ba073d2980e3718bacad86f3d4ad71d5667679", [:mix], []},
"hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]},
"httpoison": {:hex, :httpoison, "0.9.1", "6c2b4eaf2588a6f3ef29663d28c992531ca3f0bc832a97e0359bc822978e1c5d", [:mix], [{:hackney, "~> 1.6.0", [hex: :hackney, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []},
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.6"},
"timex": {:hex, :timex, "2.1.4"},
"tzdata": {:hex, :tzdata, "0.5.7"}}
"timex": {:hex, :timex, "2.2.1", "0d69012a7fd69f4cbdaa00cc5f2a5f30f1bed56072fb362ed4bddf60db343022", [:mix], [{:combine, "~> 0.7", [hex: :combine, optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, optional: false]}]},
"tzdata": {:hex, :tzdata, "0.5.9", "575be217b039057a47e133b72838cbe104fb5329b19906ea4e66857001c37edb", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}}