-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3c38962
commit 6c92f5f
Showing
5 changed files
with
112 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/me/legrange/haveibeenpwned/HaveIBeenPwndBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package me.legrange.haveibeenpwned; | ||
|
||
/** A builder pattern to setup the HaveIBeenPwndApi the way you want. | ||
* | ||
* @author GideonLeGrange | ||
*/ | ||
public final class HaveIBeenPwndBuilder { | ||
|
||
private static final String HIBP_REST_URL = "https://haveibeenpwned.com/api/v2/"; | ||
private static final String PPW_REST_URL = "https://api.pwnedpasswords.com/"; | ||
private static final String DEFAULT_USER_AGENT = "HaveIBeenPwndJava-v1"; | ||
|
||
private boolean addPadding = false; | ||
private String haveIbeenPwndUrl = HIBP_REST_URL; | ||
private String pwndPasswordsUrl = PPW_REST_URL; | ||
private String userAgent = DEFAULT_USER_AGENT; | ||
|
||
/** Create a new builder. | ||
* | ||
* @return The builder | ||
*/ | ||
public static HaveIBeenPwndBuilder create() { | ||
return new HaveIBeenPwndBuilder(); | ||
} | ||
|
||
/** Change the URL for the HaveIBeenPwnd breach service. | ||
* | ||
* @param url The URL to use | ||
* @return The builder | ||
*/ | ||
public HaveIBeenPwndBuilder withHaveIBeenPwndUrl(String url) { | ||
this.haveIbeenPwndUrl = url; | ||
return this; | ||
} | ||
|
||
/** Change the URL for the HaveIBeenPwnd password service. | ||
* | ||
* @param url The URL to use | ||
* @return The builder | ||
*/ | ||
public HaveIBeenPwndBuilder withPwndPasswordsUrl(String url) { | ||
this.pwndPasswordsUrl = url; | ||
return this; | ||
} | ||
|
||
/** Change the User-Agent to send with an HTTP request from the default | ||
* | ||
* @param userAgent The URL to use | ||
* @return The builder | ||
*/ | ||
public HaveIBeenPwndBuilder withUserAgent(String userAgent) { | ||
this.userAgent = userAgent; | ||
return this; | ||
} | ||
|
||
/** Set if padding on pwnd password calls is enabled. | ||
* | ||
* @param addPadding Is padding is required? | ||
* @return The builder | ||
*/ | ||
public HaveIBeenPwndBuilder addPadding(boolean addPadding) { | ||
this.addPadding = addPadding; | ||
return this; | ||
} | ||
|
||
/** Build the API | ||
* | ||
* @return The API | ||
*/ | ||
public HaveIBeenPwndApi build() { | ||
return new HaveIBeenPwndApi(haveIbeenPwndUrl, pwndPasswordsUrl, addPadding, userAgent); | ||
} | ||
|
||
private HaveIBeenPwndBuilder() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters