Profile API for iOS

Follow
NOTE: All methods described here are blocking and must not be called from the UI thread.

Once Beemray service has started, you can access user profiles by sending the following messages:

NSError *myError;
 
/**
 Gets the list of profiles from the registered user's account in backend.
 
 @param error If an error occurs, upon return contains an NSError object that describes the problem.
 If you are not interested in possible errors, pass in `NULL`.
  
 @warning This method is blocking and should not be called from a UI thread
 
 @return array of BeemrayProfile instances; or `nil` if an error occurs
 */
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSArray *profiles = [[Beemray sharedInstance] listProfilesWithError:&myError];
});
 
/**
 Gets the profile with the given title from the registered user's account in backend.
 
 @param title User-friendly name for the new profile
 @param error If an error occurs, upon return contains an NSError object that describes the problem.
 If you are not interested in possible errors, pass in `NULL`.
 
 @warning This method is blocking and should not be called from a UI thread
 
 @return profile matching given title; or `nil` if such a profile is not found
 */
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    profile = [[Beemray sharedInstance] getProfileWithTitle:@"myProfile" error:&myError];
});
 
/**
 Gets the profile with the given ID from the registered user's account in backend.
 
 @param profileId Unique identifier for the profile to get
 @param error If an error occurs, upon return contains an NSError object that describes the problem.
 If you are not interested in possible errors, pass in `NULL`.
 
 @warning This method is blocking and should not be called from a UI thread
 
 @return profile matching given title; or `nil` if such a profile is not found
 */
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    profile = [[Beemray sharedInstance] getProfileWithId:12345 error:&myError];
});

 

A profile contains zero or more profile categories, which in turn contain zero or more profile elements of different types, always a subclass of BeemrayProfileElement. Each element is identified by a key and has value that you can consult or modify in order to store information about current user. The data type of the value depends on the specific subclass of BeemrayProfileElement.


BeemrayProfileCategory *category = [profile.categories objectAtIndex:0];
 
for(BeemrayProfileElement *element in category.elements) {
 
    NSLog(@"%@", element.key);
    NSLog(@"%@", element.stringValue);
 
    if([element isKindOfClass:[BeemrayProfileElementString class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementBoolean class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementLong class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementLongRange class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementTimestamp class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementTimestampRange class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementTimestamp class]])
        ((BeemrayProfileElementLong*)element).value = __new_value__;
    else if([element isKindOfClass:[BeemrayProfileElementOptionList class]]) {
        NSArray *options = ((BeemrayProfileElementOptionList*)element).options;
        for(BeemrayProfileOption *option in options) {
            option.selected = __new_value__;
        }
    }
}

 

Each class expects a different type of value. Programmers must verify that the correct data type is always used. Allowed classes (and value types) are:

 

Once you have modified the elements in a profile, you can save the data back to the backend. The following method will update the given profile with new values: 


/**
/**
 Updates the values stored in the backend for the elements in the given profile.
  
 @param profile The profile to update. Only elements values or selected options may differ from a
 profile returned by one of the `getProfileWith...` methods. Otherwise the request is likely to fail.
 @param error If an error occurs, upon return contains an NSError object that describes the problem.
 If you are not interested in possible errors, pass in `NULL`.
 @warning This method is blocking and should not be called from a UI thread
 @return `YES` iff the request was successful. Otherwise, check error to know the cause.
 */
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    BOOL success = [[Beemray sharedInstance] updateValuesForProfile:profile error:&myError];
});
 
/**
 Updates the value stored in the backend for the given elements. If the element is of type
 BeemrayProfileElementOptionList, options' selected status may be updated.
 
 @param element The element to update. Only value or selected options may differ from an
 element returned by one of the `getProfileWith...` methods. Otherwise the request is likely to fail.
 @param error If an error occurs, upon return contains an NSError object that describes the problem.
 If you are not interested in possible errors, pass in `NULL`.
 @warning This method is blocking and should not be called from a UI thread
 @return `YES` iff the request was successful. Otherwise, check error to know the cause.
 */
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    BOOL success = [[Beemray sharedInstance] updateValuesForProfileElement:element error:&myError];
});
Have more questions? Submit a request

Comments