Skip to content

Commit a88dd44

Browse files
committed
added JavaDoc
1 parent b7ff409 commit a88dd44

File tree

5 files changed

+491
-34
lines changed

5 files changed

+491
-34
lines changed

src/com/brein/api/BreinBase.java

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public abstract class BreinBase<T extends BreinBase> implements ISecretStrategy
2121
public final static String SIGNATURE_TYPE_FIELD = "signatureType";
2222

2323
/**
24-
* Builder for json creation
24+
* Builder for JSON creation
2525
*/
2626
public static final Gson GSON = new GsonBuilder()
27-
.setPrettyPrinting()
2827
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
2928
.create();
3029

@@ -52,19 +51,20 @@ public void set(final BreinBase base, final Object value) {
5251
}
5352

5453
/**
55-
* contains the User that will be used for the request
54+
* Contains user information for the request
5655
*/
5756
private BreinUser user;
5857

5958
/**
60-
* contains a map for the base section
59+
* The base data for the request
6160
*/
6261
private Map<String, Object> baseMap;
6362

6463
/**
65-
* retrieves the breinuser
64+
* Retrieves the current {@code BreinUser} for the request. This method never returns {@code null}, instead it
65+
* creates an empty {@code BreinUser} instance if none is available so far.
6666
*
67-
* @return breinuser
67+
* @return the current {@code BreinUser} for the request
6868
*/
6969
public BreinUser getUser() {
7070
if (this.user == null) {
@@ -75,40 +75,85 @@ public BreinUser getUser() {
7575
}
7676

7777
/**
78-
* sets the brein user
78+
* Sets the {@code BreinUser} instance for the request. It is recommended to get the user (using {@code getUser()})
79+
* and manipulate the retrieved instance directly or to use the {@code setUser(key, value)} method to set user
80+
* specific data.
7981
*
80-
* @param user user data
82+
* @param user the {@code BreinUser} to set
8183
*
82-
* @return self
84+
* @return {@code this}
85+
*
86+
* @see BreinUser
8387
*/
8488
public T setUser(final BreinUser user) {
8589
this.user = user;
8690
return getThis();
8791
}
8892

93+
/**
94+
* Sets a specific data point for the user data of the request, i.e.:
95+
* <p>
96+
* <pre>
97+
* {
98+
* user: {
99+
* 'key': 'value'
100+
* }
101+
* }
102+
* </pre>
103+
* <p>
104+
* Typically, that would be, e.g., {@code email},
105+
* {@code sessionId}, and/or {@code userId}
106+
*
107+
* @param key the value to be set (e.g., {@code "email"} or {@code "sessionId"})
108+
* @param value the value to be set for the specified key
109+
*
110+
* @return {@code this}
111+
*/
89112
public T setUser(final String key, final Object value) {
90113
this.getUser().set(key, value);
91114
return getThis();
92115
}
93116

117+
/**
118+
* Sets a specific data point for the additional part of the request, i.e.:
119+
* <p>
120+
* <pre>
121+
* {
122+
* user: {
123+
* additional: {
124+
* 'key': 'value'
125+
* }
126+
* }
127+
* }
128+
* </pre>
129+
*
130+
* @param key the value to be set (e.g., {@code "localDateTime"}, {@code "userAgent"}, {@code "referrer"} or
131+
* {@code "timezone"})
132+
* @param value the value to be set for the specified key
133+
*
134+
* @return {@code this}
135+
*/
94136
public T setAdditional(final String key, final Object value) {
95137
this.getUser().setAdditional(key, value);
96138
return getThis();
97139
}
98140

99141
/**
100-
* retrieves the endpoint. this depends of the kind of BreinBase type.
142+
* Gets the endpoint to be used to send the request to
101143
*
102144
* @param config the current configuration
103145
*
104-
* @return endpoint
146+
* @return the endpoint to be used to send the request to
147+
*
148+
* @see BreinConfig
105149
*/
106150
public abstract String getEndPoint(final BreinConfig config);
107151

108152
/**
109-
* retrieves the timestamp
153+
* Retrieves the currently set {@code unixTimestamp}. If now should be used as timestamp, the method returns {@code
154+
* -1L}.
110155
*
111-
* @return value from 1.1.1970
156+
* @return unix timestamp
112157
*/
113158
public long getUnixTimestamp() {
114159
final Object unixTimestamp = getBaseField(BaseField.UNIX_TIMESTAMP);
@@ -120,40 +165,31 @@ public long getUnixTimestamp() {
120165
}
121166

122167
/**
123-
* sets the timestamp
168+
* Sets the timestamp.
124169
*
125-
* @param unixTimestamp value from 1.1.1970
170+
* @param unixTimestamp unix timestamp to be used
126171
*
127-
* @return self
172+
* @return {@code this}
128173
*/
129174
public T setUnixTimestamp(final long unixTimestamp) {
130175
BaseField.UNIX_TIMESTAMP.set(this, unixTimestamp);
131176
return getThis();
132177
}
133178

134-
/**
135-
* gets the ipAddress
136-
*
137-
* @return content of ipAddress
138-
*/
139-
public String getIpAddress() {
140-
return getBaseField(BaseField.IP_ADDRESS);
141-
}
142-
143179
/**
144180
* sets the ipaddress
145181
*
146182
* @param ipAddress contains the ipAddress
147183
*
148-
* @return object itself
184+
* @return {@code this}
149185
*/
150186
public T setClientIpAddress(final String ipAddress) {
151187
BaseField.IP_ADDRESS.set(this, ipAddress);
152188
return getThis();
153189
}
154190

155191
/**
156-
* return the GSON builder instance
192+
* Gets the GSON builder instance used to build the requests body
157193
*
158194
* @return GSON instance
159195
*/
@@ -162,9 +198,15 @@ public Gson getGson() {
162198
}
163199

164200
/**
165-
* Sets a value
201+
* Sets a base value. The method cannot be used to set the user base-value, instead setUser has to be used.
202+
* <p>
203+
* <pre>
204+
* {
205+
* 'key': 'value'
206+
* }
207+
* </pre>
166208
*
167-
* @return self
209+
* @return {@code this}
168210
*/
169211
public T set(final String key, final Object value) {
170212
if (BreinUser.USER_FIELD.equalsIgnoreCase(key)) {
@@ -179,13 +221,20 @@ public T set(final String key, final Object value) {
179221
}
180222

181223
/**
182-
* prepares the request for the base section with standard fields
183-
* plus possible fields if configured
224+
* This method adds the request specific information to the {@code requestData}. It is called by {@link
225+
* #prepareRequestData(BreinConfig)} after the request data of the base information is added.
184226
*
185-
* @param requestData contains the created json structure
227+
* @param requestData the request data to be sent to the endpoint
186228
*/
187229
public abstract void prepareRequestData(final BreinConfig config, final Map<String, Object> requestData);
188230

231+
/**
232+
* Method to generate the body part of the request.
233+
*
234+
* @param config the configuration used to create the request body
235+
*
236+
* @return the created request body (JSON)
237+
*/
189238
public String prepareRequestData(final BreinConfig config) {
190239
final Map<String, Object> requestData = new HashMap<>();
191240

0 commit comments

Comments
 (0)