1 package com.srv4pos.server.api.softwareVendor;
2
3 import com.srv4pos.server.api.infrastructure.EmptyConnectionWriter;
4 import com.srv4pos.server.api.infrastructure.HttpMethod;
5 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
6 import com.srv4pos.server.api.infrastructure.http.HttpHelper;
7 import com.srv4pos.server.api.infrastructure.http.Transport;
8 import com.srv4pos.server.api.infrastructure.request.StringResponse;
9
10 import java.net.URL;
11 import java.util.List;
12
13 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
14 import static java.lang.String.format;
15
16
17
18
19
20 public class SoftwareVendorService {
21 private URL url;
22 private Credentials credentials;
23 private Transport transport;
24
25
26
27
28
29
30
31
32 public SoftwareVendorService(URL url, Credentials credentials, Transport transport) {
33 this.url = url;
34 this.credentials = credentials;
35 this.transport = transport;
36 }
37
38
39
40
41
42
43
44
45 public SoftwareVendorInfo get(long id) {
46 return SoftwareVendorInfo.fromJsonToSoftwareVendorInfo(requestString(
47 format("software-vendors/%s", id),
48 HttpMethod.GET,
49 url,
50 credentials.toAuthentication(),
51 null,
52 null,
53 EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
54 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
55 transport).getContent());
56 }
57
58
59
60
61
62
63 public List<SoftwareVendorInfo> list() {
64
65 StringResponse response = requestString(
66 "software-vendors",
67 HttpMethod.GET,
68 url,
69 credentials.toAuthentication(),
70 null,
71 null,
72 EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
73 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
74 transport);
75
76 return (List<SoftwareVendorInfo>) SoftwareVendorInfo.fromJsonArrayToSoftwareVendorInfoes(response.getContent());
77 }
78 }