This web page is under construction.

Authentication
Find out how many teams I am part of
Get team project list
Get project details
Get project topology
Get project disciplines
Upload project thumbnail
Create an issue in the project
Get the issue list from the project
Delete all the issues from the project
Create a new pin for the issue
Get all the pins of the issue
Create/Upload a new attachment for the issue
Get the attachment list from the issue

Authentication

CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];

    // building the json object
    if (([emailString length] != 0) && ([passwordString length] != 0))
    {

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        NSString *requestURLString = [NSString stringWithFormat:@"%@authorize",[CSS getDefaultAPIURL]];
        [request setURL:[NSURL URLWithString:requestURLString]];
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

        NSString *requestBodyString = [NSString stringWithFormat:@"{\"user_id\": \"%@\", \"password\": \"%@\", \"client_id\": \"%@\"}",emailString,passwordString,[[NSUserDefaults standardUserDefaults] objectForKey:@"ClientIdentificationForAuthorizationPurposes"]];
        [request setHTTPBody:[requestBodyString dataUsingEncoding:NSUTF8StringEncoding]];
        [request setTimeoutInterval:60];

        __block BOOL loginFailed = NO;

        __block BOOL invalidUser = NO;

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void){

            //build an info object and convert to json
            NSError *requestError;
            NSHTTPURLResponse *responseHTTP;

            NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseHTTP error:&requestError];

            if ([responseHTTP statusCode] == 200)
            {
                NSDictionary *tempdict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:&requestError];
                [CSS setUpAuthenticationForType:[tempdict valueForKey:@"token_type"] withID:[tempdict valueForKey:@"access_token"]];

                // authorization was successfull

            } else {

                loginFailed = YES;

                if (requestError.code == -1012) {

                    // Failed because it's an invalid user

                    invalidUser = YES;

                } else {

                    // check if project list stored on device.
                    // if yes, start offline mode
                }
            }
        });

    }


Find out how many teams I am part of

CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];

    //build an info object and convert to json
    NSError *requestError;
    NSHTTPURLResponse *responseHTTP;

    NSMutableURLRequest *requestForSlug = [[NSMutableURLRequest alloc] init];

    NSString *teamRequestString = [NSString stringWithFormat:@"%@teams",[CSS getDefaultAPIURL]];
    [requestForSlug setURL:[NSURL URLWithString:teamRequestString]];
    [requestForSlug setHTTPMethod:@"GET"];
    [requestForSlug setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [requestForSlug setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];

    NSData *responseForSlug = [NSURLConnection sendSynchronousRequest:requestForSlug returningResponse:&responseHTTP error:&requestError];
    [requestForSlug release];

    if ([responseHTTP statusCode] == 200) {
        // Success. Team names array.
        NSArray *tempdictForSlug = [NSJSONSerialization JSONObjectWithData:responseForSlug options:NSJSONReadingMutableContainers error:&requestError];
        NSLog(@"How many teams I am part of: %d", [tempdictForSlug count]);
    }else{
        // Login Failed.
    }


Get team project list

CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];

    //build an info object and convert to json
    NSError *requestError;
    NSHTTPURLResponse *responseHTTP;

    //get projectList
    NSMutableURLRequest *requestForProjectList = [[NSMutableURLRequest alloc] init];

    NSString *projectListRequestString = [NSString stringWithFormat:@"%@%@/projects",[CSS getDefaultAPIURL],[CSS getSlug]];
    [requestForProjectList setURL:[NSURL URLWithString:projectListRequestString]];
    [requestForProjectList setHTTPMethod:@"GET"];
    [requestForProjectList setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [requestForProjectList setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];

    NSData *responseForProjectList = [NSURLConnection sendSynchronousRequest:requestForProjectList returningResponse:&responseHTTP error:&requestError];

    [requestForProjectList release];

    if (responseForProjectList == NULL) {

            // Login Failed
    }
    else {

        NSError *error;
        NSArray *projectList = [NSJSONSerialization JSONObjectWithData:responseForProjectList options:NSJSONReadingMutableContainers error:&error];

        BOOL success = [[ProjectManager sharedProjectManager] loadProjectsFromData:projectList];

        if (!success){

            // Failed to Load Projects List

        }
    }


Get project details

//build an info object and convert to json
        NSError *requestError;
        NSHTTPURLResponse *responseHTTP;
        NSError *dictError;

        //Get project details

        NSMutableURLRequest *requestForProjectDetails;
        requestForProjectDetails = [[NSMutableURLRequest alloc] init];

        [requestForProjectDetails setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@/projects/%@",[CSS getDefaultAPIURL],[CSS getSlug],proj.mID]]];
        [requestForProjectDetails setHTTPMethod:@"GET"];
        [requestForProjectDetails setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [requestForProjectDetails setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];

        NSData *responseForProjectDetails = [NSURLConnection sendSynchronousRequest:requestForProjectDetails returningResponse:&responseHTTP error:&requestError];
        [requestForProjectDetails release];

        if (responseHTTP.statusCode == 200) {

            // Success, we have a project detail dictionary
            NSDictionary *projectDetails = [NSJSONSerialization JSONObjectWithData:responseForProjectDetails options:NULL error:&dictError];

            // Time to process this project details as you want/need
            [proj processProjectDetails:projectDetails];

        }else{
            // Download Failed
            return;
        }


Get project topology

//build an info object and convert to json
        NSError *requestError;
        NSHTTPURLResponse *responseHTTP;

        NSString* requestString = [[NSString alloc] initWithFormat:@"%@%@/projects/%@/topology",[CSS getDefaultAPIURL],[CSS getSlug], mProjectID];

        NSMutableURLRequest *requestForProjectsTree = [[NSMutableURLRequest alloc] init];
        [requestForProjectsTree setURL:[NSURL URLWithString:requestString]];
        [requestString release];

        [requestForProjectsTree setHTTPMethod:@"GET"];
        [requestForProjectsTree setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [requestForProjectsTree setValue:[[CommunicationSingleton sharedSingleton] getAuthorization] forHTTPHeaderField:@"Authorization"];

        NSData *response = [NSURLConnection sendSynchronousRequest:requestForProjectsTree returningResponse:&responseHTTP error:&requestError];
        [requestForProjectsTree release];

        NSString *path = [[proj getProjectFolderPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.topology", mProjectID]];

        if ([responseHTTP statusCode] == 200)
        {
            // Save project topology locally.
            [response writeToFile:path atomically:NO];

            // Load project topology to memory.
            [proj loadTopologyFromData:response];

        } else {

            // If Failed

            // Check if we have the last used topology for this project is available offline (rembember that this is could not be the last version)
            if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                // Loading project topology offline

                NSData* data = [NSData dataWithContentsOfFile:path];
                [proj loadTopologyFromData:data];

            } else {
                // Download Failed + Local Storage not available
            }

        }


Get project disciplines

    Project* proj = [[ProjectManager sharedProjectManager] getProjectbyID:mProjectID];
    
    maxNodes = [[proj getAllNodesWithoutParents] count];
    
    // Don't download nodes data if we want to download them dynamically
    // we are still going to need the parents
    if ( ![[[NSUserDefaults standardUserDefaults] valueForKey:kDownloadNodesDynamically] boolValue] ) {
        
        dispatch_async(dispatch_get_main_queue(), ^(void){

            mDownloadManager = [[DownloadManager alloc] init];
            mDownloadManager.delegate = self;
            
            //get disciplines
            NSArray *disciplineIds = proj.projectsDisciplineIDs;
            for (int i = 0; i < [disciplineIds count]; i++) {
                [mDownloadManager downloadFiles:[proj getAllNodesWithoutParents] forProject:mProjectID forDiscipline:[disciplineIds objectAtIndex:i]];
            }
            
            if ([disciplineIds count] < 1) {
                [mDownloadManager downloadFiles:[proj getAllNodesWithoutParents] forProject:mProjectID forDiscipline:NULL];
            }
            
        });
    }

In "downloadFiles" method there are some logic and data storage operations and for each of the discipline you can call this snippet:


	NodeHeaderDatas *nodeDatas = [mFilesToProcess objectAtIndex:0];
	NSString *nodeidForAPICall = nodeDatas.nodeID;
    
	CommunicationSingleton *CSS = [CommunicationSingleton sharedSingleton];
	NSMutableURLRequest *requestForNodeData = [[NSMutableURLRequest alloc] init];
	NSString *nodesURL;
        if (nodeDatas.disciplineForDownloading != NULL) {
            nodesURL = [NSString stringWithFormat:
                        @"%@%@/objects/%@/disciplines/%@/geometries/threejs",
                        [CSS getDefaultAPIURL],
                        [CSS getSlug],
                        nodeidForAPICall,
                        nodeDatas.disciplineForDownloading];
        }else{
            nodesURL = [NSString stringWithFormat:
                        @"%@%@/objects/%@/geometries/threejs",
                        [CSS getDefaultAPIURL],
                        [CSS getSlug],
                        nodeidForAPICall];
            
        }
        [requestForNodeData setURL:[NSURL URLWithString:nodesURL]];
        [requestForNodeData setHTTPMethod:@"GET"];
        [requestForNodeData setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [requestForNodeData setValue:[CSS getAuthorization] forHTTPHeaderField:@"Authorization"];
        
        if(requestForNodeData){
            mConnection = [[NSURLConnection alloc] initWithRequest:requestForNodeData delegate:self startImmediately:YES];
        }
if (!mConnection)
        {
            // Connection Failed
        }
        else
        {
            [mConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
            [mConnection start];
        }
        [requestForNodeData release];