Class Client
java.lang.Object
page.codeberg.friedolyn.configuration.client.Client
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The kind of client to use for the HTTP requests. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull Boolean
The Do Not Track header indicates whether the user would prefer privacy rather than personalised content.private @NonNull Boolean
The Global Privacy Control header indicates whether the user consents to a website or service selling or sharing their personal information with third parties.private @NonNull Client.ClientKind
The kind of client to use for the HTTP requests.private @NonNull String
The user agent to use for the HTTP client. -
Constructor Summary
ConstructorsModifierConstructorDescriptionClient()
Creates a new client with the given user agent by callingsetUserAgent(String)
.private
Client
(String userAgent, Boolean doNotTrack, Boolean globalPrivacyControl, String preferredClientKind) Creates a new client with the given user agent, Do Not Track and Global Privacy Control settings.Client
(UserAgentManager.Client client, UserAgentManager.Platform platform) Creates a new client with the given user agent. -
Method Summary
Modifier and TypeMethodDescription@NonNull Client
copy()
boolean
Checks whether the fields of this client are equal to the fields of another client.boolean
Checks whether the fields of this client are equal to the default values, i.e.void
setDoNotTrack
(Boolean doNotTrack) Updates thedoNotTrack
field.void
setGlobalPrivacyControl
(Boolean globalPrivacyControl) Updates theglobalPrivacyControl
field.private void
setNullableUserAgent
(String userAgent) Deprecated.Only to be used by Jackson for deserialisation.private void
setPreferredClientKind
(String preferredClientKind) Deprecated.Only to be used by Jackson for deserialisation.void
setPreferredClientKind
(Client.ClientKind preferredClientKind) Updates thepreferredClientKind
field.void
setUserAgent
(@NonNull String userAgent) Updates theuserAgent
field with the given one.void
setUserAgent
(UserAgentManager.Client client, UserAgentManager.Platform platform) Updates theuserAgent
field with the given parameters.@NonNull String
toString()
-
Field Details
-
preferredClientKind
The kind of client to use for the HTTP requests. Defaults toClient.ClientKind.HTTP_CLIENT
. -
userAgent
The user agent to use for the HTTP client. Defaults toFRIEDOLYN
without a platform specified
. -
doNotTrack
The Do Not Track header indicates whether the user would prefer privacy rather than personalised content. -
globalPrivacyControl
The Global Privacy Control header indicates whether the user consents to a website or service selling or sharing their personal information with third parties.
-
-
Constructor Details
-
Client
public Client()- Implementation Note:
- For some reason, when using
NoArgsConstructor
,Builder
complains that it needs "a proper constructor", so we need to define a no-argument constructor ourselves.
-
Client
Creates a new client with the given user agent.- Parameters:
client
- The name of the client that the user agent should indicate.platform
- The operating system or device that the user agent should indicate.
-
Client
Creates a new client with the given user agent by callingsetUserAgent(String)
.- Parameters:
userAgent
- Same as insetUserAgent(String)
.
-
Client
private Client(String userAgent, Boolean doNotTrack, Boolean globalPrivacyControl, String preferredClientKind) throws IllegalArgumentException Creates a new client with the given user agent, Do Not Track and Global Privacy Control settings.- Parameters:
userAgent
- The user agent to use for the HTTP client. Will be stored inuserAgent
.doNotTrack
-true
means that the user prefers privacy rather than personalised content.false
means the opposite. Will be stored indoNotTrack
.globalPrivacyControl
-true
means that the user consents to a website or service selling or sharing their personal information with third parties.false
means the opposite. Will be stored inglobalPrivacyControl
.preferredClientKind
- The kind of client to use for the HTTP requests. Will be stored inpreferredClientKind
.- Throws:
IllegalArgumentException
- If the user agent is blank.- Implementation Note:
- This constructor must NOT be replaced by
Lombok
's@AllArgsConstructor
annotation, because then the default values would be ignored, i.e. if optional fields were missing, they would be set tonull
instead of the default values.
-
-
Method Details
-
setUserAgent
public void setUserAgent(@NonNull UserAgentManager.Client client, @NonNull UserAgentManager.Platform platform) Updates theuserAgent
field with the given parameters.- Parameters:
client
- The name of the client that the user agent should indicate.platform
- The operating system or device that the user agent should indicate.- Throws:
IllegalStateException
- If the client was not found in the user-agent collection.IllegalArgumentException
- If the client is not available on the platform specified.- See Also:
-
setUserAgent
Updates theuserAgent
field with the given one.- Parameters:
userAgent
- The user agent to use for the HTTP client; will be stored inuserAgent
. If it contains a dot, the method will try to cast the substring before the dot to aClient
and the substring after the dot to aPlatform
. If there is no dot or if the cast fails, the given user agent will be used verbatim (as is).- Throws:
IllegalArgumentException
- If the user agent is blank.- See Also:
-
setNullableUserAgent
@Deprecated private void setNullableUserAgent(@Nullable String userAgent) throws IllegalArgumentException Deprecated.Only to be used by Jackson for deserialisation. UsesetUserAgent(String)
instead.- Parameters:
userAgent
- The user agent to use for the HTTP client; will be stored inuserAgent
.- Throws:
IllegalArgumentException
- SeesetUserAgent(String)
.
-
setDoNotTrack
Updates thedoNotTrack
field.- Parameters:
doNotTrack
-true
means that the user prefers privacy rather than personalized content.false
means the opposite. If it is null, the field will not be updated.
-
setGlobalPrivacyControl
Updates theglobalPrivacyControl
field.- Parameters:
globalPrivacyControl
-true
means that the user consents to a website or service selling or sharing their personal information with third parties.false
means the opposite. If it is null, the field will not be updated.
-
setPreferredClientKind
Updates thepreferredClientKind
field.- Parameters:
preferredClientKind
- The kind of client to use for the HTTP requests. If it is null, the field will not be updated.
-
setPreferredClientKind
Deprecated.Only to be used by Jackson for deserialisation. UsesetPreferredClientKind(ClientKind)
instead. Updates thepreferredClientKind
field.- Parameters:
preferredClientKind
- The kind of client to use for the HTTP requests. If it is null or does not match any member of theClient.ClientKind
enum, the field will not be updated.
-
copy
-
toString
-
equals
-
equalsDefault
public boolean equalsDefault()Checks whether the fields of this client are equal to the default values, i.e. whether this client resembles a newly created one.- Returns:
true
if the fields are equal to the default values,false
otherwise.
-