11defmodule ComponentsGuide.Fetch.Request do
22 defstruct method: "GET" , url_string: "" , uri: % URI { } , headers: [ ] , body: nil
33
4- def new! ( url_string , options \\ [ ] ) do
4+ def new ( uri_or_url_string , options \\ [ ] )
5+
6+ def new ( uri = % URI { } , options ) do
57 headers = Keyword . get ( options , :headers , [ ] )
68 method = Keyword . get ( options , :method , "GET" )
79 body = Keyword . get ( options , :body )
8- uri = URI . new! ( url_string )
10+ url_string = URI . to_string ( uri )
911 % __MODULE__ { method: method , url_string: url_string , uri: uri , headers: headers , body: body }
1012 end
1113
12- def new ( url_string , options \\ [ ] ) do
14+ def new ( url_string , options ) when is_binary ( url_string ) do
1315 headers = Keyword . get ( options , :headers , [ ] )
1416 method = Keyword . get ( options , :method , "GET" )
1517 body = Keyword . get ( options , :body )
@@ -21,4 +23,14 @@ defmodule ComponentsGuide.Fetch.Request do
2123 { :error , _ } = value -> value
2224 end
2325 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
2436end
0 commit comments