Class GravatarAvatarRequest
java.lang.Object
com.github.natche.gravatarjavaclient.avatar.GravatarAvatarRequest
A class for building a Gravatar Avatar request, requesting the resource, and saving
the resource to a
File or a BufferedImage.
See Avatar image request API Documentation.-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the provided object is equal to this.static GravatarAvatarRequestConstructs and returns a new GravatarAvatarRequest.static GravatarAvatarRequestConstructs and returns a new GravatarAvatarRequest.Reads and returns aBufferedImageusing the URL constructed from the current state of this.Returns the default image type this request will use.Returns the default image URL.getHash()Returns the hash for this request.Reads and returns anImageIconusing the URL constructed from the current state of this.Returns the protocol this request will use.Returns the rating this request will use.Returns the URL for requesting the Avatar based on the current state of this.Returns whether this request should append the jpg suffix to the hash.intgetSize()Returns the length of the image this request should return.Returns whether this request will use full URL parameters.inthashCode()Returns a hashcode for this object.booleanSaves an image obtained from the URL constructed from this to the provided file as a jpg.booleanSaves an image obtained from the URL constructed from this to the provided file as a png.booleanSaves an image obtained from the URL constructed from this to the provided file.setDefaultImageType(GravatarDefaultImageType imageType) Sets the default image type this request will use.setDefaultImageUrl(String defaultImageUrl) Sets the default image URL.setForceDefaultImage(GravatarForceDefaultImage forceDefaultImage) Sets whether this request should force the default image.setProtocol(GravatarProtocol protocol) Sets the protocol this request will use.setRating(GravatarRating rating) Sets the rating this request will use.setShouldAppendJpgSuffix(GravatarUseJpgSuffix useJpgSuffix) Returns whether this request should append the jpg suffix to the hash.setSize(int imageLength) Sets the length of the image this request should return.setUseFullUrlParameters(GravatarUseFullUrlParameters useFullUrlParameters) Sets whether this request should use full URL parameters.Returns whether this request should force the default image.toString()Returns a string representation of this.
-
Method Details
-
fromEmail
Constructs and returns a new GravatarAvatarRequest.- Parameters:
email- the email for this Gravatar Avatar request- Throws:
NullPointerException- if the email is nullIllegalArgumentException- if the email is empty or not a valid email address
-
fromHash
Constructs and returns a new GravatarAvatarRequest.- Parameters:
hash- the hash for this Gravatar Avatar request- Throws:
NullPointerException- if the hash is nullIllegalArgumentException- if the hash is empty
-
getHash
Returns the hash for this request.- Returns:
- the hash for this request
-
setDefaultImageUrl
Sets the default image URL. Note,defaultImageTypeis set tonullif this method is invoked.Conditions which must be met for the Gravatar API endpoint to return a default image:
- The image must be publicly available (e.g. cannot be on an intranet, on a local development machine, behind HTTP Auth or some other firewall etc). Default images are passed through a security scan to avoid malicious content.
- The image must be accessible via HTTP or HTTPS on the standard ports, 80 and 443, respectively.
- The image must have a recognizable image extension (jpg, jpeg, gif, png, heic)
- The image must not include a query string (if it does, it will be ignored)
- Parameters:
defaultImageUrl- the default image URL- Returns:
- this builder
- Throws:
NullPointerException- if the provided image URL is nullIllegalArgumentException- if the provided image URL is empty or invalid
-
getDefaultImageUrl
Returns the default image URL.- Returns:
- the default image URL
-
setUseFullUrlParameters
@CanIgnoreReturnValue public GravatarAvatarRequest setUseFullUrlParameters(GravatarUseFullUrlParameters useFullUrlParameters) Sets whether this request should use full URL parameters.- Parameters:
useFullUrlParameters- whether this request should use full URL parameters- Returns:
- this builder
- Throws:
NullPointerException- if the provided value is null
-
getUseFullUrlParameters
Returns whether this request will use full URL parameters.- Returns:
- whether this request will use full URL parameters
-
setProtocol
Sets the protocol this request will use.- Parameters:
protocol- the protocol- Returns:
- this builder
- Throws:
NullPointerException- if the provided protocol is null
-
getProtocol
Returns the protocol this request will use.- Returns:
- the protocol this request will use
-
setDefaultImageType
@CanIgnoreReturnValue public GravatarAvatarRequest setDefaultImageType(GravatarDefaultImageType imageType) Sets the default image type this request will use. NotedefaultImageUrlis set to null if this method is invoked.- Parameters:
imageType- the default image type this request will use- Returns:
- this builder
- Throws:
NullPointerException- if the provided image type is null
-
getDefaultImageType
Returns the default image type this request will use.- Returns:
- the default image type this request will use
-
setForceDefaultImage
@CanIgnoreReturnValue public GravatarAvatarRequest setForceDefaultImage(GravatarForceDefaultImage forceDefaultImage) Sets whether this request should force the default image.- Parameters:
forceDefaultImage- whether this request should force the default image- Returns:
- this builder
- Throws:
NullPointerException- if the provided value is null
-
shouldForceDefaultImage
Returns whether this request should force the default image.- Returns:
- whether this request should force the default image
-
setRating
Sets the rating this request will use.- Parameters:
rating- the rating this request will use- Returns:
- this builder
- Throws:
NullPointerException- if the provided rating is null
-
getRating
Returns the rating this request will use.- Returns:
- the rating this request will use
-
setShouldAppendJpgSuffix
@CanIgnoreReturnValue public GravatarAvatarRequest setShouldAppendJpgSuffix(GravatarUseJpgSuffix useJpgSuffix) Returns whether this request should append the jpg suffix to the hash.- Parameters:
useJpgSuffix- whether this request should append the jpg suffix to the hash- Returns:
- this builder
- Throws:
NullPointerException- if the provided value is null
-
getShouldAppendJpgSuffix
Returns whether this request should append the jpg suffix to the hash.- Returns:
- whether this request should append the jpg suffix to the hash
-
setSize
Sets the length of the image this request should return.- Parameters:
imageLength- the length of the image this request should return- Returns:
- this builder
- Throws:
IllegalArgumentException- if the provided image length is not in the rangeIMAGE_SIZE_RANGE
-
getSize
public int getSize()Returns the length of the image this request should return.- Returns:
- the length of the image this request should return
-
getRequestUrl
Returns the URL for requesting the Avatar based on the current state of this.- Returns:
- the URL for requesting the Avatar based on the current state of this
-
getBufferedImage
Reads and returns aBufferedImageusing the URL constructed from the current state of this.- Returns:
- a
BufferedImagerepresenting an Avatar - Throws:
GravatarJavaClientException- if an exception occurs reading from the URL
-
getImageIcon
Reads and returns anImageIconusing the URL constructed from the current state of this.- Returns:
- an
ImageIconrepresenting an Avatar - Throws:
GravatarJavaClientException- if an exception occurs reading from the URL
-
saveAsPng
Saves an image obtained from the URL constructed from this to the provided file as a png.- Parameters:
saveTo- the file to save the image to- Returns:
- whether the save operation was successful
- Throws:
NullPointerException- if the provided file is nullIllegalArgumentException- if the provided file is a directory
-
saveAsJpg
Saves an image obtained from the URL constructed from this to the provided file as a jpg.- Parameters:
saveTo- the file to save the image to- Returns:
- whether the save operation was successful
- Throws:
NullPointerException- if the provided file is nullIllegalArgumentException- if the provided file is a directory
-
saveTo
Saves an image obtained from the URL constructed from this to the provided file. Note, while the file could be named "Image.png", if "jpg" is provided as the format, the image will be a jpg yet named "Image.png".- Parameters:
saveTo- the file to save the image toformat- the format to use; seeImageIO.getWriterFormatNames()- Returns:
- whether the save operation was successful
- Throws:
NullPointerException- if any parameter is nullIllegalArgumentException- if the provided format is empty or the provided file is a directory
-
toString
Returns a string representation of this. -
hashCode
public int hashCode()Returns a hashcode for this object. -
equals
Returns whether the provided object is equal to this.
-