@@ -7,11 +7,11 @@ defmodule Algora.Github.Client do
7
7
@ type token :: String . t ( )
8
8
9
9
# TODO: move to a separate module and use only for data migration between databases
10
- def http_cached ( host , method , path , headers , body ) do
10
+ def http_cached ( host , method , path , headers , body , opts \\ [ ] ) do
11
11
cache_path = ".local/github/#{ path } .json"
12
12
13
13
with :error <- read_from_cache ( cache_path ) ,
14
- { :ok , response_body } <- do_http_request ( host , method , path , headers , body ) do
14
+ { :ok , response_body } <- do_http_request ( host , method , path , headers , body , opts ) do
15
15
write_to_cache ( cache_path , response_body )
16
16
{ :ok , response_body }
17
17
else
@@ -20,18 +20,18 @@ defmodule Algora.Github.Client do
20
20
end
21
21
end
22
22
23
- def http ( host , method , path , headers , body ) do
24
- do_http_request ( host , method , path , headers , body )
23
+ def http ( host , method , path , headers , body , opts \\ [ ] ) do
24
+ do_http_request ( host , method , path , headers , body , opts )
25
25
end
26
26
27
- defp do_http_request ( host , method , path , headers , body ) do
27
+ defp do_http_request ( host , method , path , headers , body , opts ) do
28
28
url = "https://#{ host } #{ path } "
29
29
headers = [ { "Content-Type" , "application/json" } | headers ]
30
30
31
31
with { :ok , encoded_body } <- Jason . encode ( body ) ,
32
32
request = Finch . build ( method , url , headers , encoded_body ) ,
33
33
{ :ok , response } <- Finch . request ( request , Algora.Finch ) do
34
- handle_response ( response )
34
+ if opts [ :skip_decoding ] , do: { :ok , response . body } , else: handle_response ( response )
35
35
end
36
36
end
37
37
@@ -67,17 +67,19 @@ defmodule Algora.Github.Client do
67
67
File . write! ( cache_path , Jason . encode! ( data ) )
68
68
end
69
69
70
- def fetch ( access_token , url , method \\ "GET" , body \\ nil )
70
+ def fetch ( access_token , url , method \\ "GET" , body \\ nil , opts \\ [ ] )
71
71
72
- def fetch ( access_token , "https://api.github.com" <> path , method , body ) , do: fetch ( access_token , path , method , body )
72
+ def fetch ( access_token , "https://api.github.com" <> path , method , body , opts ) ,
73
+ do: fetch ( access_token , path , method , body , opts )
73
74
74
- def fetch ( access_token , path , method , body ) do
75
+ def fetch ( access_token , path , method , body , opts ) do
75
76
http (
76
77
"api.github.com" ,
77
78
method ,
78
79
path ,
79
80
[ { "accept" , "application/vnd.github.v3+json" } , { "Authorization" , "Bearer #{ access_token } " } ] ,
80
- body
81
+ body ,
82
+ opts
81
83
)
82
84
end
83
85
@@ -185,4 +187,9 @@ defmodule Algora.Github.Client do
185
187
def add_labels ( access_token , owner , repo , number , labels ) do
186
188
fetch ( access_token , "/repos/#{ owner } /#{ repo } /issues/#{ number } /labels" , "POST" , % { labels: labels } )
187
189
end
190
+
191
+ @ impl true
192
+ def render_markdown ( access_token , markdown ) do
193
+ fetch ( access_token , "/markdown" , "POST" , % { text: markdown } , skip_decoding: true )
194
+ end
188
195
end
0 commit comments