1 package com.srv4pos.server.api.posplus;
2
3 import com.srv4pos.server.api.infrastructure.HttpMethod;
4 import com.srv4pos.server.api.infrastructure.StringConnectionWriter;
5 import com.srv4pos.server.api.infrastructure.exceptions.enums.InconsistentDataErrorType;
6 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
7 import com.srv4pos.server.api.infrastructure.http.HttpHelper;
8 import com.srv4pos.server.api.infrastructure.http.Transport;
9
10 import java.net.URL;
11
12 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
13 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestVoid;
14 import static java.lang.String.format;
15
16
17
18
19
20 public class PosPlusService {
21 private URL url;
22 private Credentials credentials;
23 private Transport transport;
24
25
26
27
28
29
30
31
32 public PosPlusService(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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public KdReplyInfo kd(KdInfo kdInfo) {
84 return KdReplyInfo.fromJsonToKdReplyInfo(
85 requestString(
86 "pospluses/kd",
87 HttpMethod.POST,
88 url,
89 credentials.toAuthentication(),
90 null,
91 null,
92 new StringConnectionWriter(kdInfo.toJson()),
93 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
94 transport).getContent());
95 }
96
97
98
99
100
101
102
103
104
105
106 public KdReplyInfo kd(KdInfo kdInfo, String logId) {
107 return KdReplyInfo.fromJsonToKdReplyInfo(
108 requestString(
109 format("pospluses/kd?logId=%s", logId),
110 HttpMethod.POST,
111 url,
112 credentials.toAuthentication(),
113 null,
114 null,
115 new StringConnectionWriter(kdInfo.toJson()),
116 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
117 transport).getContent());
118 }
119
120
121
122
123
124
125 public void create(ControlUnitEndpointInfo controlUnitEndpointInfo) {
126 requestVoid("control-unit-endpoints",
127 HttpMethod.POST,
128 url,
129 credentials.toAuthentication(),
130 null,
131 null,
132 new StringConnectionWriter(controlUnitEndpointInfo.toJson()),
133 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
134 transport);
135 }
136 }