Search…
Use the Site Reputation SDK

Querying Site Reputation

The Site Reputation SDK enables you to warn or guard your users from accessing low reputation websites. The getSiteReputation function of the SDK returns a SiteReputation structure with attributes you can use to form a decision on whether to block access to a site or display a warning to your users.
TypeScript
Swift
Kotlin
// const client = new SudoSiteReputationClient({...})
​
import {
SiteReputation,
ReputationDataNotPresentError
} from '@sudoplatform/sudo-site-reputation'
​
let siteReputation: SiteReputation
try {
siteReputation = client.getSiteReputation('https://sudoplatform.com')
} catch (error) {
if (error instanceof ReputationDataNotPresentError) {
// There is no locally-cached site reputation data.
// Call `update` as described below before querying site reputation data.
// Fail or warn users if reputation data is not present.
} else {
throw error
}
}
var client: SudoSiteReputationClient!
​
let checkResult = client.getSiteReputation(url: "https://sudoplatform.com")
​
switch checkResult {
case .success(let reputation: SiteReputation):
// See the definition of SiteReputation below.
case .failure(.reputationDataNotPresent):
// There is no locally-cached site reputation data.
// Call `update` as described below before querying site reputation data.
// Fail or warn users if reputation data is not present.
case .failure(let error):
// An unexpected error occurred. Log or display it.
}
// val client: SudoSiteReputationClient
​
launch {
try {
val siteReputation = withContext(Dispatchers.IO) {
client.getSiteReputation(
url = "http://somedodgyhost.com/somewhere"
)
}
if (siteReputation.isMalicious) {
// URL should not be loaded
}
} catch (e: SudoSiteReputationException) {
// Handle/notify user of exception
}
}
The getSiteReputation function operates on locally cached site reputation data. If getSiteReputation throws a reputationDataNotPresent error, then you must call update and wait for it to complete before attempting to query site reputation.
TypeScript
Swift
Kotlin
interface SiteReputation {
/** True if the requested site has been reported as a known-malicious domain. */
readonly isMalicious: boolean
}
struct SiteReputation {
/// True if the requested site has been reported as a known-malicious domain.
let isMalicious: Bool
}
data class SiteReputation(
/** True if the requested site has been reported as a known-malicious domain. */
val isMalicious: Boolean
)

Updating Site Reputation Data

The getSiteReputation function operates on locally cached site reputation data. This data should be updated frequently in order to ensure reported reputation data is up-to-date. Call the update function to retrieve the latest site reputation data from the Sudo Platform Site Reputation Service. Cached reputation data that is already up-to-date will not be re-downloaded.
TypeScript
Swift
Kotlin
// const client = new SudoSiteReputationClient({...})
​
await client.update()
// `getSiteReputation` will now use the latest reputation data.
var client: SudoSiteReputationClient!
​
client.update { result in
switch result {
case .success:
// `getSiteReputation` will now use the latest reputation data.
case .failure(.alreadyInProgress):
// An outstanding call to `update` or `clearStorage` is already in progress.
case .failure(.cancelled):
// The update process was cancelled by a call to `clearStorage`.
case .failure(let error):
// An unexpected error occurred. Log or display it.
}
}
// val client: SudoSiteReputationClient
​
launch {
try {
withContext(Dispatchers.IO) {
client.update()
}
} catch (e: SudoSiteReputationException) {
// Handle/notify user of exception
}
}

Accessing the Last Updated Date

The SDK provides access to a timestamp representing the last time an update was successfully performed. To read this timestamp, access the lastUpdatePerformedAt property of the Site Reputation client.
TypeScript
Swift
Kotlin
// const client = new SudoSiteReputationClient({...})
​
const lastUpdate: Date | undefined = client.lastUpdatePerformedAt
var client: SudoSiteReputationClient!
​
let lastUpdated: Date? = client.lastUpdatePerformedAt
// val client: SudoSiteReputationClient
​
launch {
try {
val yesterday = Calendar.getInstance().apply {
add(Calendar.HOUR_OF_DAY, -24)
}
if (client.lastUpdatePerformedAt?.before(yesterday.time) == true) {
// Reputation rulesets are more than 24 hours old or are missing, update them.
withContext(Dispatchers.IO) {
client.update()
}
}
} catch (e: SudoSiteReputationException) {
// Handle/notify user of exception
}
}

Clearing Local Storage

To remove all cached reputation data persisted locally by the Site Reputation SDK, use the clearStorage function.
TypeScript
Swift
Kotlin
// const client = new SudoSiteReputationClient({...})
​
await client.clearStorage()
var client: SudoSiteReputationClient!
​
try? client.clearStorage()
// val client: SudoSiteReputationClient
​
launch {
try {
withContext(Dispatchers.IO) {
client.clearStorage()
}
} catch (e: SudoSiteReputationException) {
// Handle/notify user of exception
}
}

Checking Entitlements

Import the ENTITLEMENT_NAME string constant that can be compared with entitlements retrieved from the Entitlements SDK getEntitlements method.
TypeScript
Swift
Kotlin
​
​
// val client: SudoSiteReputationClient
​
val entitlementName = client.ENTITLEMENT_NAME