SimpleSample-ratings-ios

Ask tech team
From QuickBlox Developers (API docs, code samples, SDK)
Jump to: navigation, search

Contents

Sources

Project homepage on GIT — https://github.com/QuickBlox/quickblox-ios-sdk/tree/master/sample-ratings

Download ZIP - https://github.com/QuickBlox/quickblox-ios-sdk/archive/master.zip

Setup guide

In order to work with the Ratings module, you must create a Game mode at admin.quickblox.com , Ratings module page, Game modes tab.

Overview

This sample demonstrates how to work with the QuickBlox ratings module.
It allows you to rate any items (e.g. films, products, music) and see the average ratings

It shows you how to:

  1. Rate some items
  2. Get average ratings


Case Studies

  • Creating a Score
QBRScore *score = [QBRScore score];
score.gameModeID = 115;
score.value = 100;
 
[QBRatings createScore:score delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Create Score result
    if([result isKindOfClass:QBRScoreResult.class]){        
        if(result.success){
            QBRScoreResult *res = (QBRScoreResult *)result;
            NSLog(@"Score=%@", res.score);        
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Getting a Score with an ID
[QBRatings scoreWithID:862 delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Get Score with ID result
    if([result isKindOfClass:QBRScoreResult.class]){        
        if(result.success){
            QBRScoreResult *res = (QBRScoreResult *)result;
            NSLog(@"Score=%@", res.score);     
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Updating a Score
QBRScore *score = [QBRScore score];
score.ID = 862;
score.value = 200;
 
[QBRatings updateScore:score delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Update Score result
    if([result isKindOfClass:QBRScoreResult.class]){        
        if(result.success){
            QBRScoreResult *res = (QBRScoreResult *)result;
            NSLog(@"Score=%@", res.score);        
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Deleting a score with an ID
[QBRatings deleteScoreWithID:862 delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Delete score with ID result
    if([result isKindOfClass:QBRScoreResult.class]){        
        if(result.success){
            NSLog(@"Score was deleted successfully");        
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Getting the top "N" of scores
QBRScoreGetRequest *getRequest = [QBRScoreGetRequest request];
getRequest.sortAsc = 1;
getRequest.sortBy = ScoreSortByKindValue;
 
[QBRatings topNScores:3 gameModeID:114 extendedRequest:getRequest delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Get top N scores result
    if([result isKindOfClass:QBRScorePagedResult.class]){       
        if(result.success){
            QBRScorePagedResult *res = (QBRScorePagedResult *)result;
            NSLog(@"Scores=%@", res.scores);
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Getting scores with a user ID
QBRScoreGetRequest *getRequest = [QBRScoreGetRequest request];
getRequest.sortAsc = 1;
getRequest.sortBy = ScoreSortByKindValue;
 
[QBRatings scoresWithUserID:292 extendedRequest:getRequest delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Get scores with user ID result
    if([result isKindOfClass:QBRScorePagedResult.class]){       
        if(result.success){
            QBRScorePagedResult *res = (QBRScorePagedResult *)result;
            NSLog(@"Scores=%@", res.scores);
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Get an average with the game mode ID
[QBRatings averageWithGameModeID:114  delegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Get average with game mode ID result
    if([result isKindOfClass:QBRAverageResult.class]){
        if(result.success){
            QBRAverageResult *res = (QBRAverageResult *)result;
            NSLog(@"Average=%@", res.average);
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}
  • Getting averages for an application
[QBRatings averagesForApplicationWithDelegate:self];
 
...
 
- (void)completedWithResult:(Result *)result{
    // Get averages for application result
    if([result isKindOfClass:QBRAveragePagedResult.class]){
        if(result.success){
            QBRAveragePagedResult *res = (QBRAveragePagedResult *)result;
            NSLog(@"Averages=%@", res.averages);
        }else{
            NSLog(@"errors=%@", result.errors);
        }
    }
}

Comments

Feel free to comment on this page using the form below.

blog comments powered by Disqus