void App42StorageResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42StorageResult failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrStorages = Util::getJSONChild("storage", ptrResponse);
    if (ptrStorages)
    {
        cJSON* child = ptrStorages;
        if(child->type == cJSON_Array)
        {
            child = child->child;
        }
        
        while(child != NULL && child->type == cJSON_Object)
        {
            App42Storage app42Storage;
            app42Storage.dbName = Util::getJSONString("dbName", child);
            app42Storage.collectionName = Util::getJSONString("collectionName", child);
            app42Storage.recordCount = Util::getJSONDouble("recordCount", child);//Util::getJSONString("recordCount", child);
            
            child = child->next;
            
            if(Util::getJSONChild("jsonDoc",ptrStorages))
            {
                cJSON* ptrjsonDocs = Util::getJSONChild("jsonDoc", ptrStorages);
                cJSON* child = ptrjsonDocs;
                if(child->type == cJSON_Array)
                {
                    child = child->child;
                }
                while(child != NULL && child->type == cJSON_Object)
                {
                    JSONDocument document;
                    buildJsonDocument(child, &document);
                    
                    app42Storage.jsonDocArray.push_back(document);
                    child = child->next;
                }
            }
            storages.push_back(app42Storage);
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}
void App42EmailResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42EmailResult failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrEmail = Util::getJSONChild("email", ptrResponse);
    if (ptrEmail)
    {
        from = Util::getJSONString("from", ptrEmail);
        to = Util::getJSONString("to", ptrEmail);
        subject = Util::getJSONString("subject", ptrEmail);
        body = Util::getJSONString("body", ptrEmail);

        cJSON* ptrConfigurations = Util::getJSONChild("configurations", ptrEmail);
        if(ptrConfigurations)
        {
            cJSON* ptrConfig = Util::getJSONChild("config", ptrConfigurations);
            if (ptrConfig)
            {
                cJSON* childConfig = ptrConfig;
                if(childConfig->type == cJSON_Array)
                {
                    childConfig = childConfig->child;
                }
                while(childConfig != NULL && childConfig->type == cJSON_Object)
                {
                    App42Configuration config;
                    
                    config.emailId = Util::getJSONString("emailId", childConfig);
                    config.host = Util::getJSONString("host", childConfig);
                    config.ssl = Util::getJSONBool("ssl", childConfig);
                    config.port = Util::getJSONInt("port", childConfig);
                    
                    configurationArray.push_back(config);
                    childConfig = childConfig->next;
                }
            }
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}
void App42UploadResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42UploadResponse failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrUpload = Util::getJSONChild("upload", ptrResponse);
    if (ptrUpload)
    {
        cJSON* ptrFiles = Util::getJSONChild("files", ptrUpload);
        if (ptrFiles)
        {
            cJSON* ptrFile = Util::getJSONChild("file", ptrFiles);
            if (ptrFile)
            {
                cJSON* child = ptrFile;
                if(child->type == cJSON_Array)
                {
                    child = child->child;
                }
                while(child != NULL && child->type == cJSON_Object)
                {
                    App42Upload app42Upload;
                    app42Upload.name = Util::getJSONString("name", child);
                    app42Upload.userName = Util::getJSONString("userName", child);
                    app42Upload.type = Util::getJSONString("type", child);
                    app42Upload.url = Util::getJSONString("url", child);
                    app42Upload.tinyUrl = Util::getJSONString("tinyUrl", child);
                    app42Upload.description = Util::getJSONString("description", child);
                    app42Upload.createdOn = Util::getJSONString("createdOn", child);
                    uploadArray.push_back(app42Upload);
                    child = child->next;
                }
            }
        }
    }
    else
    {
        setTotalRecords();
    }
    cJSON_Delete(ptrBody);
}
void App42BuddyResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42User failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrBuddies = Util::getJSONChild("buddies", ptrResponse);
    
    if (ptrBuddies)
    {
        cJSON* ptrBuddy = Util::getJSONChild("buddy", ptrBuddies);
        
        if (ptrBuddy)
        {
            cJSON* child = ptrBuddy;
            if(child->type == cJSON_Array)
            {
                child = child->child;
            }
            
            while(child != NULL && child->type == cJSON_Object)
            {
                App42Buddy app42Buddy;
                app42Buddy.userName = Util::getJSONString("userName", child);
                app42Buddy.buddyName = Util::getJSONString("buddyName", child);
                app42Buddy.groupName = Util::getJSONString("groupName", child);
                app42Buddy.ownerName = Util::getJSONString("ownerName", child);
                app42Buddy.messageId = Util::getJSONString("messageId", child);
                app42Buddy.message = Util::getJSONString("message", child);
                app42Buddy.sentOn = Util::getJSONString("sendedOn", child);
                app42Buddy.acceptedOn = Util::getJSONString("acceptedOn", child);

                cJSON *ptrPoints = Util::getJSONChild("points", child);
                if (ptrPoints != NULL)
                {
                    cJSON *ptrPoint = Util::getJSONChild("point", ptrPoints);
                    
                    if (ptrPoint != NULL)
                    {
                        //vector<JSONDocument> docArray;
                        cJSON* pointChild = ptrPoint;
                        if (pointChild->type == cJSON_Array)
                        {
                            pointChild = pointChild->child;
                        }
                        while(pointChild != NULL && pointChild->type == cJSON_Object)
                        {
                            App42GeoPoint geoPoint;
                            geoPoint.latitude = Util::getJSONDouble("latitude", pointChild);
                            geoPoint.longitude = Util::getJSONDouble("longitude", pointChild);
                            geoPoint.markerName = Util::getJSONString("markerName", pointChild);
                            geoPoint.createdOn = Util::getJSONString("createdOn", pointChild);
                            app42Buddy.pointList.push_back(geoPoint);
                            pointChild = pointChild->next;
                        }
                        //app42Score.setJsonDocList(docArray);
                    }
                    
                }
                
                buddyList.push_back(app42Buddy);
                child = child->next;
            }
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}
Exemplo n.º 5
0
void App42SocialResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42SocialResponse failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrSocial = Util::getJSONChild("social", ptrResponse);
    social.setDefaults();
    if (ptrSocial)
    {
        cJSON* child = ptrSocial;
        if(child->type == cJSON_Array)
        {
            child = child->child;
        }
        
        while(child != NULL && child->type == cJSON_Object)
        {            
            social.setUserName(Util::getJSONString("userName", child));
            social.setStatus(Util::getJSONString("status", child));
            social.setFacebookAccessToken(Util::getJSONString("facebookAccessToken", child));
            social.setFacebookAppId(Util::getJSONString("facebookAppId", child));
            printf("\n%s",Util::getJSONString("facebookAppId", child).c_str());
            social.setFacebookAppSecret(Util::getJSONString("facebookAppSecret", child));
            
            cJSON* ptrFriends = Util::getJSONChild("friends",child);
            if(ptrFriends)
            {
                cJSON* friendsJson = ptrFriends;
                if(friendsJson->type == cJSON_Array)
                {
                    friendsJson = friendsJson->child;
                }
                while(friendsJson != NULL && friendsJson->type == cJSON_Object)
                {
                    App42Friend app42Friend;
                    app42Friend.setName(Util::getJSONString("name", friendsJson));
                    app42Friend.setFriendId(Util::getJSONString("id", friendsJson));
                    app42Friend.setPicture(Util::getJSONString("picture", friendsJson));
                    app42Friend.setInstalled(Util::getJSONBool("installed", friendsJson));

                    friendsList.push_back(app42Friend);
                    friendsJson = friendsJson->next;
                }
            }
            
            cJSON* ptrMe = Util::getJSONChild("me",child);
            if(ptrMe)
            {
                
                facebookProfile.setName(Util::getJSONString("name", ptrMe));
                facebookProfile.setFbId(Util::getJSONString("id", ptrMe));
                facebookProfile.setPicture(Util::getJSONString("picture", ptrMe));
            }
            
            cJSON* ptrFacebookProfile = Util::getJSONChild("facebookProfile",child);
            if(ptrFacebookProfile)
            {
                facebookProfile.setName(Util::getJSONString("name", ptrFacebookProfile));
                facebookProfile.setFbId(Util::getJSONString("id", ptrFacebookProfile));
                facebookProfile.setPicture(Util::getJSONString("picture", ptrFacebookProfile));
            }
            
            cJSON* ptrFriendsProfile = Util::getJSONChild("profile",child);
            if(ptrFriendsProfile)
            {
                cJSON* friendsProfileJson = ptrFriendsProfile;
                if(friendsProfileJson->type == cJSON_Array)
                {
                    friendsProfileJson = friendsProfileJson->child;
                }
                while(friendsProfileJson != NULL && friendsProfileJson->type == cJSON_Object)
                {
                    App42PublicProfile app42FriendProfile;
                    app42FriendProfile.setName(Util::getJSONString("name", friendsProfileJson));
                    app42FriendProfile.setFbId(Util::getJSONString("id", friendsProfileJson));
                    app42FriendProfile.setPicture(Util::getJSONString("picture", friendsProfileJson));
                    
                    publicProfile.push_back(app42FriendProfile);
                    friendsProfileJson = friendsProfileJson->next;
                }
            }
            
            child = child->next;
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}
void App42UserResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42User failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrUsers = Util::getJSONChild("users", ptrResponse);
    if (ptrUsers)
    {
        cJSON* ptrUser = Util::getJSONChild("user", ptrUsers);
        
        if (ptrUser)
        {
            cJSON* child = ptrUser;
            if(child->type == cJSON_Array)
            {
                child = child->child;
            }
            
            while(child != NULL && child->type == cJSON_Object)
            {
                App42User app42User;
                app42User.userName = Util::getJSONString("userName", child);
                app42User.email = Util::getJSONString("email", child);
                app42User.isAccountLocked = Util::getJSONInt("accountLocked", child);
                app42User.sessionId = Util::getJSONInt("sessionId", child);
                
                cJSON* ptrUserProfile = Util::getJSONChild("profile", child);
                if (ptrUserProfile)
                {
                    app42User.profile = buildUserProfile(ptrUserProfile);
                }
                
                cJSON* ptrUserRoles = Util::getJSONChild("role", child);
                if (ptrUserRoles)
                {
                    cJSON* childRole = ptrUserRoles;

                    if (childRole->type == cJSON_Array)
                    {
                        int size = cJSON_GetArraySize(childRole);
                        for (int i=0; i<size; i++)
                        {
                            cJSON *item = cJSON_GetArrayItem(childRole, i);
                            app42User.roleList.push_back(item->valuestring);
                        }
                    }
                }
                
                users.push_back(app42User);
                child = child->next;
            }
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}
	void App42GameResponse::init()
	{
		if (_result != 200)
		{
			Util::app42Trace("App42Game failed result is %d", _result);
			buildErrorMessage();
			return;
		}
		cJSON *ptrBody = cJSON_Parse(_body.c_str());
		cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
		cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
		cJSON* ptrGames = Util::getJSONChild("games", ptrResponse);
		if (ptrGames)
		{
			cJSON* ptrGame = Util::getJSONChild("game", ptrGames);

			cJSON* child = ptrGame;
			if (child->type == cJSON_Array)
			{
				child = child->child;
			}

			while (child != NULL && child->type == cJSON_Object)
			{
				App42Game app42Game;
				app42Game.name = Util::getJSONString("name", child);
				app42Game.description = Util::getJSONString("description", child);
				games.push_back(app42Game);
				child = child->next;
				if (Util::getJSONChild("scores", ptrGame))
				{
					cJSON* ptrScores = Util::getJSONChild("scores", ptrGame);
					cJSON* ptrScore = Util::getJSONChild("score", ptrScores);
					cJSON* child = ptrScore;
					if (child->type == cJSON_Array)
					{
						child = child->child;
					}
					while (child != NULL && child->type == cJSON_Object)
					{
						App42Score app42Score;
						app42Score.setUserName(Util::getJSONString("userName", child));
						app42Score.setRank(Util::getJSONDouble("rank", child));
						app42Score.setScoreId(Util::getJSONString("scoreId", child));
						app42Score.setScoreValue(Util::getJSONDouble("value", child));
						app42Score.setCreatedOn(Util::getJSONString("createdOn", child));

						cJSON* ptrFacebookProfile = Util::getJSONChild("facebookProfile", child);
						if (ptrFacebookProfile)
						{

							app42Score.facebookProfile.setName(Util::getJSONString("name", ptrFacebookProfile));
							app42Score.facebookProfile.setFbId(Util::getJSONString("id", ptrFacebookProfile));
							app42Score.facebookProfile.setPicture(Util::getJSONString("picture", ptrFacebookProfile));
						}

						cJSON *ptrJsonDoc = Util::getJSONChild("jsonDoc", child);
						if (ptrJsonDoc != NULL)
						{
							vector<JSONDocument> docArray;
							if (ptrJsonDoc->type == cJSON_Array)
							{
								ptrJsonDoc = ptrJsonDoc->child;
							}
							while (ptrJsonDoc != NULL && ptrJsonDoc->type == cJSON_Object)
							{
								JSONDocument jsonDOC;
								buildJsonDocument(ptrJsonDoc, &jsonDOC);
								ptrJsonDoc = ptrJsonDoc->next;
								docArray.push_back(jsonDOC);
							}
							app42Score.setJsonDocList(docArray);
						}
						scores.push_back(app42Score);
						child = child->next;
					}
				}
			}
		}
		else
		{
			setTotalRecords();
		}


		cJSON_Delete(ptrBody);
	}
void App42SessionResponse::init()
{
    if(_result != 200)
    {
        Util::app42Trace("App42User failed result is %d", _result);
        buildErrorMessage();
        return;
    }
    // parse the body
    cJSON *ptrBody = cJSON_Parse(_body.c_str());
    cJSON* ptrApp42 = Util::getJSONChild("app42", ptrBody);
    cJSON* ptrResponse = Util::getJSONChild("response", ptrApp42);
    cJSON* ptrSession = Util::getJSONChild("session", ptrResponse);
    
    if (ptrSession)
    {
        cJSON* child = ptrSession;
        if(child->type == cJSON_Array)
        {
            child = child->child;
        }
        
        while(child != NULL && child->type == cJSON_Object)
        {
            app42Session.userName = Util::getJSONString("userName", child);
            app42Session.sessionId = Util::getJSONString("sessionId", child);
            app42Session.createdOn = Util::getJSONString("createdOn", child);
            app42Session.invalidatedOn = Util::getJSONString("invalidatedOn", child);
            
            cJSON* ptrAttributes = Util::getJSONChild("attributes", child);
            if (ptrAttributes)
            {
                cJSON* ptrAttribute = Util::getJSONChild("attribute", ptrAttributes);
                if (ptrAttribute)
                {
                    cJSON* attributeChild = ptrAttribute;
                    if(attributeChild->type == cJSON_Array)
                    {
                        attributeChild = attributeChild->child;
                    }
                    
                    while(attributeChild != NULL && attributeChild->type == cJSON_Object)
                    {
                        App42Attribute attribute;
                        attribute.name = Util::getJSONString("name", attributeChild);
                        attribute.value = Util::getJSONString("value", attributeChild);
                        app42Session.attributeArray.push_back(attribute);
                        attributeChild = attributeChild->next;
                    }
                }
            }

            child = child->next;
        }
    }
    else
    {
        setTotalRecords();
    }
    
    cJSON_Delete(ptrBody);
}