diff options
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 |