addFile
last analyzed

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
1
package com.base.Http.Request;
2
3
import com.base.Auth.AccessToken;
4
5
import java.io.File;
6
import java.util.Map;
7
8
public class Request {
9
    /**
10
     * Request Method GET
11
     */
12
    public static final String METHOD_GET = "GET";
13
14
    /**
15
     * Request Method POST
16
     */
17
    public static final String METHOD_POST = "POST";
18
19
    /**
20
     * Request Method PUT
21
     */
22
    public static final String METHOD_PUT = "PUT";
23
24
    /**
25
     * Request Method PATCH
26
     */
27
    public static final String METHOD_PATCH = "PATCH";
28
29
    /**
30
     * Request Method DELETE
31
     */
32
    public static final String METHOD_DELETE = "DELETE";
33
34
    /**
35
     * Request endpoint
36
     */
37
    protected String endpoint;
38
39
    /**
40
     * Request url
41
     */
42
    protected String url;
43
44
    /**
45
     * Request method
46
     */
47
    protected String method;
48
49
    /**
50
     * Request headers
51
     */
52
    protected Map<String, String> headers;
53
54
    /**
55
     * Request parameters
56
     */
57
    protected Map<String, String> parameters;
58
59
    /**
60
     * Request body
61
     */
62
    protected RequestBody body;
63
64
    /**
65
     * Content type
66
     */
67
    protected String contentType = "application/json; charset=utf-8";
68
69
    /**
70
     * Files
71
     */
72
    protected Map<String, File> files;
73
74
    /**
75
     * Access Token
76
     */
77
    protected AccessToken accessToken;
78
79
    /**
80
     * Create new Request.
81
     *
82
     * @param endpoint
83
     * @param method
84
     */
85
    public Request(String endpoint, String method) {
86
        this.endpoint = endpoint;
87
        this.method = method;
88
    }
89
90
    /**
91
     * Get Request Endpoint.
92
     *
93
     * @return Request Endpoint.
94
     */
95
    public String getEndpoint() {
96
        return endpoint;
97
    }
98
99
    /**
100
     * Set Endpoint.
101
     *
102
     * @param endpoint
103
     * @return
104
     */
105
    public Request setEndpoint(String endpoint) {
106
        this.endpoint = endpoint;
107
        return this;
108
    }
109
110
    /**
111
     * Get Request Method.
112
     *
113
     * @return Request Method.
114
     */
115
    public String getMethod() {
116
        return method;
117
    }
118
119
    /**
120
     * Set Method.
121
     *
122
     * @param method
123
     * @return
124
     */
125
    public Request setMethod(String method) {
126
        this.method = method;
127
        return this;
128
    }
129
130
    /**
131
     * Get Request Headers.
132
     *
133
     * @return Request Headers.
134
     */
135
    public Map<String, String> getHeaders() {
136
        return headers;
137
    }
138
139
    /**
140
     * Set Headers.
141
     *
142
     * @param headers
143
     * @return
144
     */
145
    public Request setHeaders(Map<String, String> headers) {
146
        this.headers = headers;
147
        return this;
148
    }
149
150
    /**
151
     * Get Request Parameters.
152
     *
153
     * @return Request Parameters.
154
     */
155
    public Map<String, String> getParameters() {
156
        return parameters;
157
    }
158
159
    /**
160
     * Set Parameters.
161
     *
162
     * @param parameters
163
     * @return
164
     */
165
    public Request setParameters(Map<String, String> parameters) {
166
        this.parameters = parameters;
167
        return this;
168
    }
169
170
    /**
171
     * Get Request Body.
172
     *
173
     * @return Request Body.
174
     */
175
    public RequestBody getBody() {
176
        return body;
177
    }
178
179
    /**
180
     * Set Body.
181
     *
182
     * @param body
183
     * @return
184
     */
185
    public Request setBody(RequestBody body) {
186
        this.body = body;
187
        return this;
188
    }
189
190
    /**
191
     * Request Content Type
192
     *
193
     * @return Request Content Type
194
     */
195
    public String getContentType() {
196
        return contentType;
197
    }
198
199
    /**
200
     * @param contentType
201
     * @return
202
     */
203
    public Request setContentType(String contentType) {
204
        this.contentType = contentType;
205
        return this;
206
    }
207
208
    /**
209
     * Request Get Files
210
     *
211
     * @return Request Get Files
212
     */
213
    public Map<String, File> getFiles() {
214
        return files;
215
    }
216
217
    /**
218
     * Set Files of Request
219
     *
220
     * @param files
221
     * @return
222
     */
223
    public Request setFiles(Map<String, File> files) {
224
        this.files = files;
225
        return this;
226
    }
227
228
    /**
229
     * Add Files
230
     *
231
     * @param key  File Key
232
     * @param file File
233
     * @return
234
     */
235
    public Request addFile(String key, File file) {
236
        this.files.put(key, file);
237
        return this;
238
    }
239
240
    /**
241
     * Return true or false if Request has Files or Not.
242
     *
243
     * @return boolean
244
     */
245
    public boolean hasFiles() {
246
        return !this.files.isEmpty();
247
    }
248
249
    /**
250
     * Request URL
251
     *
252
     * @return Request URL
253
     */
254
    public String getUrl() {
255
        return url;
256
    }
257
258
    /**
259
     * Set Request URL
260
     *
261
     * @param url
262
     * @return
263
     */
264
    public Request setUrl(String url) {
265
        this.url = url;
266
        return this;
267
    }
268
269
    /**
270
     * Return Request AccessToken
271
     *
272
     * @return AccessToken
273
     */
274
    public AccessToken getAccessToken() {
275
        return accessToken;
276
    }
277
278
    /**
279
     * Request AccessToken
280
     *
281
     * @param accessToken
282
     * @return
283
     */
284
    public Request setAccessToken(AccessToken accessToken) {
285
        this.accessToken = accessToken;
286
        return this;
287
    }
288
}
289