@@ -17,6 +17,24 @@ public final class okhttp implements Module {
1717
1818 @ Override
1919 public Map <String , Value > constants () {
20+ MapValue okhttp = new MapValue (3 );
21+ okhttp .set ("client" , defaultClient );
22+ okhttp .set ("request" , args -> new RequestBuilderValue ());
23+ okhttp .set ("newClient" , args -> newClientBuilder ());
24+
25+ return Map .of (
26+ "RequestBody" , requestBody (),
27+ "MultipartBody" , multipartBody (),
28+ "okhttp" , okhttp
29+ );
30+ }
31+
32+ @ Override
33+ public Map <String , Function > functions () {
34+ return Collections .emptyMap ();
35+ }
36+
37+ private static MapValue requestBody () {
2038 MapValue requestBody = new MapValue (5 );
2139 requestBody .set ("bytes" , args -> {
2240 Arguments .checkOrOr (2 , 4 , args .length );
@@ -52,30 +70,21 @@ public Map<String, Value> constants() {
5270 args [1 ].asString ()
5371 ));
5472 });
73+ return requestBody ;
74+ }
5575
56-
76+ private static MapValue multipartBody () {
5777 MapValue multipartBody = new MapValue (6 );
5878 multipartBody .set ("ALTERNATIVE" , new StringValue (MultipartBody .ALTERNATIVE .toString ()));
5979 multipartBody .set ("DIGEST" , new StringValue (MultipartBody .DIGEST .toString ()));
6080 multipartBody .set ("FORM" , new StringValue (MultipartBody .FORM .toString ()));
6181 multipartBody .set ("MIXED" , new StringValue (MultipartBody .MIXED .toString ()));
6282 multipartBody .set ("PARALLEL" , new StringValue (MultipartBody .PARALLEL .toString ()));
6383 multipartBody .set ("builder" , args -> new MultipartBodyBuilderValue ());
64-
65-
66- MapValue okhttp = new MapValue (3 );
67- okhttp .set ("client" , defaultClient );
68- okhttp .set ("request" , args -> new RequestBuilderValue ());
69-
70- return Map .of (
71- "RequestBody" , requestBody ,
72- "MultipartBody" , multipartBody ,
73- "okhttp" , okhttp
74- );
84+ return multipartBody ;
7585 }
7686
77- @ Override
78- public Map <String , Function > functions () {
79- return Collections .emptyMap ();
87+ private static HttpClientBuilderValue newClientBuilder () {
88+ return new HttpClientBuilderValue (new OkHttpClient .Builder ());
8089 }
8190}
0 commit comments