Package com.moesif.api
Class APIHelper
java.lang.Object
com.moesif.api.APIHelper
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String, Object> parameters) Appends the given set of parameters to the given query stringstatic voidappendUrlWithTemplateParameters(StringBuilder queryBuilder, Map<String, Object> parameters) Replaces template parameters in the given urlstatic StringcleanUrl(StringBuilder url) Validates and processes the given Urlstatic StringdateToString(Date date) Convert a date to an ISO8601 formatted stringstatic LinkedHashMap<String,Object> deserialize(String json) JSON Deserialization of the given json string.static <T> Tdeserialize(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) JSON Deserialization of the given json string.static <T> Tdeserialize(String json, Class<T> typeReference) JSON Deserialization of the given json string.static ExecutorServiceSingleton access to the threadpool schedulerstatic StringGet the current version of the moesifapi-java artifactstatic booleanValidates if the string is null, empty or whitespacestatic DateParse a date from its string representationstatic voidpopulate(String json, APIException obj) Populates an object of an APIException subclass with the required properties.prepareFormFields(Object value) Prepares Array style form fields from a given array of valuesstatic voidremoveNullValues(Map<String, ?> map) Removes null values from the given mapstatic voidreplaceAll(StringBuilder stringBuilder, String toReplace, String replaceWith) Replaces all occurrences of the given string in the string builderstatic StringJSON Serialization of a given object.static voidshutdown()Shutdown all the threads
-
Field Details
-
mapper
public static com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Constructor Details
-
APIHelper
public APIHelper()
-
-
Method Details
-
getScheduler
Singleton access to the threadpool scheduler- Returns:
- ExecutorService instance
-
shutdown
public static void shutdown()Shutdown all the threads -
parseDate
Parse a date from its string representation- Parameters:
date- ISO8601 encodede date string- Returns:
- Parsed Date object
- Throws:
ParseException
-
dateToString
Convert a date to an ISO8601 formatted string- Parameters:
date- Date object to format- Returns:
- ISO8601 formatted date string
-
serialize
public static String serialize(Object obj) throws com.fasterxml.jackson.core.JsonProcessingException JSON Serialization of a given object.- Parameters:
obj- The object to serialize into JSON- Returns:
- The serialized Json string representation of the given object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if error serializing JSON obj
-
deserialize
public static <T> T deserialize(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) throws IOException JSON Deserialization of the given json string.- Type Parameters:
T- The type of the object to deserialize into- Parameters:
json- The json string to deserializetypeReference- The TypeReference of the object to deserialize into- Returns:
- The deserialized object
- Throws:
IOException- if error deserializing
-
deserialize
JSON Deserialization of the given json string.- Type Parameters:
T- The type of the object to deserialize into- Parameters:
json- The json string to deserializetypeReference- The Class of the object to deserialize into- Returns:
- The deserialized object
- Throws:
IOException- if error deserializing
-
populate
Populates an object of an APIException subclass with the required properties.- Parameters:
json- The json string to deserializeobj- The object to populate- Throws:
IOException- if error deserializing
-
deserialize
JSON Deserialization of the given json string.- Parameters:
json- The json string to deserialize- Returns:
- The deserialized json as a Map
- Throws:
IOException- if error deserializing
-
appendUrlWithTemplateParameters
public static void appendUrlWithTemplateParameters(StringBuilder queryBuilder, Map<String, Object> parameters) Replaces template parameters in the given url- Parameters:
queryBuilder- The query string builder to replace the template parametersparameters- The parameters to replace in the url
-
appendUrlWithQueryParameters
public static void appendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String, Object> parameters) Appends the given set of parameters to the given query string- Parameters:
queryBuilder- The query url string to append the parametersparameters- The parameters to append
-
isNullOrWhiteSpace
Validates if the string is null, empty or whitespace- Parameters:
s- The string to validate- Returns:
- The result of validation
-
replaceAll
Replaces all occurrences of the given string in the string builder- Parameters:
stringBuilder- The string builder to update with replaced stringstoReplace- The string to replace in the string builderreplaceWith- The string to replace with
-
removeNullValues
Removes null values from the given map- Parameters:
map- the input map
-
cleanUrl
Validates and processes the given Url- Parameters:
url- The given Url to process- Returns:
- Pre-process Url as string
-
prepareFormFields
Prepares Array style form fields from a given array of values- Parameters:
value- Value for the form fields- Returns:
- Dictionary of form fields created from array elements
-
getVersion
Get the current version of the moesifapi-java artifact- Returns:
- Version string
-