A set of utilities for working with the AT Protocol in Elixir.
at v0.2.0 492 B view raw
1defmodule Atex.XRPC.Adapter.Req do 2 @moduledoc """ 3 `Req` adapter for XRPC. 4 """ 5 6 @behaviour Atex.XRPC.Adapter 7 8 def get(url, opts) do 9 Req.get(url, opts) |> adapt() 10 end 11 12 def post(url, opts) do 13 Req.post(url, opts) |> adapt() 14 end 15 16 defp adapt({:ok, %Req.Response{status: 200} = res}) do 17 {:ok, res.body} 18 end 19 20 defp adapt({:ok, %Req.Response{} = res}) do 21 {:error, res.status, res.body} 22 end 23 24 defp adapt({:error, exception}) do 25 {:error, exception} 26 end 27end