http: add support for query parameters, use Jason for JSON encoding instead of Poison...
authorWilliam Pitcock <nenolod@dereferenced.org>
Tue, 15 Jan 2019 19:31:13 +0000 (19:31 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 15 Jan 2019 19:31:13 +0000 (19:31 +0000)
lib/pleroma/http/http.ex
lib/pleroma/http/request_builder.ex

index b8103cef601e6e072b66e9541525e00d309e7e3d..75c58e6c9a07dce77d77389cd489ab338b15ba92 100644 (file)
@@ -31,12 +31,15 @@ defmodule Pleroma.HTTP do
       process_request_options(options)
       |> process_sni_options(url)
 
+    params = Keyword.get(options, :params, [])
+
     %{}
     |> Builder.method(method)
     |> Builder.headers(headers)
     |> Builder.opts(options)
     |> Builder.url(url)
     |> Builder.add_param(:body, :body, body)
+    |> Builder.add_param(:query, :query, params)
     |> Enum.into([])
     |> (&Tesla.request(Connection.new(), &1)).()
   end
index bffc7c6feb8b981ff643c4fcd793249ded6dd856..5f2cff2c0d461be23195d0026cba2ad5ea49488b 100644 (file)
@@ -100,6 +100,8 @@ defmodule Pleroma.HTTP.RequestBuilder do
   Map
   """
   @spec add_param(map(), atom, atom, any()) :: map()
+  def add_param(request, :query, :query, values), do: Map.put(request, :query, values)
+
   def add_param(request, :body, :body, value), do: Map.put(request, :body, value)
 
   def add_param(request, :body, key, value) do
@@ -107,7 +109,10 @@ defmodule Pleroma.HTTP.RequestBuilder do
     |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0)
     |> Map.update!(
       :body,
-      &Tesla.Multipart.add_field(&1, key, Poison.encode!(value),
+      &Tesla.Multipart.add_field(
+        &1,
+        key,
+        Jason.encode!(value),
         headers: [{:"Content-Type", "application/json"}]
       )
     )