Esempio n. 1
0
json::object response_base::build_response( const json::string& session_id, const json::array& response, const json::array& updates ) const
{
    json::object result;
    result.add( id_token, session_id );

    if ( !response.empty() )
        result.add( response_token, response );

    if ( !updates.empty() )
        result.add( update_token, updates );

    return result;
}
Esempio n. 2
0
	void response_base< Timer >::handle_connect( const json::object& request,
	    const boost::shared_ptr< response_interface >& self, bool last_message )
	{
	    assert( session_ );

	    if ( !check_connection_type( request, session_->session_id() ) )
	        return;

	    // when there are already messages to be send, then there is no point in blocking
	    const bool do_not_block = !bayeux_response_.empty() || !last_message || zero_timeout_advice( request );
	    const json::array messages = do_not_block ? session_->events() : session_->wait_for_events( self );

	    if ( !messages.empty() )
		{
	        bayeux_response_ += messages;
			bayeux_response_.add( build_connect_response( request, session_->session_id() ) );
		}
		else
		{
		    if ( do_not_block )
		    {
                bayeux_response_.add( build_connect_response( request, session_->session_id() ) );
		    }
		    else
		    {
                blocking_connect_ = request;
		    }
		}
	}
Esempio n. 3
0
Json RiotService::GetMatchFeedByIds::internalCall() {
    Json summoners = _service->_api.getSummonerByIds(_params["ids"]);
    Json::object diff;
    Json::array matches;
    std::string err;
    auto cmp = [](const Json & a, const Json & b) {
        return a["createDate"].number_value() > b["createDate"].number_value();
    };
    for (auto & kv : summoners.object_items()) {
        Json cache = _service->getSummonerInfoCache(kv.first);
        printf("cache : %s\nnew: %s", cache.dump().c_str(), kv.second.dump().c_str());
        if (cache.is_null() || cache["revisionDate"].number_value() < kv.second["revisionDate"].number_value()) {
            diff[kv.first] = kv.second;
        } else {
            matches.insert(matches.end(), cache["games"].array_items().begin(), cache["games"].array_items().end());
        }
    }
    std::sort(matches.begin(), matches.end(), cmp);
    if (!matches.empty()) {
        _onRead(matches);
    }
    for (auto & kv : diff) {
        auto future = std::async(std::launch::async, [this, kv, cmp, &matches]() {
            Json newInfo = _service->_api.getRecentGamesBySummonerId(kv.first);
            if (!newInfo.is_null()) {
                Json::array modifiedMatches;
                for (auto & match : newInfo["games"].array_items()) {
                    auto item = match.object_items();
                    item["summonerId"] = kv.first;
                    item["name"] = kv.second["name"].string_value();
                    modifiedMatches.push_back(item);
                }
                matches.insert(matches.end(), modifiedMatches.begin(), modifiedMatches.end());
                sort(matches.begin(), matches.end(), cmp);
                
                Json::object updateObject(kv.second.object_items());
                updateObject["games"] = modifiedMatches;
                _service->saveSummonerInfo(kv.first, Json(updateObject));
            }
            _onRead(matches);
        });
    }
    return Json(matches);
}