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
1
// const client = new SudoSiteReputationClient({...})
2
​
3
import {
4
SiteReputation,
5
ReputationDataNotPresentError
6
} from '@sudoplatform/sudo-site-reputation'
7
​
8
let siteReputation: SiteReputation
9
try {
10
siteReputation = client.getSiteReputation('https://sudoplatform.com')
11
} catch (error) {
12
if (error instanceof ReputationDataNotPresentError) {
13
// There is no locally-cached site reputation data.
14
// Call `update` as described below before querying site reputation data.
15
// Fail or warn users if reputation data is not present.
16
} else {
17
throw error
18
}
19
}
Copied!
1
var client: SudoSiteReputationClient!
2
​
3
let checkResult = client.getSiteReputation(url: "https://sudoplatform.com")
4
​
5
switch checkResult {
6
case .success(let reputation: SiteReputation):
7
// See the definition of SiteReputation below.
8
case .failure(.reputationDataNotPresent):
9
// There is no locally-cached site reputation data.
10
// Call `update` as described below before querying site reputation data.
11
// Fail or warn users if reputation data is not present.
12
case .failure(let error):
13
// An unexpected error occurred. Log or display it.
14
}
Copied!
1
// val client: SudoSiteReputationClient
2
​
3
launch {
4
try {
5
val siteReputation = withContext(Dispatchers.IO) {
6
client.getSiteReputation(
7
url = "http://somedodgyhost.com/somewhere"
8
)
9
}
10
if (siteReputation.isMalicious) {
11
// URL should not be loaded
12
}
13
} catch (e: SudoSiteReputationException) {
14
// Handle/notify user of exception
15
}
16
}
Copied!
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
1
interface SiteReputation {
2
/** True if the requested site has been reported as a known-malicious domain. */
3
readonly isMalicious: boolean
4
}
Copied!
1
struct SiteReputation {
2
/// True if the requested site has been reported as a known-malicious domain.
3
let isMalicious: Bool
4
}
Copied!
1
data class SiteReputation(
2
/** True if the requested site has been reported as a known-malicious domain. */
3
val isMalicious: Boolean
4
)
Copied!

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
1
// const client = new SudoSiteReputationClient({...})
2
​
3
await client.update()
4
// `getSiteReputation` will now use the latest reputation data.
Copied!
1
var client: SudoSiteReputationClient!
2
​
3
client.update { result in
4
switch result {
5
case .success:
6
// `getSiteReputation` will now use the latest reputation data.
7
case .failure(.alreadyInProgress):
8
// An outstanding call to `update` or `clearStorage` is already in progress.
9
case .failure(.cancelled):
10
// The update process was cancelled by a call to `clearStorage`.
11
case .failure(let error):
12
// An unexpected error occurred. Log or display it.
13
}
14
}
Copied!
1
// val client: SudoSiteReputationClient
2
​
3
launch {
4
try {
5
withContext(Dispatchers.IO) {
6
client.update()
7
}
8
} catch (e: SudoSiteReputationException) {
9
// Handle/notify user of exception
10
}
11
}
Copied!

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
1
// const client = new SudoSiteReputationClient({...})
2
​
3
const lastUpdate: Date | undefined = client.lastUpdatePerformedAt
Copied!
1
var client: SudoSiteReputationClient!
2
​
3
let lastUpdated: Date? = client.lastUpdatePerformedAt
Copied!
1
// val client: SudoSiteReputationClient
2
​
3
launch {
4
try {
5
val yesterday = Calendar.getInstance().apply {
6
add(Calendar.HOUR_OF_DAY, -24)
7
}
8
if (client.lastUpdatePerformedAt?.before(yesterday.time) == true) {
9
// Reputation rulesets are more than 24 hours old or are missing, update them.
10
withContext(Dispatchers.IO) {
11
client.update()
12
}
13
}
14
} catch (e: SudoSiteReputationException) {
15
// Handle/notify user of exception
16
}
17
}
Copied!

Clearing Local Storage

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

Checking Entitlements

Import the ENTITLEMENT_NAME string constant that can be compared with entitlements retrieved from the Entitlements SDK getEntitlements method.
TypeScript
Swift
Kotlin
1
​
Copied!
1
​
Copied!
1
// val client: SudoSiteReputationClient
2
​
3
val entitlementName = client.ENTITLEMENT_NAME
Copied!
Last modified 1mo ago