Skip to main content

GmailClient

Handles Gmail OAuth authentication and e-receipt parsing via the Gmail API.

Package: com.microblink.digital

Declaration

class GmailClient(context: Context, clientId: String) : Client
class GmailClient(context: Context, threads: Int, clientId: String) : Client

clientId is the OAuth 2.0 Client ID from the Google API Console.


Quick Reference

Properties

PropertyDescription
dayCutoff()Search depth in days
dateCutoff()Specific date boundary, overrides dayCutoff
searchUntil()Upper boundary for the search period
countryCode()ISO country code for parsing accuracy
sendersToSearch()Maps sender email addresses to merchant identifiers
filterSensitive()Whether to redact sensitive data from results
useAggregation()Whether to aggregate related emails into a single result
subProducts()Whether sub-products are included in results
overrideEndpoint()Override the server-side endpoint for result posting

Methods

MethodDescription
login()Initiates the Gmail OAuth sign-in flow
account()Returns the currently signed-in Google account
logout()Signs out and clears stored tokens
onAccountAuthorizationActivityResult()Pass-through for OAuth callback
verify()Validates stored Gmail credentials
messages(activity)Fetches and parses e-receipts from Gmail
clearLastCheckedTime()Resets the last-checked timestamp
close()Releases client resources

Configuration Properties

dayCutoff()

fun dayCutoff(): Int
fun dayCutoff(days: Int)

Search depth in days.


dateCutoff()

fun dateCutoff(): Date?
fun dateCutoff(date: Date)

Specific date boundary, overrides dayCutoff when set.


searchUntil()

fun searchUntil(): Date?
fun searchUntil(date: Date)

Upper boundary for the search period.


countryCode()

fun countryCode(): String?
fun countryCode(code: String)

ISO country code to improve parsing accuracy for region-specific receipts.


sendersToSearch()

fun sendersToSearch(): Map<String, Merchant>?
fun sendersToSearch(senders: Map<String, Merchant>)

Maps sender email addresses to merchant identifiers for filtering.


filterSensitive()

fun filterSensitive(): Boolean
fun filterSensitive(filter: Boolean)

Whether to redact sensitive data from parsed results.


useAggregation()

fun useAggregation(): Boolean
fun useAggregation(aggregate: Boolean)

Whether to aggregate related emails (e.g., shipping updates) into a single result.


subProducts()

fun subProducts(): Boolean
fun subProducts(enabled: Boolean)

Whether sub-products are included in parsed results.


overrideEndpoint()

fun overrideEndpoint(): String?
fun overrideEndpoint(endpoint: String)

Override the server-side endpoint for result posting.


Authentication Methods

login()

fun login(): Task<GoogleSignInAccount>
fun login(activity: Activity, executor: Executor): Task<GoogleSignInAccount>

Initiates the Gmail OAuth sign-in flow.


account()

fun account(): Task<GoogleSignInAccount>
fun account(activity: Activity): Task<GoogleSignInAccount>

Returns the currently signed-in Google account.


logout()

fun logout(): Task<Boolean>
fun logout(executor: Executor): Task<Boolean>

Signs out the current Gmail account and clears stored tokens.


onAccountAuthorizationActivityResult(requestCode, resultCode, data)

fun onAccountAuthorizationActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent
): Task<GoogleSignInAccount>

Pass-through for Activity.onActivityResult() to handle OAuth callback. Required for the OAuth flow to complete.


verify()

fun verify(): Task<Boolean>

Validates that stored Gmail credentials are still active.


Parsing Methods

messages(activity)

fun messages(activity: Activity): Task<List<ScanResults>>
fun messages(activity: Activity, executor: Executor): Task<List<ScanResults>>

Fetches and parses e-receipts from the signed-in Gmail account.


fun messages(provider: Provider, sender: String, html: String): Task<List<ScanResults>>

Parses e-receipt data from a raw HTML string for testing purposes.


fun messages(executor: Executor, provider: Provider, sender: String, html: String): Task<List<ScanResults>>

Parses e-receipt data from raw HTML using the specified executor.


clearLastCheckedTime()

fun clearLastCheckedTime(): Task<Boolean>

Resets the last-checked timestamp, causing the next messages() call to re-fetch from the cutoff date.


close()

fun close()

Releases client resources.