Skip to content

Commit 3884e14

Browse files
committed
extract common rest code on client side
1 parent c70bd34 commit 3884e14

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016-2022 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.npm;
17+
18+
abstract class BaseNpmRestService {
19+
20+
protected final SimpleRestClient restClient;
21+
22+
BaseNpmRestService(String baseUrl) {
23+
this.restClient = SimpleRestClient.forBaseUrl(baseUrl);
24+
}
25+
26+
public String shutdown() {
27+
return restClient.post("/shutdown");
28+
}
29+
30+
}

lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,12 +19,10 @@
1919
import java.util.LinkedHashMap;
2020
import java.util.Map;
2121

22-
public class PrettierRestService {
23-
24-
private final SimpleRestClient restClient;
22+
public class PrettierRestService extends BaseNpmRestService {
2523

2624
PrettierRestService(String baseUrl) {
27-
this.restClient = SimpleRestClient.forBaseUrl(baseUrl);
25+
super(baseUrl);
2826
}
2927

3028
public String resolveConfig(File prettierConfigPath, Map<String, Object> prettierConfigOptions) {
@@ -48,9 +46,4 @@ public String format(String fileContent, String configOptionsJsonString) {
4846

4947
return restClient.postJson("/prettier/format", jsonProperties);
5048
}
51-
52-
public String shutdown() {
53-
return restClient.post("/shutdown");
54-
}
55-
5649
}

lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,12 +18,10 @@
1818
import java.util.LinkedHashMap;
1919
import java.util.Map;
2020

21-
public class TsFmtRestService {
22-
23-
private final SimpleRestClient restClient;
21+
public class TsFmtRestService extends BaseNpmRestService {
2422

2523
TsFmtRestService(String baseUrl) {
26-
this.restClient = SimpleRestClient.forBaseUrl(baseUrl);
24+
super(baseUrl);
2725
}
2826

2927
public String format(String fileContent, Map<String, Object> configOptions) {
@@ -35,9 +33,4 @@ public String format(String fileContent, Map<String, Object> configOptions) {
3533

3634
return restClient.postJson("/tsfmt/format", jsonProperties);
3735
}
38-
39-
public String shutdown() {
40-
return restClient.post("/shutdown");
41-
}
42-
4336
}

0 commit comments

Comments
 (0)