-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReferenceDataApiClient.java
More file actions
51 lines (41 loc) · 1.83 KB
/
Copy pathReferenceDataApiClient.java
File metadata and controls
51 lines (41 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//------------------------------------------------------------------
// Copyright 2020 mobile.de GmbH.
// Author/Developer: Philipp Bartsch
//
// This code is licensed under MIT license (see LICENSE for details)
//------------------------------------------------------------------
package org.example.moveclient;
import static java.lang.String.format;
import ecg.move.sellermodel.listing.RefMake;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.Response.StatusType;
public class ReferenceDataApiClient {
private final String moveBaseUrl;
public ReferenceDataApiClient(String moveBaseUrl) {
this.moveBaseUrl = moveBaseUrl;
}
public List<RefMake> getMakesAndModels(String partnerId, String vehicleClassId) {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(moveBaseUrl);
WebTarget getListingByPartnerAndForeignId = webTarget
.path("/refdata/partners/{partnerId}/vehicle-classes/{vehicleClassId}/makes-models")
.resolveTemplate("partnerId", partnerId)
.resolveTemplate("vehicleClassId", vehicleClassId);
Response response = getListingByPartnerAndForeignId
.request()
.accept(MediaType.APPLICATION_JSON)
.get();
StatusType statusInfo = response.getStatusInfo();
if (!statusInfo.getFamily().equals(Family.SUCCESSFUL)) {
throw new IllegalStateException(format("Unexpected response while GETting list of supported makes/models: %s", statusInfo));
}
return response.readEntity(new GenericType<>() {});
}
}