status_code -> status

This commit is contained in:
Maksim Pechnikov 2018-12-02 17:08:36 +03:00
parent 97252a27d9
commit 87109482f3
9 changed files with 17 additions and 15 deletions

View File

@ -20,7 +20,7 @@ def put_file(upload) do
extension = String.split(upload.name, ".") |> List.last() extension = String.split(upload.name, ".") |> List.last()
query = "#{cgi}?#{extension}" query = "#{cgi}?#{extension}"
with {:ok, %{status_code: 200, body: body}} <- @httpoison.post(query, file_data) do with {:ok, %{status: 200, body: body}} <- @httpoison.post(query, file_data) do
remote_file_name = String.split(body) |> List.first() remote_file_name = String.split(body) |> List.first()
public_url = "#{files}/#{remote_file_name}.#{extension}" public_url = "#{files}/#{remote_file_name}.#{extension}"
{:ok, {:url, public_url}} {:ok, {:url, public_url}}

View File

@ -25,10 +25,10 @@ def get_token() do
["Content-Type": "application/json"], ["Content-Type": "application/json"],
hackney: [:insecure] hackney: [:insecure]
) do ) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} -> {:ok, %Tesla.Env{status: 200, body: body}} ->
body["access"]["token"]["id"] body["access"]["token"]["id"]
{:ok, %HTTPoison.Response{status_code: _}} -> {:ok, %Tesla.Env{status: _}} ->
"" ""
end end
end end

View File

@ -13,10 +13,10 @@ def upload_file(filename, body, content_type) do
token = Pleroma.Uploaders.Swift.Keystone.get_token() token = Pleroma.Uploaders.Swift.Keystone.get_token()
case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do
{:ok, %HTTPoison.Response{status_code: 201}} -> {:ok, %Tesla.Env{status: 201}} ->
{:ok, {:file, filename}} {:ok, {:file, filename}}
{:ok, %HTTPoison.Response{status_code: 401}} -> {:ok, %Tesla.Env{status: 401}} ->
{:error, "Unauthorized, Bad Token"} {:error, "Unauthorized, Bad Token"}
{:error, _} -> {:error, _} ->

View File

@ -762,7 +762,7 @@ def fetch_and_contain_remote_object_from_id(id) do
Logger.info("Fetching #{id} via AP") Logger.info("Fetching #{id} via AP")
with true <- String.starts_with?(id, "http"), with true <- String.starts_with?(id, "http"),
{:ok, %{body: body, status_code: code}} when code in 200..299 <- {:ok, %{body: body, status: code}} when code in 200..299 <-
@httpoison.get( @httpoison.get(
id, id,
[Accept: "application/activity+json"], [Accept: "application/activity+json"],

View File

@ -1168,7 +1168,7 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do
user = user.nickname user = user.nickname
url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user)
with {:ok, %{status_code: 200, body: body}} <- with {:ok, %{status: 200, body: body}} <-
@httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout),
{:ok, data} <- Jason.decode(body) do {:ok, data} <- Jason.decode(body) do
data2 = data2 =

View File

@ -346,13 +346,15 @@ def get_atom_url(body) do
def fetch_activity_from_atom_url(url) do def fetch_activity_from_atom_url(url) do
with true <- String.starts_with?(url, "http"), with true <- String.starts_with?(url, "http"),
{:ok, %{body: body, status_code: code}} when code in 200..299 <- {:ok, %{body: body, status: code}} when code in 200..299 <-
@httpoison.get( @httpoison.get(
url, url,
[Accept: "application/atom+xml"], [Accept: "application/atom+xml"],
follow_redirect: true, follow_redirect: true,
adapter: [
timeout: 10000, timeout: 10000,
recv_timeout: 20000 recv_timeout: 20000
]
) do ) do
Logger.debug("Got document from #{url}, handling...") Logger.debug("Got document from #{url}, handling...")
handle_incoming(body) handle_incoming(body)

View File

@ -220,7 +220,7 @@ def get_template_from_xml(body) do
end end
def find_lrdd_template(domain) do def find_lrdd_template(domain) do
with {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- with {:ok, %{status: status, body: body}} when status in 200..299 <-
@httpoison.get("http://#{domain}/.well-known/host-meta", [], follow_redirect: true) do @httpoison.get("http://#{domain}/.well-known/host-meta", [], follow_redirect: true) do
get_template_from_xml(body) get_template_from_xml(body)
else else
@ -259,7 +259,7 @@ def finger(account) do
[Accept: "application/xrd+xml,application/jrd+json"], [Accept: "application/xrd+xml,application/jrd+json"],
follow_redirect: true follow_redirect: true
), ),
{:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response do {:ok, %{status: status, body: body}} when status in 200..299 <- response do
doc = XML.parse_document(body) doc = XML.parse_document(body)
if doc != :error do if doc != :error do

View File

@ -173,7 +173,7 @@ def subscribe(subscriber, subscribed, requester \\ &request_subscription/1) do
def gather_feed_data(topic, getter \\ &@httpoison.get/1) do def gather_feed_data(topic, getter \\ &@httpoison.get/1) do
with {:ok, response} <- getter.(topic), with {:ok, response} <- getter.(topic),
status_code when status_code in 200..299 <- response.status, status when status in 200..299 <- response.status,
body <- response.body, body <- response.body,
doc <- XML.parse_document(body), doc <- XML.parse_document(body),
uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc), uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc),

View File

@ -184,7 +184,7 @@ test "rejects the subscription if it can't be accepted" do
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic}) websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers -> poster = fn ^hub, {:form, _data}, _headers ->
{:ok, %{status_code: 202}} {:ok, %{status: 202}}
end end
{:error, websub} = Websub.request_subscription(websub, poster, 1000) {:error, websub} = Websub.request_subscription(websub, poster, 1000)
@ -193,7 +193,7 @@ test "rejects the subscription if it can't be accepted" do
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic}) websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers -> poster = fn ^hub, {:form, _data}, _headers ->
{:ok, %{status_code: 400}} {:ok, %{status: 400}}
end end
{:error, websub} = Websub.request_subscription(websub, poster, 1000) {:error, websub} = Websub.request_subscription(websub, poster, 1000)