Skip to content

Commit 5bb9381

Browse files
committed
Clean up a few dialyzer errors
1 parent 8d6658c commit 5bb9381

File tree

9 files changed

+39
-24
lines changed

9 files changed

+39
-24
lines changed

lib/code_corps/emails/emails.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule CodeCorps.Emails do
4444
case charge |> Transmissions.Receipt.build(invoice) do
4545
%SparkPost.Transmission{} = transmission ->
4646
transmission |> API.send_transmission
47-
build_failure -> build_failure
47+
{:error, reason} -> {:error, reason}
4848
end
4949
end
5050

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule CodeCorps.Emails.ExtendedAPI do
2-
@moduledoc """
2+
@moduledoc ~S"""
33
Serves as an extension of the SparkPost API provided by the elixir-sparkpost
44
library, for features the external package does not support yet
55
@@ -9,31 +9,41 @@ defmodule CodeCorps.Emails.ExtendedAPI do
99

1010
use HTTPoison.Base
1111

12+
alias SparkPost.{Transmission, Endpoint}
13+
1214
@base_url "https://api.sparkpost.com/api/v1"
1315

16+
@spec process_url(String.t) :: String.t
1417
def process_url(url), do: @base_url <> url
1518

19+
@spec process_request_headers(list) :: list
1620
def process_request_headers(headers) do
1721
[
1822
{"Content-Type", "application/json"},
1923
{"Authorization", System.get_env("SPARKPOST_API_KEY")}
2024
] ++ headers
2125
end
2226

27+
@spec process_request_body(String.t) :: map
2328
def process_request_body(body), do: body |> Poison.encode!
29+
30+
@spec process_response_body(String.t) :: map
2431
def process_response_body(body), do: body |> Poison.decode!
2532

33+
@spec create_template(map, list, list) :: {:ok, HTTPoison.Response.t} | {:error, HTTPoison.Error.t}
2634
def create_template(body \\ %{}, headers \\ [], options \\ []) do
2735
start()
2836
post("/templates", body, headers, options)
2937
end
3038

39+
@spec update_template(String.t, map, list, list) :: {:ok, HTTPoison.Response.t} | {:error, HTTPoison.Error.t}
3140
def update_template(id, body \\ %{}, headers \\ [], options \\ []) do
3241
start()
3342
put("/templates/#{id}", body, headers, options)
3443
end
3544

36-
def send_transmission(content) do
37-
SparkPost.Transmission.send(content)
45+
@spec send_transmission(%Transmission{}) :: %Transmission.Response{} | %Endpoint.Error{}
46+
def send_transmission(%Transmission{} = transmission) do
47+
transmission |> SparkPost.Transmission.send
3848
end
3949
end

lib/code_corps/emails/recipient.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule CodeCorps.Emails.Recipient do
22
@moduledoc ~S"""
3-
In charge of adapting `CodeCorps.User` data into SparkPost recipient data.
3+
In charge of adapting CodeCorps data into SparkPost recipient data.
44
"""
55

66
alias CodeCorps.{OrganizationInvite, User}

lib/code_corps/emails/transmissions/message_initiated_by_project.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule CodeCorps.Emails.Transmissions.MessageInitiatedByProject do
99
WebClient
1010
}
1111

12-
@spec build(User.t, String.t) :: %Transmission{}
12+
@spec build(Message.t, Conversation.t) :: %Transmission{}
1313
def build(
1414
%Message{project: %Project{} = project},
1515
%Conversation{user: %User{} = user} = conversation) do

lib/code_corps/emails/transmissions/receipt.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule CodeCorps.Emails.Transmissions.Receipt do
2020
"https://d3pgew4wbk2vb1.cloudfront.net/emails/images/emoji-1f64c-1f3ff@2x.png"
2121
]
2222

23-
@spec build(StripeConnectCharge.t, Stripe.Invoice.t) :: %Transmission{}
23+
@spec build(StripeConnectCharge.t, Stripe.Invoice.t) :: %Transmission{} | {:error, atom}
2424
def build(%StripeConnectCharge{} = charge, %Stripe.Invoice{} = invoice) do
2525
with %StripeConnectCharge{user: %User{} = user} = charge <- Repo.preload(charge, :user),
2626
%Project{} = project <- invoice.subscription |> get_project(),
@@ -45,7 +45,9 @@ defmodule CodeCorps.Emails.Transmissions.Receipt do
4545
}
4646
else
4747
nil -> {:error, :project_not_found}
48-
other -> other
48+
{:error, :donation_goal_not_found} -> {:error, :donation_goal_not_found}
49+
{:error, :subscription_not_found} -> {:error, :subscription_not_found}
50+
%StripeConnectCharge{user: nil} -> {:error, :charge_not_associated_to_user}
4951
end
5052
end
5153

lib/code_corps/messages/conversation_parts.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ defmodule CodeCorps.Messages.ConversationParts do
1212
Repo
1313
}
1414
alias CodeCorpsWeb.ConversationChannel
15+
alias Ecto.Changeset
1516

16-
@spec create(map) :: ConversationPart.t | Ecto.Changeset.t
17+
@spec create(map) :: {:ok, ConversationPart.t} | {:error, Changeset.t}
1718
def create(attrs) do
1819
with {:ok, %ConversationPart{} = conversation_part} <- %ConversationPart{} |> create_changeset(attrs) |> Repo.insert() do
1920
ConversationChannel.broadcast_new_conversation_part(conversation_part)
2021
{:ok, conversation_part}
22+
else
23+
{:error, %Changeset{} = changeset} -> {:error, changeset}
2124
end
2225
end
2326

lib/code_corps/messages/emails.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ defmodule CodeCorps.Messages.Emails do
66
ConversationPart,
77
Emails,
88
Message,
9-
Repo
9+
Repo,
10+
User
1011
}
1112

1213
@message_preloads [:project, [conversations: :user]]
@@ -44,8 +45,9 @@ defmodule CodeCorps.Messages.Emails do
4445
"""
4546
@spec notify_of_new_reply(ConversationPart.t) :: :ok
4647
def notify_of_new_reply(%ConversationPart{} = part) do
47-
part = part |> Repo.preload(@part_preloads)
48-
part |> send_reply_to_conversation_emails()
48+
part
49+
|> Repo.preload(@part_preloads)
50+
|> send_reply_to_conversation_emails()
4951
end
5052

5153
@spec send_reply_to_conversation_emails(ConversationPart.t) :: :ok

lib/code_corps/policy/conversation_part.ex

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@ defmodule CodeCorps.Policy.ConversationPart do
3939
@spec authorize(User.t, ConversationPart.t | map) :: boolean
4040
defp authorize(%User{} = user, attrs) do
4141
%Conversation{} = conversation = attrs |> get_conversation()
42-
is_target? = conversation |> conversation_target?(user)
4342

44-
is_admin? =
45-
conversation
46-
|> get_message()
47-
|> get_project()
48-
|> administered_by?(user)
49-
50-
is_target? or is_admin?
43+
cond do
44+
conversation |> conversation_target?(user) -> true
45+
conversation |> get_message() |> get_project() |> administered_by?(user) -> false
46+
true -> false
47+
end
5148
end
5249

53-
defp conversation_target?(%Conversation{user_id: target_id}, %User{id: user_id}) do
54-
target_id == user_id
55-
end
50+
@spec conversation_target?(Conversation.t, User.t) :: boolean
51+
defp conversation_target?(%Conversation{user_id: target_id}, %User{id: user_id})
52+
when target_id == user_id, do: true
53+
defp conversation_target?(%Conversation{}, %User{}), do: false
5654
end

lib/code_corps/policy/helpers.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ defmodule CodeCorps.Policy.Helpers do
104104
@doc """
105105
Retrieves conversation from associated record
106106
"""
107-
@spec get_conversation(Changeset.t() | ConversationPart.t() | map) :: Message.t()
107+
@spec get_conversation(Changeset.t() | ConversationPart.t() | map) :: Conversation.t()
108108
def get_conversation(%ConversationPart{conversation_id: conversation_id}), do: Repo.get(Conversation, conversation_id)
109109
def get_conversation(%{"conversation_id" => conversation_id}), do: Repo.get(Conversation, conversation_id)
110110
def get_conversation(%Changeset{changes: %{conversation_id: conversation_id}}), do: Repo.get(Conversation, conversation_id)

0 commit comments

Comments
 (0)