@@ -331,49 +331,38 @@ defmodule AlgoraWeb.Admin.CampaignLive do
331331 end )
332332 end
333333
334- @ spec deliver_email (
335- recipient :: map ( ) ,
336- subject :: String . t ( ) ,
337- template_params :: Keyword . t ( ) ,
338- from :: { String . t ( ) , String . t ( ) } ,
339- opts :: Keyword . t ( )
340- ) ::
341- { :ok , term } | { :error , term }
342- def deliver_email ( recipient , subject , template_params , from , opts \\ [ ] ) do
334+ def deliver_email ( opts ) do
335+ recipient = opts [ :recipient ]
336+
343337 case :get
344338 |> Finch . build ( "https://algora.io/og/go/#{ recipient [ "repo_owner" ] } /#{ recipient [ "repo_name" ] } " )
345339 |> Finch . request ( Algora.Finch ) do
346340 { :ok , % Finch.Response { status: status , body: body } } when status in 200 .. 299 ->
347- deliver (
348- recipient [ "email" ] ,
349- subject ,
350- template_params ,
351- from ,
352- [
353- Swoosh.Attachment . new ( { :data , body } ,
354- filename: "#{ recipient [ "repo_owner" ] } .png" ,
355- content_type: "image/png" ,
356- type: :inline
357- )
358- ] ,
359- opts
360- )
341+ opts
342+ |> Keyword . put ( :attachments , [
343+ Swoosh.Attachment . new ( { :data , body } ,
344+ filename: "#{ recipient [ "repo_owner" ] } .png" ,
345+ content_type: "image/png" ,
346+ type: :inline
347+ )
348+ ] )
349+ |> deliver ( )
361350
362351 { :error , reason } ->
363352 raise reason
364353 end
365354 end
366355
367- defp deliver ( to , subject , template_params , from , attachments , opts \\ [ ] ) do
356+ defp deliver ( opts ) do
368357 email =
369358 Email . new ( )
370- |> Email . to ( to )
371- |> Email . from ( from )
372- |> Email . subject ( subject )
373- |> Email . text_body ( Mailer . text_template ( template_params ) )
374- |> Email . html_body ( Mailer . html_template ( template_params , preheader: opts [ :preheader ] ) )
359+ |> Email . to ( opts [ :recipient ] [ "email" ] )
360+ |> Email . from ( opts [ : from] )
361+ |> Email . subject ( opts [ : subject] )
362+ |> Email . text_body ( Mailer . text_template ( opts [ : template_params] ) )
363+ |> Email . html_body ( Mailer . html_template ( opts [ : template_params] , preheader: opts [ :preheader ] ) )
375364
376- email = Enum . reduce ( attachments , email , fn attachment , acc -> Email . attachment ( acc , attachment ) end )
365+ email = Enum . reduce ( opts [ : attachments] , email , fn attachment , acc -> Email . attachment ( acc , attachment ) end )
377366
378367 Mailer . deliver_with_logging ( email )
379368 end
0 commit comments