Profile services

📘

data consistency with entity tag

In order to manage concurrent updates of an profile from many devices/websites use eTag. When obtaining profile details from the services you can find an eTag in CMPResult object. It describes what version of server data you got. When you want to update this data pass the same eTag with the new profile details. If the server data will change before your next update the services will not allow such modification until you obtain the recent version of the data and pass correct eTag with the next update. This way you can keep consistency of the data across many devices.

Get profile:

[client.services.profile getProfileForProfileID:@"<PROFILE-ID>" completion:^(CMPResult<CMPProfile *> * result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];
client.services.profile.getProfile(profileID: "") { (result) in
    if let err = result.error {
        // error occurred
    } else if let obj = result.object {
        // success
    }
}

Query profiles:

// query profiles where there is a given value under the given key
CMPQueryElements *e1 = [[CMPQueryElements alloc] initWithKey:@"key" element:CMPQueryElementEqual value:@"value"];

[client.services.profile queryProfilesWithQueryElements:[NSArray arrayWithObjects:e1, nil] completion:^(CMPResult<NSArray<CMPProfile *> *> * result) {
	if (result.error) {
		// error occurred
	} else {
		// success
	}
}];
client.services.profile.queryProfiles(queryElements: [.init(key: "email", element: .contains, value: "new")]) { (result) in
    if let err = result.error {
        // error occurred
    } else if let obj = result.object {
        // success
    }
}

Patch profile:

Applies patch for an user profile. This method won't erase previous profile details with different keys.

[client.services.profile patchProfileWithProfileID:@"<PROFILE-ID>" attributes:@{@"email" : @"[email protected]"} eTag:nil completion:^(CMPResult<CMPProfile *> * result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];
client.services.profile.patchProfile(profileID: "profileId", attributes: ["email" : "[email protected]"], eTag: nil) { (result) in
    if let err = result.error {
        // error occurred
    } else if let obj = result.object {
        // success
    }
}

Update profile:

Update your user profile providing custom map of values that should be associated with it.

[client.services.profile updateProfileWithProfileID:@"<PROFILE-ID>" attributes:@{@"email" : @"[email protected]"} eTag:nil completion:^(CMPResult<CMPProfile *> * result) {
    if (result.error) {
        // error occurred
    } else {
        // success
    }
}];
client.services.profile.updateProfile(profileID: "profileId", attributes: ["email" : "[email protected]"], eTag: nil) { (result) in
    if let err = result.error {
        // error occurred
    } else if let obj = result.object {
        // success
    }
}