defmodule Arpas.REST.Cae.Api do alias Arpas.REST.Cae.Env def token do url = Env.token_url() username = "username=#{Env.user()}" password = "password=#{Env.password()}&grant_type=password" client_id = "client_id=GenericClient" client_instance = "client_instance=123457" payload = "#{username}&#{password}&#{client_id}&#{client_instance}" headers = [ {"Accept", "application/json"}, {"Content-Type", "application/x-www-form-urlencoded"}, {"Cache-Control", "no-cache, no-store, must-revalidate"}, ] result = case HTTPoison.post(url, payload , headers) do {:ok, %HTTPoison.Response{status_code: 200, body: body}} -> body {:ok, %HTTPoison.Response{status_code: 404}} -> IO.puts "Not found :(" {:error, %HTTPoison.Error{reason: reason}} -> IO.inspect reason end IO.puts(result) result end end