@@ -18,8 +18,16 @@ defmodule Helper.AuditBot do
18
18
audit_failed_reason: ""
19
19
}
20
20
"""
21
+ use Tesla , only: [ :post ]
21
22
import Helper.Utils , only: [ get_config: 2 ]
22
23
24
+ @ timeout_limit 4000
25
+
26
+ plug ( Tesla.Middleware.Headers , [ { "Content-Type" , "application/x-www-form-urlencoded" } ] )
27
+ plug ( Tesla.Middleware.Retry , delay: 300 , max_retries: 3 )
28
+ plug ( Tesla.Middleware.Timeout , timeout: @ timeout_limit )
29
+ plug ( Tesla.Middleware.FormUrlencoded )
30
+
23
31
# conclusionType === 1
24
32
@ conclusionOK 1
25
33
@ conclusionMaybe 3
@@ -35,26 +43,26 @@ defmodule Helper.AuditBot do
35
43
{ "Content-Type" , "application/x-www-form-urlencoded" }
36
44
]
37
45
38
- text = text |> HtmlSanitizeEx . strip_tags ( )
46
+ query = % {
47
+ text: text |> HtmlSanitizeEx . strip_tags ( )
48
+ }
39
49
40
- with { :ok , result } <- HTTPoison . post ( get_endpoint ( ) , { :form , [ text: text ] } , headers ) do
50
+ with { :ok , result } <- post ( get_endpoint ( ) , query ) do
41
51
parse_result ( result )
42
52
end
43
53
end
44
54
45
55
def analysis_wrong ( :text , text ) do
46
- headers = [
47
- { "Content-Type" , "application/x-www-form-urlencoded" }
48
- ]
49
-
50
- text = text |> HtmlSanitizeEx . strip_tags ( )
56
+ query = % {
57
+ text: text |> HtmlSanitizeEx . strip_tags ( )
58
+ }
51
59
52
- with { :ok , result } <- HTTPoison . post ( @ wrong_endpoint , { :form , [ text: text ] } , headers ) do
60
+ with { :ok , result } <- post ( @ wrong_endpoint , query ) do
53
61
parse_result ( result )
54
62
end
55
63
end
56
64
57
- defp parse_result ( % HTTPoison.Response { body: body , status_code : 200 } ) do
65
+ defp parse_result ( % Tesla.Env { body: body , status : 200 } ) do
58
66
with { :ok , result } <- Jason . decode ( body ) ,
59
67
{ :ok , result } <- is_request_ok? ( result ) do
60
68
conclusion = result [ "conclusionType" ]
0 commit comments