defmodule Teac.Api.Polls do def get(opts) do token = Keyword.fetch!(opts, :token) client_id = Keyword.get(opts, :client_id, Teac.client_id()) case Req.get!(Teac.api_uri() <> "polls", headers: [ {"Authorization", "Bearer #{token}"}, {"Client-Id", client_id} ], params: [] ) do %Req.Response{status: 200, body: %{"data" => data}} -> {:ok, data} %Req.Response{body: body} -> {:error, body} end end def post(opts) do token = Keyword.fetch!(opts, :token) client_id = Keyword.get(opts, :client_id, Teac.client_id()) case Req.post!(Teac.api_uri() <> "polls", headers: [ {"Authorization", "Bearer #{token}"}, {"Client-Id", client_id}, {"Content-Type", "application/x-www-form-urlencoded"} ], form: [], decode_body: :json ) do %Req.Response{status: 200, body: %{"data" => data}} -> {:ok, data} %Req.Response{body: body} -> {:error, body} end end def patch(opts) do token = Keyword.fetch!(opts, :token) client_id = Keyword.get(opts, :client_id, Teac.client_id()) case Req.patch!(Teac.api_uri() <> "polls", headers: [ {"Authorization", "Bearer #{token}"}, {"Client-Id", client_id}, {"Content-Type", "application/x-www-form-urlencoded"} ], form: [], decode_body: :json ) do %Req.Response{status: 200, body: %{"data" => data}} -> {:ok, data} %Req.Response{body: body} -> {:error, body} end end end