Repository: wojtekmach/req (elixir)

Issue:
Add Req.put!/3 and Req.delete!/2

Pull request:
Req.put!/3 and Req.delete!/2
Closes #32


Patch:
diff --git a/lib/req.ex b/lib/req.ex
index d78b5c4..ab4d5bc 100644
--- a/lib/req.ex
+++ b/lib/req.ex
@@ -29,6 +29,27 @@ defmodule Req do
     request!(:post, uri, options)
   end
 
+  @doc """
+  Makes a PUT request.
+
+  See `request/3` for a list of supported options.
+  """
+  @doc api: :high_level
+  def put!(uri, body, options \\ []) do
+    options = Keyword.put(options, :body, body)
+    request!(:put, uri, options)
+  end
+
+  @doc """
+  Makes a DELETE request.
+
+  See `request/3` for a list of supported options.
+  """
+  @doc api: :high_level
+  def delete!(uri, options \\ []) do
+    request!(:delete, uri, options)
+  end
+
   @doc """
   Makes an HTTP request.
 
diff --git a/mix.exs b/mix.exs
index ff6f815..fbe3137 100644
--- a/mix.exs
+++ b/mix.exs
@@ -13,6 +13,9 @@ defmodule Req.MixProject do
       deps: deps(),
       package: package(),
       docs: docs(),
+      preferred_cli_env: [
+        docs: :docs
+      ],
       xref: [
         exclude: [
           NimbleCSV.RFC4180


Test patch:
diff --git a/test/req_test.exs b/test/req_test.exs
index 4db9d30..18f610b 100644
--- a/test/req_test.exs
+++ b/test/req_test.exs
@@ -6,14 +6,46 @@ defmodule ReqTest do
     [bypass: bypass, url: "http://localhost:#{bypass.port}"]
   end
 
-  test "high-level API", c do
-    Bypass.expect(c.bypass, "GET", "/json", fn conn ->
-      conn
-      |> Plug.Conn.put_resp_content_type("application/json")
-      |> Plug.Conn.send_resp(200, Jason.encode_to_iodata!(%{"a" => 1}))
-    end)
+  describe "high-level API" do
+    test "get!/2", c do
+      Bypass.expect(c.bypass, "GET", "/json", fn conn ->
+        conn
+        |> Plug.Conn.put_resp_content_type("application/json")
+        |> Plug.Conn.send_resp(200, Jason.encode_to_iodata!(%{"a" => 1}))
+      end)
+
+      assert Req.get!(c.url <> "/json").body == %{"a" => 1}
+    end
 
-    assert Req.get!(c.url <> "/json").body == %{"a" => 1}
+    test "post!/3", c do
+      Bypass.expect(c.bypass, "POST", "/json", fn conn ->
+        conn
+        |> Plug.Conn.put_resp_content_type("application/json")
+        |> Plug.Conn.send_resp(200, Jason.encode_to_iodata!(%{"a" => 1}))
+      end)
+
+      assert Req.post!(c.url <> "/json", {:json, %{foo: "bar"}}).body == %{"a" => 1}
+    end
+
+    test "put!/3", c do
+      Bypass.expect(c.bypass, "PUT", "/json", fn conn ->
+        conn
+        |> Plug.Conn.put_resp_content_type("application/json")
+        |> Plug.Conn.send_resp(200, Jason.encode_to_iodata!(%{"a" => 1}))
+      end)
+
+      assert Req.put!(c.url <> "/json", {:json, %{foo: "bar"}}).body == %{"a" => 1}
+    end
+
+    test "delete!/2", c do
+      Bypass.expect(c.bypass, "DELETE", "/json", fn conn ->
+        conn
+        |> Plug.Conn.put_resp_content_type("application/json")
+        |> Plug.Conn.send_resp(200, Jason.encode_to_iodata!(%{"a" => 1}))
+      end)
+
+      assert Req.delete!(c.url <> "/json").body == %{"a" => 1}
+    end
   end
 
   test "raw mode", c do