MetricManagerAdvancedCAPI.c

A more advanced metric that updates the history of a metric. Usually this would be a metric from an external data source, e.g. e-mail or Facebook messages.

    #include<libusermetricsinput/usermetricsinput.h>

    intmain(intargc,char*argv[]){
    //Westartwithamanagerobject.
    //Thiscanbeusedasalong-livedobjecttoreduceDBustraffic.
    UserMetricsInputMetricManagermetricManager=
    usermetricsinput_metricmanager_new();

    //Createaparametersobject
    UserMetricsInputMetricParametersparameters=
    usermetricsinput_metricparameters_new("twitter");

    //Setitsattributes
    usermetricsinput_metricparameters_set_format_string(parameters,
    "<b>%1</b>tweetsreceivedtoday");
    usermetricsinput_metricparameters_set_empty_data_string(parameters,
    "Notweetstoday");
    usermetricsinput_metricparameters_set_text_domain(parameters,
    "myapptextdomain");

    //Youcanholdontothissharedobjectforaslongasyouwant.
    //Itwillbedestroyedwhenthemanagerisdestroyed.
    UserMetricsInputMetricmetric=usermetricsinput_metricmanager_add(
    metricManager,parameters);

    //Remembertofreetheparametersobjectafteruse
    usermetricsinput_metricparameters_delete(parameters);

    //Theupdateissentwhentheupdateobjectisdestroyed.
    //Providingablankusernamestringwillusethecurrent
    //useraccordingtotheUSERenvironmentvariable.
    UserMetricsInputMetricUpdatemetricUpdate=usermetricsinput_metric_update(
    metric,"username");

    //Thedataisorderedstartingfromtoday,goingbackwardsintime
    usermetricsinput_metricupdate_add_data(metricUpdate,1.0);
    usermetricsinput_metricupdate_add_data(metricUpdate,0.1);
    usermetricsinput_metricupdate_add_data(metricUpdate,-5.0);

    //Deleteanddispatchthemetriupdate
    usermetricsinput_metricupdate_delete(metricUpdate);

    //Freethemanagerwhendonewithit
    usermetricsinput_metricmanager_delete(metricManager);

    return0;
    }