grim/purple-spasm
Clone
Summary
Browse
Changes
Graph
Initial basic support for using the rest api
2017-05-09, Gary Kramlich
255ea8d6611e
Initial basic support for using the rest api
/*
* PurpleSpasm - A Twitch Protocol Plugin
* Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include
<json-glib/json-glib.h>
#include
"debug.h"
#include
"spasm-user.h"
#include
"spasm-rest.h"
/******************************************************************************
* User endpoint
*****************************************************************************/
static
void
_purple_spasm_refresh_user_cb
(
PurpleSpasmAccount
*
sa
,
JsonParser
*
parser
,
GError
*
error
,
gpointer
data
)
{
JsonNode
*
node
=
NULL
;
if
(
error
)
{
purple_debug_info
(
"spasm"
,
"refresh user error: %s"
,
error
->
message
);
g_error_free
(
error
);
return
;
}
node
=
json_parser_get_root
(
parser
);
// now output the string to make sure it's all working
JsonGenerator
*
gen
=
json_generator_new
();
json_generator_set_root
(
gen
,
node
);
json_generator_set_pretty
(
gen
,
TRUE
);
gchar
*
json_data
=
json_generator_to_data
(
gen
,
NULL
);
purple_debug_info
(
"spasm"
,
"%s"
,
json_data
);
g_free
(
json_data
);
g_object_unref
(
G_OBJECT
(
gen
));
}
void
purple_spasm_refresh_user
(
PurpleSpasmAccount
*
sa
)
{
purple_spasm_rest_request
(
sa
,
"GET"
,
"/user"
,
NULL
,
_purple_spasm_refresh_user_cb
,
NULL
);
}