AppChains Integration using Objective-C | Sequencing.com

Real-Time Personalization (+RTP) API Guide

Integration

Sequencing.com has already everything to simplify integration of AppChains API into your Objective-C based project.

There are 2 ways of achiving this:

  • Get code from our GitHub repository and paste it into your project
  • Integrate using our Cocoapod artifacts

For Cocoapods integration please follow next steps

1) If you are new to CocoaPods, check general "Getting started" guide

2) Create Podfile in your project directory:

$ pod init

3) Specify following parameters in Podfile:

pod 'sequencing-app-chains-api-objc', '~> 1.1.0'

4) Install the dependency in your project:

$ pod install

5) Always open the Xcode workspace instead of the project file.

$ open *.xcworkspace

 

Objective-C module API

Method Purpose Arguments Description
- (instancetype)initWithToken:(NSString *)token Constructor  
- (instancetype)initWithToken:(NSString *)token withHostName:(NSString *)hostName Constructor Constructor used for creating AppChains class instance in case reporting API is needed and where security token is required
- (void)getReportWithApplicationMethodName:(NSString *)applicationMethodName withDatasourceId:(NSString *)datasourceId withSuccessBlock:(void (^)(Report *result))success withFailureBlock:(void (^)(NSError *error))failure; Reporting API
  • applicationMethodName - name of data processing routine
  • datasourceId - input data identifier
  • success - callback executed on success operation, results with Report object
  • failure - callback executed on operation failure
 
- (void)getBatchReportWithApplicationMethodName:(NSArray *)appChainsParams withSuccessBlock:(ReportsArray)success withFailureBlock:(void (^)(NSError *error))failure; Reporting API
  • appChainsParams - array of params for batch request
    Each param should be an array with items:
    first object: applicationMethodName
    last object: datasourceId
  • success - callback executed on success operation, results with array of dictionaries.
    Each dictionary has following keys and objects:
    appChainID - appChain ID string
    report - Report object
  • failure - callback executed on operation failure
 

 

Code snippet

Single App Chain retrieval example

AppChains *appChains = [[AppChains alloc] initWithToken:@"<yourAccessToken>" withHostName:@"api.sequencing.com"];
[appChains getReportWithApplicationMethodName:@"<chain id>"
        withDatasourceId:@"<file id>"
        withSuccessBlock:^(Report *result) {
            for (Result *obj in [result getResults]) {
                ResultValue *frv = [obj getValue];
                if ([frv getType] == kResultTypeText) {
                    NSLog(@"\nvalue %@ = %@\n", [obj getName], [(TextResultValue *)frv getData]);
                }
            }
        }
        withFailureBlock:^(NSError *error) {
            NSLog(@"Error occured: %@", [error description]);
        }];

Batch App Chain retrieval example

AppChains *appChains = [[AppChains alloc] initWithToken:yourAccessToken withHostName:@"api.sequencing.com"];
    
// parameters array for batch request as example
NSArray *appChainsForRequest = @[
        @[@"<chain id>", @"<file id>"], 
        @[@"<chain id>", @"<file id>"]
        ];
    
[appChains getBatchReportWithApplicationMethodName:appChainsForRequest
        withSuccessBlock:^(NSArray *reportResultsArray) {
            
            // @reportResultsArray - result of reports (Report object) for batch request, it's an array of dictionaries
            // each dictionary has following keys: "appChainID": appChainID string, "report": *Report object
            
            for (NSDictionary *appChainReportDict in reportResultsArray) {
                
                Report *result = [appChainReportDict objectForKey:@"report"];
                NSString *appChainID = [appChainReportDict objectForKey:@"appChainID"];
                
                NSLog(@"\n\n appChainID: %@\n", appChainID);
                
                for (Result *obj in [result getResults]) {
                    ResultValue *frv = [obj getValue];
                    if ([frv getType] == kResultTypeText) {
                        NSLog(@"\nvalue %@ = %@\n", [obj getName], [(TextResultValue *)frv getData]);
                    }
                }
            }
        }
        withFailureBlock:^(NSError *error) {
            NSLog(@"batch request error: %@", error);
        }];