Class GravatarProfileRequest
java.lang.Object
com.github.natche.gravatarjavaclient.profile.GravatarProfileRequest
A class for requesting a Profile from the Gravatar Profile API.
Both authenticated and unauthenticated requests are supported by this API.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the provided object equals this.static GravatarProfileRequestConstructs a new GravatarProfileRequest from the provided email.static GravatarProfileRequestfromHashOrId(String hashOrId) Constructs a new GravatarProfileRequest from the provided hash or ID such as "nathanvcheshire".Returns the SHA256 hash or ID this request will use.Retrieves the profile using the provided email or hash from the Gravatar Profile API using HTTPS as the protocol.inthashCode()Returns a hashcode of this object.setTokenSupplier(GravatarProfileTokenProvider tokenSupplier) Sets the API token provider to use when requesting this profile from the Gravatar API.toString()Returns a string representation of this object.booleanwriteToFile(com.google.gson.Gson serializer, File file) Writes the profile object obtained from this request to the provided file using the provided GSON object as the serializer.booleanwriteToFile(File file) Writes the profile object obtained from this request to the provided file.
-
Method Details
-
fromHashOrId
Constructs a new GravatarProfileRequest from the provided hash or ID such as "nathanvcheshire".- Parameters:
hashOrId- the hash or ID- Returns:
- a new GravatarProfileRequest
- Throws:
NullPointerException- if the provided hash/ID is nullIllegalArgumentException- if the provided hash/ID is empty
-
fromEmail
Constructs a new GravatarProfileRequest from the provided email.- Parameters:
email- the email address- Returns:
- a new GravatarProfileRequest
- Throws:
NullPointerException- if the provided email is nullIllegalArgumentException- if the provided email is empty or not a valid email
-
setTokenSupplier
Sets the API token provider to use when requesting this profile from the Gravatar API. If not provided, only certain fields will be returned. A supplier is used instead of a String to allow for the avoidance of tokens appearing in String pool due to how strings work in the JVM.- Parameters:
tokenSupplier- a supplier for returning a token- Returns:
- this request builder
-
getHashOrId
Returns the SHA256 hash or ID this request will use.- Returns:
- the SHA256 hash or ID this request will use
-
getProfile
Retrieves the profile using the provided email or hash from the Gravatar Profile API using HTTPS as the protocol.- Returns:
- the GravatarProfile obtained from the API
- Throws:
GravatarJavaClientException- if an exception occurs when fetching the profile
-
writeToFile
Writes the profile object obtained from this request to the provided file.- Parameters:
file- the file to write the object to- Returns:
- whether the write operation was successful
- Throws:
NullPointerException- if the provided file is nullIllegalArgumentException- if the provided file is a directory
-
writeToFile
Writes the profile object obtained from this request to the provided file using the provided GSON object as the serializer. The provided file must have a valid name. SeeResourceReader.isValidFilename(String)for more details.- Parameters:
serializer- the GSON object to serialize the profilefile- the file to write the object to- Returns:
- whether the write operation was successful
- Throws:
NullPointerException- if the provided file or serializer is nullIllegalArgumentException- if the provided file is a directory, does not exist, or has an invalid name
-
hashCode
public int hashCode()Returns a hashcode of this object. -
equals
Returns whether the provided object equals this. -
toString
Returns a string representation of this object.
-