Member Information Management

Last Updated on : 2024-08-23 09:47:59download

This topic describes how to implement the features of member management using APIs.

  • Add member: How to add a new member and set the basic information.
  • Remove member: How to delete a member and all associated information.
  • Modify member information: How to update the name, role, and other information of a member.
  • Invite member: How to add a new member via an invitation code or invitation link.

The class ThingSmartMemberBiz is used for member management.

Compared with ThingSmartHomeMember, ThingSmartMemberBiz provides more features. If you are still using ThingSmartHomeMember, please refer to this document.

Class (or protocol) Description
ThingSmartMemberBiz The member management class.
ThingSmartHomeMemberModel The member model class.

Data model

Data model of ThingSmartHomeMemberModel

Field Type Description
memberId long long The member ID.
homeId long long The ID of the home that a member belongs to.
headPic NSString The avatar of the member.
name NSString The name of the member.
role ThingHomeRoleType The role of the member.
  • owner: Home owner
  • admin: Admin
  • member: Common member

The table below lists the permissions by role.

Role type Role description Permissions
Home owner The creator of a home, which has the highest level of privileges. There can be only one home owner per home.
  • Query, modify, and delete a home.
  • Transfer the role of home owner.
  • Query, create, modify, and delete a room in the home.
  • Query, modify, and delete a home member.
  • Add an admin and common member.
  • Add, query, control, edit, share, and remove a device. View device status and update device firmware.
  • Create, edit, dismiss, and control a group, and control devices.
  • Query, modify, and add a scene.
Admin An admin can be added only by a home owner. Multiple admins can be added in a home. An admin can add a common member and leave a home, but cannot delete a home.
  • Query, modify, and leave a home.
  • Query, create, modify, and delete a room in the home.
  • Query home members. Add, modify, and delete a common member.
  • Add, query, control, edit, share, and remove a device. View device status and update device firmware.
  • Create, edit, dismiss, and control a group.
  • Query, modify, and add a scene.
Common member A common member can be added by a home owner or admin. Multiple common members can be added in a home. A common member is only allowed to view information.
  • Query and leave a home.
  • Query a room.
  • Query a home member.
  • View device status and information.
  • View group information.
  • Query a scene.

Add a home member

  • A home owner can add an admin and common member.
  • An admin can add a common member.

API description

- (void)addHomeMemberWithModel:(ThingSmartHomeAddMemberRequestModel *)model
                        homeId:(long long)homeId
                       success:(void(^)(ThingSmartFamilyMemberModel *memberModel))success
                       failure:(ThingFailureError)failure;

Parameter description

Parameters Description
model The request model to add a member.
homeId The home ID.
success The success callback.
failure The failure callback.

Data model of ThingSmartHomeAddMemberRequestModel

Field Type Description
name NSString The nickname set for the invitee.
account NSString The account of the invitee.
countryCode NSString The country code of the invitee’s account.
role ThingHomeRoleType The role of the member.
headPic UIImage The avatar set for the invitee. If the value is set to nil, the invitee’s own avatar is used.
autoAccept BOOL Specifies whether the invitation is automatically accepted.
  • YES: The invitation is automatically accepted.
  • NO: The invitee needs to accept the invitation before joining the home.

Data model of ThingSmartFamilyMemberModel

Field Type Description
memberId long long The member ID.
headPic NSString The avatar of the member.

Example

Objective-C:

- (void)addMemberWithHomeId:(long long)homeId {
    ThingSmartHomeAddMemberRequestModel *requestModel = [[ThingSmartHomeAddMemberRequestModel alloc] init];
    requestModel.name = @"";
    requestModel.headPic = [UIImage imageNamed:@""];
    requestModel.countryCode = @"";
    requestModel.account = @"";
    requestModel.role = ThingHomeRoleType_Member;
    requestModel.autoAccept = NO;
    [[ThingSmartMemberBiz sharedInstance] addHomeMemberWithModel:requestModel homeId:homeId success:^(ThingSmartHomeMemberModel * _Nonnull memberModel) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func addMember(homeId:Int64) {
    let model = ThingSmartHomeAddMemberRequestModel()
    model.account = ""
    model.autoAccept = false
    model.countryCode = ""
    model.role = ThingHomeRoleType.member
    model.name = ""
    ThingSmartMemberBiz.sharedInstance().addHomeMember(with: model, homeId: homeId) { memberModel in

    } failure: { error in

    }
}

Remove a home member

A home owner specified by ThingHomeRoleType_Owner can remove an admin and role with low privileges. An admin specified by ThingHomeRoleType_Admin can remove a common member.

API description

The result of removing a member varies by the role of a memberId.

  • After a home admin or common member leaves a home, the home will not be dismissed and all the devices in the home will not be reset.
  • After a home owner leaves a home, the home will be dismissed and all the devices in the home will be reset, the same as the result of deleting a home.
- (void)removeHomeMemberWithMemberId:(long long)memberId
                             success:(ThingSuccessHandler)success
                             failure:(ThingFailureError)failure;

Parameter description

Parameters Description
memberId The ID of the member to remove.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeMember:(long long)memberId {
    [[ThingSmartMemberBiz sharedInstance] removeHomeMemberWithMemberId:memberId success:^{
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func removeMember(memberId:Int64) {
    ThingSmartMemberBiz.sharedInstance().removeHomeMember(withMemberId: memberId) {

    } failure: { error in

    }
}

Update a home member

A home owner specified by ThingHomeRoleType_Owner can modify an admin and role with low privileges. An admin specified by ThingHomeRoleType_Admin can modify a common member.

API description

- (void)updateHomeMemberInfoWithModel:(ThingSmartHomeMemberRequestModel *)model
                              success:(ThingSuccessHandler)success
                              failure:(ThingFailureError)failure;

Parameter description

Parameters Description
model Update the request model for member information.
success The success callback.
failure The failure callback.

Data model of ThingSmartHomeMemberRequestModel

Field Type Description
memberId long long The ID of the member to update.
name NSString The nickname set for the member.
role ThingHomeRoleType The role assigned to the member.
headPic UIImage The avatar set for the member.

Example

Objective-C:

- (void)updateMember:(long long)memberId {
    ThingSmartHomeMemberRequestModel *requestModel = [[ThingSmartHomeMemberRequestModel alloc] init];
    requestModel.memberId = memberId;
    requestModel.name = @"new nick name";
    requestModel.role = ThingHomeRoleType_Admin;
    requestModel.headPic = [UIImage imageNamed:@""];
    [[ThingSmartMemberBiz sharedInstance] updateHomeMemberInfoWithModel:requestModel success:^{
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func updateMember(memberId:Int64) {
    let requestModel = ThingSmartHomeMemberRequestModel()
    requestModel.name = "new nick name"
    requestModel.role = ThingHomeRoleType.admin
    requestModel.headPic = UIImage()
    requestModel.memberId = memberId
    ThingSmartMemberBiz.sharedInstance().updateHomeMemberInfo(with: requestModel) {

    } failure: { error in

    }
}

Link an account

If a home member is not linked with an email address or phone number, for example, when signing in with a third party, this method can link them with their email address or phone number. A home owner can do this for an admin and a role with low privileges. An admin can do this for a common member.

API description

- (void)associateHomeMemberWithModel:(ThingSmartHomeMemberAssocaiteRequestModel *)model
                             success:(void(^)(BOOL result))success
                             failure:(ThingFailureError)failure;

Parameter description

Parameters Description
model The request model to link a member account.
success The success callback.
failure The failure callback.

Data model of ThingSmartHomeMemberAssocaiteRequestModel

Field Type Description
memberId long long The ID of the member to link an account.
countryCode NSString The country code of the member.
role ThingHomeRoleType The role assigned to the member.
account NSString The account to link.

Example

Objective-C:

- (void)associateMember:(long long)memberId {
    ThingSmartHomeMemberAssocaiteRequestModel *requestModel = [[ThingSmartHomeMemberAssocaiteRequestModel alloc] init];
    requestModel.memberId = memberId;
    requestModel.account = @"";
    requestModel.role = ThingHomeRoleType_Member;
    requestModel.countryCode = @"";
    [[ThingSmartMemberBiz sharedInstance] associateHomeMemberWithModel:requestModel success:^(BOOL result) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func associateMember(memberId:Int64) {
    let requestModel = ThingSmartHomeMemberAssocaiteRequestModel()
    requestModel.memberId = memberId;
    requestModel.account = ""
    requestModel.countryCode = ""
    requestModel.role = ThingHomeRoleType.member
    ThingSmartMemberBiz.sharedInstance().associateHomeMember(with: requestModel) { result in

    } failure: { error in

    }
}

Get the list of members

Get the list of members in a home.

API description

- (void)getHomeMemberListWithHomeId:(long long)homeId
                            success:(void(^)(NSArray <ThingSmartHomeMemberModel *> * list))success
                            failure:(ThingFailureError )failure;

Parameter description

Parameters Description
homeId The home ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getMemberListWithHomeId:(long long)homeId {
    [[ThingSmartMemberBiz sharedInstance] getHomeMemberListWithHomeId:homeId success:^(NSArray<ThingSmartHomeMemberModel *> * _Nonnull list) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func getMemberList(with homeId:Int64) {
    ThingSmartMemberBiz.sharedInstance().getHomeMemberList(withHomeId: homeId) { memberList in

    } failure: { error in

    }
}

Get member information

Get the information about members in a home.

API description

- (void)getHomeMemberInfoWithHomeId:(long long)homeId
                           memberId:(long long)memberId
                            success:(void(^)(ThingSmartHomeMemberModel * model))success
                             failure:(ThingFailureError)failure;

Parameter description

Parameters Description
homeId The home ID.
memberId The member ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getMemberInfoWithHomeId:(long long)homeId memberId:(long long)memberId {
    [[ThingSmartMemberBiz sharedInstance] getHomeMemberInfoWithHomeId:homeId memberId:memberId success:^(ThingSmartHomeMemberModel * _Nonnull model) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func getMemberInfo(homeId:Int64, memberId:Int64) {
    ThingSmartMemberBiz.sharedInstance().getHomeMemberInfo(withHomeId: homeId, memberId: memberId) { memberModel in

    } failure: { error in

    }
}

Get the devices a member can access

Get the list of devices that a member can use. For example, access to door locks or security devices is only granted to specific members.

API description

- (void)getHomeMemberDeviceListWithMemberId:(long long)memberId
                                    success:(void(^)(NSArray <ThingSmartMemberLinkDeviceListModel *> * list))success
                                  	failure:(ThingFailureError)failure;

Parameter description

Parameters Description
memberId The member ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getDeviceListWithMemberId:(long long)memberId {
    [[ThingSmartMemberBiz sharedInstance] getHomeMemberDeviceListWithMemberId:memberId success:^(NSArray<ThingSmartMemberLinkDeviceListModel *> * _Nonnull list) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func getDeviceList(memberId:Int64) {
    ThingSmartMemberBiz.sharedInstance().getHomeMemberDeviceList(withMemberId: memberId) { deviceList in

    } failure: { error in

    }
}

Transfer a home

The home owner transfers a home to another member.

API description

- (void)transferHomeWithMemberId:(long long)memberId
                         success:(ThingSuccessHandler)success
                         failure:(ThingFailureError)failure;

Parameter description

Parameters Description
memberId The member ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)transferHomeToMember:(long long)memberId {
    [[ThingSmartMemberBiz sharedInstance] transferHomeWithMemberId:memberId success:^{
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func transferHome(to memberId:Int64) {
    ThingSmartMemberBiz.sharedInstance().transferHome(withMemberId: memberId) {

    } failure: { error in

    }
}

Get the home invitation records

Get the records of home invitations, including the pending and expired ones.

API description

- (void)getInvitationRecordListWithHomeId:(long long)homeId
                                    success:(void(^)(NSArray<ThingSmartHomeInvitationRecordModel *> *invitationRecordList))success
                                    failure:(ThingFailureError)failure;

Parameter description

Parameters Description
homeId The home ID.
success The success callback.
failure The failure callback.

Data model of ThingSmartHomeInvitationRecordModel

Field Type Description
validTime NSInteger The validity period of the invitation.
invitationID NSNumber The invitation ID.
invitationCode NSString The invitation code.
name NSString The name of the invitation.

Example

Objective-C:

- (void)getRecordListWithHomeId:(long long)homeId {
    [[ThingSmartMemberBiz sharedInstance] getInvitationRecordListWithHomeId:homeId success:^(NSArray<ThingSmartHomeInvitationRecordModel *> * _Nonnull invitationRecordList) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func getRecordList(homeId:Int64) {
    ThingSmartMemberBiz.sharedInstance().getInvitationRecordList(withHomeId: homeId) { recordList in

    } failure: { error in

    }
}

Create a home invitation code

Make a callback on success to return the invitation code and message.

API description

- (void)createInvitationWithHomeId:(long long)homeId
                           success:(void(^)(ThingSmartHomeInvitationResultModel *invitationResultModel))success
                           failure:(ThingFailureError)failure;

Parameter description

Parameters Description
homeId The home ID.
success The success callback.
failure The failure callback.

Data model of ThingSmartHomeInvitationResultModel

Field Type Description
invitationCode NSString The invitation code.
invitationMsgContent NSString The invitation message.

Example

Objective-C:

- (void)createInvitation:(long long)homeId {
    [[ThingSmartMemberBiz sharedInstance] createInvitationWithHomeId:homeId success:^(ThingSmartHomeInvitationResultModel * _Nonnull invitationResultModel) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func createInvitation(homeId:Int64) {
    ThingSmartMemberBiz.sharedInstance().createInvitation(withHomeId: homeId) { invitation in

    } failure: { error in

    }
}

Renew a home invitation code

After an invitation code expires, this method can create a new one with the original invitation ID unchanged.

API description

- (void)reinviteInvitationWithInvitationId:(NSNumber *)invitationId
                                   success:(void(^)(ThingSmartHomeInvitationResultModel *invitationResultModel))success
                                   failure:(ThingFailureError)failure;

Parameter description

Parameters Description
invitationId The invitation ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)reinviteInvitation:(NSNumber *)invitationId {
    [[ThingSmartMemberBiz sharedInstance] reinviteInvitationWithInvitationId:invitationId success:^(ThingSmartHomeInvitationResultModel * _Nonnull invitationResultModel) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func reinviteInvitation(invitationId:NSNumber) {
    ThingSmartMemberBiz.sharedInstance().reinviteInvitation(withInvitationId: invitationId) { invitation in

    } failure: { error in

    }
}

Revoke a home invitation code

Revoke a home invitation code. The invitee cannot join the home with the code anymore.

API description

- (void)cancelInvitationWithInvitationId:(NSNumber *)invitationId
                                 success:(ThingSuccessBOOL)success
                                 failure:(ThingFailureError)failure;

Parameter description

Parameters Description
invitationId The invitation ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)cancelInvitation:(NSNumber *)invitationId {
    [[ThingSmartMemberBiz sharedInstance] cancelInvitationWithInvitationId:invitationId success:^(BOOL result) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func cancelInvitation(invitationId:NSNumber) {
    ThingSmartMemberBiz.sharedInstance().cancelInvitation(withInvitationId: invitationId) { result in

    } failure: { error in

    }
}

Update a home invitation code

Modify the information about the invitee and update the invitation code.

API description

- (void)updateInvitationWithModel:(ThingSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
                          success:(ThingSuccessBOOL)success
                          failure:(ThingFailureError)failure;

Parameter description

Parameters Description
invitationInfoRequestModel The request model to update an invitation code.
success The success callback.
failure The failure callback.

Data model of ThingSmartHomeInvitationInfoRequestModel

Field Type Description
invitationID NSString The invitation ID.
name NSString The name of the invitation.

Example

Objective-C:

- (void)updateInvitation:(ThingSmartHomeInvitationInfoRequestModel *)model {
    ThingSmartHomeInvitationInfoRequestModel *requestModel = [[ThingSmartHomeInvitationInfoRequestModel alloc] init];
    requestModel.invitationID = [NSNumber new];
    requestModel.name = @"";
    [[ThingSmartMemberBiz sharedInstance] updateInvitationWithModel:model success:^(BOOL result) {
        
    } failure:^(NSError *error) {
        
    }];
}

Swift:

func updateInvitation(invitationId:NSNumber) {
    let requestModel = ThingSmartHomeInvitationInfoRequestModel()
    requestModel.invitationID = invitationId
    requestModel.name = ""
    ThingSmartMemberBiz.sharedInstance().updateInvitation(with: requestModel) { result in

    } failure: { error in

    }
}