Invitations

Handles Invitation related requests with IMS web services.

Primary Driver Send Invitation to Secondary Driver

The SDK allows for the host application to enable the primary driver to send invitations to any secondary driver based on VEHICLE or FAMILY ACCOUNT.

Required information

*Identity: In order to send invitation by account, the application must have a valid user (represented by the Identity). That user must be active.

Concrete example

Sending invitation based on account

To send the invitation, one can use the following snippet. In this example we send an invitation based on ACCOUNT.
Swift
Kotlin
let invitationService = InvitationService(identity: identity)
invitationService.sendAccountInvitation(fromUserID: fromUserID,
toUserFirstName: toUserFirstName,
toUserLastName: toUserLastName,
toUserEmail: toUserEmail,
toUserPhoneNumber: toUserPhoneNumber,
fromAccountIds: fromAccountIDs, then: { result in
switch result {
case .success(_):
// invitation successful
case .failure
// error
}
})
val service = InvitationService(identity)
service.sendAccountInvitation(fromUserId,
fromAccountIds,
toUserFirstName,
toUserLastName,
toUserPhoneNumber,
toUserEmail) { result: Result<List<Invitation>> ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val response = result.value
completionHandler(content)
}
})

Sending invitation based on vehicle

To send the invitation based on VEHICLE you need to provide vehicleIds field instead of fromAccountIds and to call sendVehicleInvitation.
Swift
Kotlin
let invitationService = InvitationService(identity: identity)
invitationService.sendVehicleInvitation(fromUserID: fromUserID,
toUserFirstName: toUserFirstName,
toUserLastName: toUserLastName,
toUserEmail: toUserEmail,
toUserPhoneNumber: toUserPhoneNumber,
vehicleIDs: vehicleIDs, then: { result in
switch result {
case .success(_):
// invitation successful
case .failure
// error
}
})
val service = InvitationService(identity)
service.sendVehicleInvitation(fromUserId,
vehicleIds,
toUserFirstName,
toUserLastName,
toUserPhoneNumber,
toUserEmail){ result ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val response = result.value
completionHandler(content)
}
}

Remove secondary user from FAMILY ACCOUNT.

Required information

*Identity: In order to remove guest driver from account, the application must have a valid user (represented by the Identity). That user must be active.

Concrete example

Removing secondary user based on account

To remove secondary guest driver from the account, one can use following snippet.
Swift
Kotlin
let service = InvitationService(identity: identity)
service.removeGuestDriverFromAccount(toUserId: userID,
accountId: accountID, then: { result in
switch result {
case .success(_):
// successfully removed
case .failure
// error
}
})
val service = InvitationService(identity)
service.removeDriverFromAccount(userId,
accountId) { result ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val response = result.value
completionHandler(content)
}
}

Removing secondary user based on vehicle

To remove secondary guest driver from vehicle, one can use following snippet.
Swift
Kotlin
let service = InvitationService(identity: identity)
service.removeGuestDriverFromVehicle(toUserId: userID,
vehicleId: vehicle, then: { result in
switch result {
case .success(_):
// successfully removed
case .failure
// error
}
})
val service = InvitationService(identity)
service.removeDriverFromVehicle(userId,
vehicleId){ result ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val response = result.value
completionHandler(content)
}
}

Retrieve Pending Invitations

The host application can retrieve pending invitations. The list contains all invitations that the user has sent or received, so apps should check the primaryDriver and secondaryDriver ID's to see if the current user sent (primary) or received (secondary) each one.

Required information

  • Identity: In order to retrieve the invitations, the application must have a valid user (represented by the Identity). That user has to be active.

Concrete example

To retrieve the account invitations, one can use the following snippet
Swift
Kotlin
let service = InvitationService(identity: identity)
service.fetchAccountInvites(then: { result in
guard !result.value?.isEmpty else {
// failure
return
}
completionHandler(.success(result.value))
})
val service = InvitationService(identity)
service.fetchInvitations(userId) { result: Result<InvitationResponse?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val response = result.value
completionHandler(content)
}
})
To retrieve vehicle invites, one can use following snippet.
Swift
Kotlin
let service = InvitationService(identity: identity)
service.fetchVehicleInvites(then: { result in
guard !result.value?.isEmpty else {
// failure
return
}
completionHandler(.success(result.value))
})
val service = InvitationService(identity)
service.fetchVehicleInvitations(userId) { result: Result<InvitationResponse?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val response = result.value
completionHandler(content)
}
})

Respond to Pending Invitation

The host application can accept or decline pending invitations.

Required information

  • Identity: In order to accept or decline invitations, the application must have a valid user (represented by the Identity). That user has to be active.

Concrete example

To accept or decline an invitation, one can use the following snippet
Swift
Kotlin
let service = InvitationService(identity: identity)
service.respondToInvitation(toUserId: toUserId,
invitationId: invitationId,
response: response, then: { result in
switch result
case .success(_):
// response successful
case .failure(_):
// error
})
val service = InvitationService(identity)
service.respondInvitation(invitation,
Invitation.Response.ACCEPT) { result: Result<Any> ->
if (result.throwable != null) {
// failure
} else {
// Success
}
})

Cancel Pending Invitation

The host application can cancel pending invitations.

Required information

  • Identity: In order to cancel invitations, the application must have a valid user (represented by the Identity). That user has to be active.
  • UserId: Only the user who sent the invitation can cancel it.

Concrete example

To cancel to an invitation, one can use the following snippet
Swift
Kotlin
let service = InvitationService(identity: identity)
service.cancelVehicleInvitation(fromUserId: fromUserId,
invitationId: invitationId,
then: { result in
switch result
case .success(_):
// cancel successful
case .failure(_):
// error
})
val service = InvitationService(identity)
service.cancelInvitation(invitation) { result: Result<Any> ->
if (result.throwable != null) {
// failure
} else {
// Success
}
})