Daniel Caixinha
Software Engineer @
@dcaixinha
[app@0e04683009ec$:~/motus]$ MIX_ENV=test mix test
Excluding tags: [integration: true, pending: true]
............................................................................................................................................................
Finished in 7.1 seconds
822 tests, 0 failures, 0 skipped
Randomized with seed 799264
def generate_report(conn) do
result =
Helper.query_string_params(conn)
|> perform_request()
conn
|> json_response
|> Plug.Conn.send_resp(response_code, result)
end
# standard.json.eex
{
"data": {
"score": "<%= provider_score %>"
}
}
# provider_standard.exs
%{
template: "standard.json.eex",
etl_matches: %{
"provider_score" => %{clear: "0.0", consider: "1.0"}
}
}
defmodule MyApp.Terraformers.Foo do
alias MyApp.Clients.Foo
use Plug.Router
plug :match
plug :dispatch
# match specific path
get "/v1/hello-world", do: send_resp(conn, 200, "This was handled by Elixir!")
# match all GETs
get _ do
%{method: "GET", request_path: request_path, params: params, req_headers: req_headers} = conn
res = Foo.get!(request_path, req_headers, [params: Map.to_list(params)])
send_response({:ok, conn, res})
end
defp send_response({:ok, conn, %{headers: headers, status_code: status_code, body: body}}) do
conn = %{conn | resp_headers: headers}
send_resp(conn, status_code, body)
end
end
defmodule Demo do
@moduledoc """
Documentation for Demo.
"""
@doc """
Hello world.
## Examples
iex> Demo.hello()
:world
"""
def hello do
:world
end
end
After your first prototype is a hit, you'll need to
think about growing a team!
BEAM Me Up, Scotty!
@dcaixinha