Skip to content

Commit a7fb8fb

Browse files
committed
introduce reuse of constructors everywhere
1 parent b6af917 commit a7fb8fb

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

core/src/main/java/com/panic08/funpay4j/AuthorizedFunPayExecutor.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,22 @@ public class AuthorizedFunPayExecutor extends FunPayExecutor {
7272
* Creates a new AuthorizedFunPayExecutor instance
7373
*
7474
* @param goldenKey golden key which will be used to authorize the user
75+
* @param baseURL base URL of the primary server
76+
* @param proxy proxy for forwarding requests
7577
*/
76-
public AuthorizedFunPayExecutor(@NonNull String goldenKey) {
77-
super();
78-
78+
public AuthorizedFunPayExecutor(
79+
@NonNull String goldenKey, @NonNull String baseURL, Proxy proxy) {
80+
super(baseURL, proxy);
7981
this.goldenKey = goldenKey;
8082
}
8183

8284
/**
8385
* Creates a new AuthorizedFunPayExecutor instance
8486
*
8587
* @param goldenKey golden key which will be used to authorize the user
86-
* @param baseURL base URL of the primary server
87-
* @param proxy proxy for forwarding requests
8888
*/
89-
public AuthorizedFunPayExecutor(
90-
@NonNull String goldenKey, @NonNull String baseURL, @NonNull Proxy proxy) {
91-
super(baseURL, proxy);
92-
93-
this.goldenKey = goldenKey;
89+
public AuthorizedFunPayExecutor(@NonNull String goldenKey) {
90+
this(goldenKey, FunPayURL.BASE_URL, null);
9491
}
9592

9693
/**
@@ -100,9 +97,7 @@ public AuthorizedFunPayExecutor(
10097
* @param baseURL base URL of the primary server
10198
*/
10299
public AuthorizedFunPayExecutor(@NonNull String goldenKey, @NonNull String baseURL) {
103-
super(baseURL);
104-
105-
this.goldenKey = goldenKey;
100+
this(goldenKey, baseURL, null);
106101
}
107102

108103
/**
@@ -112,9 +107,7 @@ public AuthorizedFunPayExecutor(@NonNull String goldenKey, @NonNull String baseU
112107
* @param proxy proxy for forwarding requests
113108
*/
114109
public AuthorizedFunPayExecutor(@NonNull String goldenKey, @NonNull Proxy proxy) {
115-
super(proxy);
116-
117-
this.goldenKey = goldenKey;
110+
this(goldenKey, FunPayURL.BASE_URL, proxy);
118111
}
119112

120113
/**

core/src/main/java/com/panic08/funpay4j/FunPayExecutor.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,37 @@ public class FunPayExecutor {
6161

6262
@NonNull protected final FunPayClient funPayClient;
6363

64-
/** Creates a new FunPayExecutor instance */
65-
public FunPayExecutor() {
66-
OkHttpClient httpClient = new OkHttpClient();
67-
68-
this.funPayParser = new JsoupFunPayParser(httpClient, FunPayURL.BASE_URL);
69-
this.funPayClient = new OkHttpFunPayClient(httpClient, FunPayURL.BASE_URL);
70-
}
71-
7264
/**
7365
* Creates a new FunPayExecutor instance
7466
*
7567
* @param baseURL base URL of the primary server
7668
* @param proxy proxy for forwarding requests
7769
*/
78-
public FunPayExecutor(@NonNull String baseURL, @NonNull Proxy proxy) {
79-
OkHttpClient httpClient = new OkHttpClient.Builder().proxy(proxy).build();
70+
public FunPayExecutor(@NonNull String baseURL, Proxy proxy) {
71+
OkHttpClient httpClient;
72+
73+
if (proxy == null) {
74+
httpClient = new OkHttpClient();
75+
} else {
76+
httpClient = new OkHttpClient.Builder().proxy(proxy).build();
77+
}
8078

8179
this.funPayParser = new JsoupFunPayParser(httpClient, baseURL);
8280
this.funPayClient = new OkHttpFunPayClient(httpClient, baseURL);
8381
}
8482

83+
/** Creates a new FunPayExecutor instance */
84+
public FunPayExecutor() {
85+
this(FunPayURL.BASE_URL, null);
86+
}
87+
8588
/**
8689
* Creates a new FunPayExecutor instance
8790
*
8891
* @param baseURL base URL of the primary server
8992
*/
9093
public FunPayExecutor(@NonNull String baseURL) {
91-
OkHttpClient httpClient = new OkHttpClient();
92-
93-
this.funPayParser = new JsoupFunPayParser(httpClient, baseURL);
94-
this.funPayClient = new OkHttpFunPayClient(httpClient, baseURL);
94+
this(baseURL, null);
9595
}
9696

9797
/**
@@ -100,10 +100,7 @@ public FunPayExecutor(@NonNull String baseURL) {
100100
* @param proxy proxy for forwarding requests
101101
*/
102102
public FunPayExecutor(@NonNull Proxy proxy) {
103-
OkHttpClient httpClient = new OkHttpClient.Builder().proxy(proxy).build();
104-
105-
this.funPayParser = new JsoupFunPayParser(httpClient, FunPayURL.BASE_URL);
106-
this.funPayClient = new OkHttpFunPayClient(httpClient, FunPayURL.BASE_URL);
103+
this(FunPayURL.BASE_URL, proxy);
107104
}
108105

109106
/**

0 commit comments

Comments
 (0)