Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing javadoc documentation for GlobalRequestAttributes class #91

Merged
merged 3 commits into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/rocks/bastion/Bastion.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ public static Configuration loadConfiguration(String resourceLocation) {
* <p>
* Starts building or modifying the configuration of the {@link GlobalRequestAttributes} for Bastion.
* </p>
* <p>
* Global attributes could be used in cases where multiple subsequent requests require the same attributes, such as
* authentication headers or route parameters. Once {@link GlobalRequestAttributes} are set, they are applied to
* every single subsequent Bastion API call. The global attributes can be reset to their default values if needed
* using {@link GlobalRequestAttributes#clear()}.
* </p>
*
* @return The configured global request attributes.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package rocks.bastion.core.configuration;

import java.util.ArrayList;
import java.util.Collection;

import rocks.bastion.core.ApiHeader;
import rocks.bastion.core.ApiQueryParam;
import rocks.bastion.core.HttpRequest;
import rocks.bastion.core.RouteParam;

import java.util.ArrayList;
import java.util.Collection;

import static java.util.Objects.requireNonNull;

/**
Expand All @@ -33,90 +34,172 @@ public void clear() {
globalRequestTimeout = 0;
}

/**
* Returns the configured global headers. The default value for this configuration is an empty list.
*
* @see HttpRequest#headers()
*/
public Collection<ApiHeader> getGlobalHeaders() {
return globalHeaders;
}

/**
* Sets the request headers for all Bastion requests. The supplied collection will replace any previously
* configured global headers.
*
* @see HttpRequest#headers()
*/
public GlobalRequestAttributes setGlobalHeaders(Collection<ApiHeader> globalHeaders) {
requireNonNull(globalHeaders, "globalHeaders should not be null.");
this.globalHeaders = globalHeaders;
return this;
}

/**
* Returns the configured global query parameters. The default value for this configuration is an empty list.
*
* @see HttpRequest#queryParams()
*/
public Collection<ApiQueryParam> getGlobalQueryParams() {
return globalQueryParams;
}

/**
* Sets the request query parameters for all Bastion requests. The supplied collection will replace any previously
* configured global query parameters.
*
* @see HttpRequest#queryParams()
*/
public GlobalRequestAttributes setGlobalQueryParams(Collection<ApiQueryParam> globalQueryParams) {
requireNonNull(globalQueryParams, "globalQueryParams should not be null.");
this.globalQueryParams = globalQueryParams;
return this;
}

/**
* Returns the configured global route parameters. The default value for this configuration is an empty list.
*
* @see HttpRequest#routeParams()
*/
public Collection<RouteParam> getGlobalRouteParams() {
return globalRouteParams;
}

/**
* Sets the request route parameters for all Bastion requests. The supplied collection will replace any previously
* configured global route parameters.
*
* @see HttpRequest#routeParams()
*/
public GlobalRequestAttributes setGlobalRouteParams(Collection<RouteParam> globalRouteParams) {
requireNonNull(globalRouteParams, "globalRouteParams should not be null.");
this.globalRouteParams = globalRouteParams;
return this;
}

/**
* Returns the configured global timeout. The default value for this is 0, indicating no timeout.
*
* @see HttpRequest#timeout()
*/
public long getGlobalRequestTimeout() {
return globalRequestTimeout;
}

/**
* Sets the timeout (in milliseconds) for all Bastion requests. A value of 0 indicates no timeout.
*
* @see HttpRequest#timeout()
*/
public GlobalRequestAttributes setGlobalRequestTimeout(long globalRequestTimeout) {
requireNonNull(globalRequestTimeout, "globalRequestTimeout should not be null.");
if (globalRequestTimeout < 0) {
throw new IllegalArgumentException("globalRequestTimeout should be equal to or greater than 0, with 0 indicating no timeout.");
}
this.globalRequestTimeout = globalRequestTimeout;
return this;
}

/**
* Adds a header for all Bastion requests.
*
* @see HttpRequest#headers()
*/
public GlobalRequestAttributes addHeader(String name, String value) {
requireNonNull(name, "Header name should not be null.");
requireNonNull(value, "Header value should not be null.");
globalHeaders.add(new ApiHeader(name, value));
return this;

}

/**
* Removes the header from all Bastion requests if it was already present.
*
* @see HttpRequest#headers()
*/
public GlobalRequestAttributes removeHeader(String name, String value) {
requireNonNull(name, "Header name should not be null.");
requireNonNull(value, "Header value should not be null.");
globalHeaders.remove(new ApiHeader(name, value));
return this;
}

/**
* Adds a query parameter for all Bastion requests.
*
* @see HttpRequest#queryParams()
*/
public GlobalRequestAttributes addQueryParam(String name, String value) {
requireNonNull(name, "Query parameter name should not be null.");
requireNonNull(value, "Query parameter value should not be null.");
globalQueryParams.add(new ApiQueryParam(name, value));
return this;
}

/**
* Removes the query parameter from all Bastion requests if it was already present.
*
* @see HttpRequest#queryParams()
*/
public GlobalRequestAttributes removeQueryParam(String name, String value) {
requireNonNull(name, "Query parameter name should not be null.");
requireNonNull(value, "Query parameter value should not be null.");
globalQueryParams.remove(new ApiQueryParam(name, value));
return this;
}

/**
* Adds a route parameter for all Bastion requests.
*
* @see HttpRequest#routeParams() ()
*/
public GlobalRequestAttributes addRouteParam(String name, String value) {
requireNonNull(name, "Route parameter name should not be null.");
requireNonNull(value, "Route parameter value should not be null.");
globalRouteParams.add(new RouteParam(name, value));
return this;
}

/**
* Removes the route parameter from all Bastion requests if it was already present.
*
* @see HttpRequest#routeParams()
*/
public GlobalRequestAttributes removeRouteParam(String name, String value) {
requireNonNull(name, "Route parameter name should not be null.");
requireNonNull(value, "Route parameter value should not be null.");
globalRouteParams.remove(new RouteParam(name, value));
return this;
}

/**
* Sets the timeout (in milliseconds) for all Bastion requests. A value of 0 indicates no timeout.
*
* @see HttpRequest#timeout()
*/
public GlobalRequestAttributes timeout(long timeout) {
if (timeout < 0) {
throw new IllegalArgumentException("timeout should be equal to or greater than 0, with 0 indicating no timeout.");
}
globalRequestTimeout = timeout;
return this;
}
Expand Down