diff options
author | href <href@random.sh> | 2022-12-03 02:00:37 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-11 02:03:36 +0000 |
commit | 251ea43c1308eb96e4ada16edf6481a8be1fa765 (patch) | |
tree | 2148e304574c684f7eb1e74607634a907df9085d /lib/couch.ex | |
parent | new plugin: radio france (diff) |
new plugin: openai gpt
Diffstat (limited to 'lib/couch.ex')
-rw-r--r-- | lib/couch.ex | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/couch.ex b/lib/couch.ex new file mode 100644 index 0000000..fdd8579 --- /dev/null +++ b/lib/couch.ex @@ -0,0 +1,18 @@ +defmodule Couch do + def get(db, doc) do + config = Application.get_env(:lsg, :couch) + url = [Keyword.get(config, :url), db, doc] |> Enum.join("/") + user = Keyword.get(config, :user) + pass = Keyword.get(config, :pass) + client_options = Keyword.get(config, :client_options, []) + headers = [{"accept", "application/json"}, {"user-agent", "beautte"}] + options = [hackney: [:insecure, {:basic_auth, {user, pass}}]] ++ client_options + case HTTPoison.get(url, headers, options) do + {:ok, %HTTPoison.Response{status_code: 200, body: body}} -> + {:ok, Poison.decode!(body)} + {:ok, %HTTPoison.Response{status_code: 404}} -> + {:error, :not_found} + error -> {:error, {:couchdb_error, error}} + end + end +end |