@@ -17,6 +17,24 @@ public final class okhttp implements Module {
17
17
18
18
@ Override
19
19
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 () {
20
38
MapValue requestBody = new MapValue (5 );
21
39
requestBody .set ("bytes" , args -> {
22
40
Arguments .checkOrOr (2 , 4 , args .length );
@@ -52,30 +70,21 @@ public Map<String, Value> constants() {
52
70
args [1 ].asString ()
53
71
));
54
72
});
73
+ return requestBody ;
74
+ }
55
75
56
-
76
+ private static MapValue multipartBody () {
57
77
MapValue multipartBody = new MapValue (6 );
58
78
multipartBody .set ("ALTERNATIVE" , new StringValue (MultipartBody .ALTERNATIVE .toString ()));
59
79
multipartBody .set ("DIGEST" , new StringValue (MultipartBody .DIGEST .toString ()));
60
80
multipartBody .set ("FORM" , new StringValue (MultipartBody .FORM .toString ()));
61
81
multipartBody .set ("MIXED" , new StringValue (MultipartBody .MIXED .toString ()));
62
82
multipartBody .set ("PARALLEL" , new StringValue (MultipartBody .PARALLEL .toString ()));
63
83
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 ;
75
85
}
76
86
77
- @ Override
78
- public Map <String , Function > functions () {
79
- return Collections .emptyMap ();
87
+ private static HttpClientBuilderValue newClientBuilder () {
88
+ return new HttpClientBuilderValue (new OkHttpClient .Builder ());
80
89
}
81
90
}
0 commit comments