Class GravatarQrCodeRequest

java.lang.Object
com.github.natche.gravatarjavaclient.avatar.GravatarQrCodeRequest

public final class GravatarQrCodeRequest extends Object
A request for a user's profile QR code from Gravatar.
  • Method Details

    • fromEmail

      public static GravatarQrCodeRequest fromEmail(String email)
      Constructs and returns a new GravatarQrCodeRequest.
      Parameters:
      email - the email for this Gravatar QR code request
      Throws:
      NullPointerException - if the email is null
      IllegalArgumentException - if the email is empty or not a valid email address
    • fromHash

      public static GravatarQrCodeRequest fromHash(String hash)
      Constructs and returns a new GravatarQrCodeRequest.
      Parameters:
      hash - the hash for this Gravatar QR code request obtained by SHA256 hashing a valid email address
      Throws:
      NullPointerException - if the hash is null
      IllegalArgumentException - if the hash is empty
    • getHash

      public String getHash()
      Returns the hash for this request.
      Returns:
      the hash for this request
    • setSize

      @CanIgnoreReturnValue public GravatarQrCodeRequest setSize(int imageLength)
      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 range IMAGE_LENGTH_RANGE
    • getSize

      public int getSize()
      Returns the size of the image this request should return.
      Returns:
      the size of the image this request should return
    • setImageType

      @CanIgnoreReturnValue public GravatarQrCodeRequest setImageType(GravatarQrImageType type)
      Sets the image type this request will use. See GravatarQrImageType.
      Parameters:
      type - the image type
      Returns:
      this builder
      Throws:
      NullPointerException - if the provided type is null
    • getImageType

      public GravatarQrImageType getImageType()
      Returns the image type this request will use.
      Returns:
      the image type this request will use
    • setVersion

      @CanIgnoreReturnValue public GravatarQrCodeRequest setVersion(GravatarQrImageVersion version)
      Sets the QR code version this request will use.
      Parameters:
      version - the QR code version this request will use
      Returns:
      this builder
      Throws:
      NullPointerException - if the provided version is null
    • getVersion

      public GravatarQrImageVersion getVersion()
      Returns the QR code version this request will use.
      Returns:
      the QR code version this request will use
    • getRequestUrl

      public String getRequestUrl()
      Returns the URL for requesting the QR code based on the current state of this.
      Returns:
      the URL for requesting the QR code based on the current state of this
    • getBufferedImage

      public BufferedImage getBufferedImage()
      Reads and returns a BufferedImage using the URL constructed from the current state of this.
      Returns:
      a BufferedImage representing a QR code
      Throws:
      GravatarJavaClientException - if an exception occurs reading from the URL
    • saveTo

      @CanIgnoreReturnValue public boolean saveTo(File saveTo)
      Saves the QR code obtained from this to the provided file as a PNG. Note: the API returns a PNG which is why encoding options are not allowed by this method.
      Parameters:
      saveTo - the file to save the QR code to as a PNG
      Returns:
      whether the save operation was successful
      Throws:
      NullPointerException - if the provided file is null
      IllegalArgumentException - if the provided file references a directory or exists
    • hashCode

      public int hashCode()
      Returns a hashcode of this object.
      Overrides:
      hashCode in class Object
      Returns:
      a hashcode of this object
    • toString

      public String toString()
      Returns a string representation of this object.
      Overrides:
      toString in class Object
      Returns:
      a string representation 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