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

    • from

      public static GravatarProfileRequest from(String id)
      Constructs a new GravatarProfileRequest from the provided ID.
      Parameters:
      id - the ID to use in the request
      Returns:
      a new GravatarProfileRequest
      Throws:
      NullPointerException - if the provided ID is null
      IllegalArgumentException - if the provided 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
    • setToken

      public GravatarProfileRequest setToken(String token)
      Sets the token this request will use when requesting information from the Gravatar API. When a valid token is provided, fields requiring authentication will be provided in the response.
      Parameters:
      token - the token
      Returns:
      this request
    • 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.
      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