Package fr.sandro642.github.api
Class ApiFactory
java.lang.Object
fr.sandro642.github.api.ApiFactory
- Direct Known Subclasses:
ApiClient
ApiFactory is a class that provides methods to parse raw JSON data and retrieve specific data from it.
It uses Jackson's ObjectMapper to convert JSON strings into Java objects.
This class is designed to handle API responses and allows for easy access to the parsed data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondisplay()Method to display the raw data stored in the ApiFactory.<O> ObjectgetData(O type) Method to retrieve data from the rawData map based on the provided type.Method to retrieve the rawData map containing the parsed JSON data.<O,K> Object getSpecData(O type, K value) Method to retrieve nested data from the rawData map based on the provided type and value.intMethod to retrieve the HTTP status code of the API response.protected voidparseFromRawJson(String rawJson) Default constructor for ApiFactory.protected voidsetStatusCode(int statusCode) Method to retrieve the statusCode from response.
-
Constructor Details
-
ApiFactory
public ApiFactory()
-
-
Method Details
-
parseFromRawJson
Default constructor for ApiFactory. Initializes the rawData and rawJson fields to null. -
setStatusCode
protected void setStatusCode(int statusCode) Method to retrieve the statusCode from response. -
getRawData
Method to retrieve the rawData map containing the parsed JSON data.- Returns:
- The rawData map containing the parsed JSON data.
-
getData
Method to retrieve data from the rawData map based on the provided type. The type is converted to lowercase to ensure case-insensitive matching.- Parameters:
type- The type of data to retrieve, which is expected to be a string representation of the key.- Returns:
- The data associated with the specified type, or null if not found.
-
getSpecData
Method to retrieve nested data from the rawData map based on the provided type and value. The type and value are converted to lowercase to ensure case-insensitive matching.- Parameters:
type- The type of data to retrieve, which is expected to be a string representation of the key.value- The specific value within the nested map to retrieve.- Returns:
- The nested data associated with the specified type and value, or null if not found.
-
getStatusCode
public int getStatusCode()Method to retrieve the HTTP status code of the API response.- Returns:
- The HTTP status code of the API response.
-
display
Method to display the raw data stored in the ApiFactory. This method returns the rawData map, which contains the parsed JSON data.- Returns:
- The rawData map containing the parsed JSON data, or null if rawData is not initialized.
-