Class GravatarProfileRequest

java.lang.Object
com.github.natche.gravatarjavaclient.profile.GravatarProfileRequest

public final class GravatarProfileRequest extends Object
A class for requesting a Profile from the Gravatar Profile API. Both authenticated and unauthenticated requests are supported by this API.
  • Method Details

    • fromHashOrId

      public static GravatarProfileRequest fromHashOrId(String hashOrId)
      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 null
      IllegalArgumentException - if the provided hash/ID is empty
    • fromEmail

      public static GravatarProfileRequest fromEmail(String email)
      Constructs a new GravatarProfileRequest from the provided email.
      Parameters:
      email - the email address
      Returns:
      a new GravatarProfileRequest
      Throws:
      NullPointerException - if the provided email is null
      IllegalArgumentException - if the provided email is empty or not a valid email
    • setTokenSupplier

      public GravatarProfileRequest setTokenSupplier(GravatarProfileTokenProvider tokenSupplier)
      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

      public String getHashOrId()
      Returns the SHA256 hash or ID this request will use.
      Returns:
      the SHA256 hash or ID this request will use
    • getProfile

      public GravatarProfile 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

      @CanIgnoreReturnValue public boolean writeToFile(File file)
      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 null
      IllegalArgumentException - if the provided file is a directory
    • writeToFile

      @CanIgnoreReturnValue public boolean writeToFile(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. The provided file must have a valid name. See ResourceReader.isValidFilename(String) for more details.
      Parameters:
      serializer - the GSON object to serialize the profile
      file - the file to write the object to
      Returns:
      whether the write operation was successful
      Throws:
      NullPointerException - if the provided file or serializer is null
      IllegalArgumentException - 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.
      Overrides:
      hashCode in class Object
      Returns:
      a hashcode of this object
    • equals

      public boolean equals(Object o)
      Returns whether the provided object equals this.
      Overrides:
      equals in class Object
      Parameters:
      o - the other object
      Returns:
      whether the provided object equals this
    • toString

      public String toString()
      Returns a string representation of this object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object