Class URLEndpoint
- java.lang.Object
-
- com.github.dannil.scbjavaclient.communication.URLEndpoint
-
public class URLEndpoint extends Object
Class which encapsulates the API URL, and enables relevant operations on this URL.
- Since:
- 1.2.0
-
-
Constructor Summary
Constructors Constructor Description URLEndpoint(String url)
Overloaded constructor.URLEndpoint(URL url)
Overloaded constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description URLEndpoint
append(String str)
Appends the given string to the URL.boolean
equals(Object obj)
String
getLanguage()
Returns the language portion of this URL.static URLEndpoint
getRootUrl()
Returns the root URL for the API.static URLEndpoint
getRootUrl(Locale locale)
Returns the root URL for the API for a specificLocale
.static URLEndpoint
getRootUrl(Locale locale, CommunicationProtocol communicationProtocol)
Returns the root URL for the API for a specificLocale
andCommunicationProtocol
.String
getTable()
Returns the table portion of this URL.int
hashCode()
String
toString()
URLEndpoint
toURL(String language)
Generates a new URL to the API by replacing the current language tag in the URL with the specified language tag.URLEndpoint
toURL(String language, CommunicationProtocol communicationProtocol)
Generates a new URL to the API by replacing the current language tag and communication protocol in the URL with the specified language tag andCommunicationProtocol
.URLEndpoint
toURL(Locale locale)
Generates a new URL to the API using the specifiedLocale
.
-
-
-
Method Detail
-
append
public URLEndpoint append(String str)
Appends the given string to the URL.
- Parameters:
str
- the string to append- Returns:
- a
URLEndpoint
with the given string appended
-
getLanguage
public String getLanguage()
Returns the language portion of this URL.
Example: URL of https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0401/BE0401A/ is converted to sv.
Due to speed efficiency, this method does not perform any validity check on the specified URL. Calling this method without a valid URL for the API may (and probably will) result in undefined behavior.
- Returns:
- the language portion of this URL
-
getTable
public String getTable()
Returns the table portion of this URL.
Example: URL of https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0401/BE0401A/ is converted to BE/BE0401/BE0401A/.
Due to speed efficiency, this method does not perform any validity check on the specified URL. Calling this method without a valid URL for the API may (and probably will) result in undefined behavior.
- Returns:
- the table portion of this URL
-
toURL
public URLEndpoint toURL(Locale locale)
Generates a new URL to the API using the specified
Locale
.See
toURL(String)
for implementation details.- Parameters:
locale
- theLocale
to use- Returns:
- an
URLEndpoint
representing the URL
-
toURL
public URLEndpoint toURL(String language)
Generates a new URL to the API by replacing the current language tag in the URL with the specified language tag. The communication protocol used, such as HTTP or HTTPS, is not modified.
- Parameters:
language
- the language to use- Returns:
- an
URLEndpoint
representing the modified URL - See Also:
toURL(String, CommunicationProtocol)
-
toURL
public URLEndpoint toURL(String language, CommunicationProtocol communicationProtocol)
Generates a new URL to the API by replacing the current language tag and communication protocol in the URL with the specified language tag and
CommunicationProtocol
.The method performs two distinct operations, if needed: replacement of the communication protocol and replacement of the language tag. The following steps are performed to figure out what needs to be replaced:
- Replaces the communication protocol (such as "http") with the specified protocol.
- Specifies the start segment as the segment preceding the language tag segment in the URL.
- Finds the length of the language tag segment by finding the next forward slash following the start segment, as this indicates that the segment has ended.
- Replaces the content between the start and end of the segment (forward slashes excluded) with the new language tag.
Example: URL of https://api.scb.se/OV0104/v1/doris/sv/ssd/ and language input of en is converted to https://api.scb.se/OV0104/v1/doris/en/ssd/.
Due to speed efficiency, this method does not perform any validity check on the specified URL. Calling this method without a valid URL for the API may (and probably will) result in undefined behavior.
- Parameters:
language
- the language to usecommunicationProtocol
- the communication protocol to use- Returns:
- an
URLEndpoint
representing the modified URL
-
getRootUrl
public static URLEndpoint getRootUrl()
Returns the root URL for the API.
- Returns:
- an
URLEndpoint
representing theROOT_URL
-
getRootUrl
public static URLEndpoint getRootUrl(Locale locale)
Returns the root URL for the API for a specific
Locale
.- Parameters:
locale
- theLocale
- Returns:
- an
URLEndpoint
representing theROOT_URL
with a converted language tag segment matching the specifiedLocale
-
getRootUrl
public static URLEndpoint getRootUrl(Locale locale, CommunicationProtocol communicationProtocol)
Returns the root URL for the API for a specific
Locale
andCommunicationProtocol
.- Parameters:
locale
- theLocale
communicationProtocol
- theCommunicationProtocol
- Returns:
- an
URLEndpoint
representing theROOT_URL
with a converted language tag segment matching the specifiedLocale
andCommunicationProtocol
-
-