Packages

This package is used for learning purposes on how to use 'mix' and 'hex' for sharing elixir code. Do NOT waste your time here. The License is MIT, but the project uses a private api.

Current section

Files

Jump to
cape lib Arpas REST Cae Api.ex
Raw

lib/Arpas/REST/Cae/Api.ex

defmodule Arpas.REST.Cae.Api do
@moduledoc ~S'''
CAE rest
'''
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=#{Env.client_instance()}"
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