1
1
defmodule ComponentsGuide.Fetch.Request do
2
2
defstruct method: "GET" , url_string: "" , uri: % URI { } , headers: [ ] , body: nil
3
3
4
- def new! ( url_string , options \\ [ ] ) do
4
+ def new ( uri_or_url_string , options \\ [ ] )
5
+
6
+ def new ( uri = % URI { } , options ) do
5
7
headers = Keyword . get ( options , :headers , [ ] )
6
8
method = Keyword . get ( options , :method , "GET" )
7
9
body = Keyword . get ( options , :body )
8
- uri = URI . new! ( url_string )
10
+ url_string = URI . to_string ( uri )
9
11
% __MODULE__ { method: method , url_string: url_string , uri: uri , headers: headers , body: body }
10
12
end
11
13
12
- def new ( url_string , options \\ [ ] ) do
14
+ def new ( url_string , options ) when is_binary ( url_string ) do
13
15
headers = Keyword . get ( options , :headers , [ ] )
14
16
method = Keyword . get ( options , :method , "GET" )
15
17
body = Keyword . get ( options , :body )
@@ -21,4 +23,14 @@ defmodule ComponentsGuide.Fetch.Request do
21
23
{ :error , _ } = value -> value
22
24
end
23
25
end
26
+
27
+ def new! ( uri_or_url_string , options \\ [ ] )
28
+
29
+ def new! ( url_string , options ) when is_binary ( url_string ) do
30
+ headers = Keyword . get ( options , :headers , [ ] )
31
+ method = Keyword . get ( options , :method , "GET" )
32
+ body = Keyword . get ( options , :body )
33
+ uri = URI . new! ( url_string )
34
+ % __MODULE__ { method: method , url_string: url_string , uri: uri , headers: headers , body: body }
35
+ end
24
36
end
0 commit comments