void ofApp::newDocument( int session_id, ofxJSONElement& json ) { if ( json.isMember("type") ) { string type = json[ "type" ].asString(); //openTableDocument* document = m_current_session->getCurrentDocument(); if ( type == "image" ) { openTableImageCollection* collection = ( openTableImageCollection* ) m_current_session->getDocument( 0 ); openTableImageGroup* group = new openTableImageGroup; group->setup(json); if ( group->nImages() > 0 ) { ofVec2f p = m_server.getSessionPosition(session_id); if (p.y < ofGetHeight() / 2) { p.y += 120.f; } else { p.y -= 120.f; } group->setPosition(p); collection->addGroup(group); } else { delete group; } m_db.save(); } else if ( type == "text" ) { openTableBusinessModelCanvas* bmc = ( openTableBusinessModelCanvas* ) m_current_session->getDocument( 1 ); bmc->updateElement(json); m_db.save(); } else if( type == "session" ) { m_current_session->unlock(); if ( json.isMember("sessions") ) { m_db.markAllDocumentsOfTypeForDelete( "session" ); for ( int i = 0; i < json[ "sessions"].size(); i++ ) { string id = json[ "sessions"][ i ].isMember( "id" ) ? json[ "sessions"][ i ][ "id" ].asString() : ""; string title = json[ "sessions"][ i ][ "session_title" ].asString(); bool active = json[ "sessions"][ i ][ "session_active" ].asBool(); openTableSession* session; if ( id.length() > 0 ) { session = ( openTableSession* )m_db.get(id); // // update existing // session->setSessionTitle( title ); m_db.clearPendingDelete(id); } else { // // create new // session = ( openTableSession* )m_db.add( "session" ); session->setSessionTitle(title); } if ( active ) m_current_session = session; } m_db.commitPendingDeletes(); m_db.save(); } } } }
//-------------------------------------------------------------- void ofxTwitter::parseResponse(ofxJSONElement result) { if(result.isMember("statuses")) { data.clear(); ofxJSONElement trends = result["statuses"]; for(int i = 0; i < trends.size(); i++) { ofxTwitterTweet tweet; tweet.id_str = trends[i]["id_str"].asString(); tweet.created_at = trends[i]["created_at"].asString(); tweet.language = trends[i]["language"].asString(); tweet.text = trends[i]["text"].asString(); if(trends[i]["geo"] != Json::Value::null) { tweet.geo = trends[i]["geo"]["type"].asString(); tweet.coordinates.x = trends[i]["geo"]["coordinates"][0].asFloat(); tweet.coordinates.y = trends[i]["geo"]["coordinates"][1].asFloat(); } tweet.source = trends[i]["source"].asString(); tweet.retweet_count = trends[i]["retweet_count"].asInt(); tweet.truncated = trends[i]["truncated"].asBool(); ofxJSONElement author = trends[i]["user"]; tweet.user.id_str = author["id_str"].asString(); tweet.user.uri = "https://twitter.com/"+author["screen_name"].asString(); tweet.user.name = author["name"].asString(); tweet.user.screen_name = author["screen_name"].asString(); tweet.user.description = author["description"].asString(); if(author["location"].asString() != " ") { tweet.user.location = author["location"].asString(); } tweet.user.lang = author["lang"].asString(); tweet.user.url = author["url"].asString(); tweet.user.default_profile = author["default_profile"].asBool(); tweet.user.default_profile_image = author["default_profile_image"].asBool(); tweet.user.geo_enabled = author["geo_enabled"].asBool(); tweet.user.profile_image_url = author["profile_image_url"].asString(); if(author["profile_image_url"] != Json::Value::null && bLoadUserProfileImageOnMemory) { ofLoadURLAsync(tweet.user.profile_image_url, "profile_"+tweet.user.id_str); } tweet.user.profile_banner_url = author["profile_banner_url"].asString(); if(author["profile_banner_url"] != Json::Value::null && bLoadUserBannerImageOnMemory) { ofLoadURLAsync(tweet.user.profile_banner_url, "banner_"+tweet.user.id_str); } tweet.user.profile_background_image_url = author["profile_background_image_url"].asString(); tweet.user.profile_background_color = author["profile_background_color"].asString(); tweet.user.profile_background_tile = author["profile_background_tile"].asBool(); tweet.user.profile_use_background_image = author["profile_use_background_image"].asBool(); data.push_back( tweet ); //tweet.print(); } ofLogNotice("ofxTwitter::parseResponse") << "(" << data.size() << ") Tweets ready"; } }