grim/purple-spasm
Clone
Summary
Browse
Changes
Graph
Almost working login stuff. The saved token doesn't seem to work though, not sure why yet
2017-05-12, Gary Kramlich
9f4a141b8eee
Almost working login stuff. The saved token doesn't seem to work though, not sure why yet
/*
* 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
"debug.h"
#include
"spasm.h"
#include
"spasm-account.h"
struct
_PurpleSpasmAccount
{
PurpleAccount
*
account
;
PurpleConnection
*
connection
;
SoupSession
*
session
;
gchar
*
access_token
;
gchar
*
display_name
;
gchar
*
id
;
gchar
*
name
;
gchar
*
type
;
gchar
*
bio
;
gchar
*
logo
;
gchar
*
email
;
gboolean
email_verified
;
gboolean
partnered
;
gboolean
twitter_connected
;
};
/******************************************************************************
* API
*****************************************************************************/
PurpleSpasmAccount
*
purple_spasm_account_new
(
PurpleAccount
*
account
,
PurpleConnection
*
connection
)
{
PurpleSpasmAccount
*
sa
=
NULL
;
sa
=
g_new0
(
PurpleSpasmAccount
,
1
);
sa
->
account
=
account
;
sa
->
connection
=
connection
;
sa
->
session
=
soup_session_new
();
SoupLogger
*
logger
=
soup_logger_new
(
SOUP_LOGGER_LOG_BODY
,
-1
);
soup_session_add_feature
(
sa
->
session
,
SOUP_SESSION_FEATURE
(
logger
));
return
sa
;
}
void
purple_spasm_account_free
(
PurpleSpasmAccount
*
sa
)
{
g_return_if_fail
(
sa
);
g_free
(
sa
->
access_token
);
g_object_unref
(
G_OBJECT
(
sa
->
session
));
g_free
(
sa
);
}
PurpleAccount
*
purple_spasm_account_get_account
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
account
;
}
PurpleConnection
*
purple_spasm_account_get_connection
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
connection
;
}
SoupSession
*
purple_spasm_account_get_session
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
if
(
sa
->
session
)
{
return
g_object_ref
(
G_OBJECT
(
sa
->
session
));
}
return
NULL
;
}
void
purple_spasm_account_set_access_token
(
PurpleSpasmAccount
*
sa
,
const
gchar
*
access_token
)
{
g_return_if_fail
(
sa
);
sa
->
access_token
=
g_strdup
(
access_token
);
}
const
gchar
*
purple_spasm_account_get_access_token
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
access_token
;
}
GError
*
purple_spasm_account_update_profile
(
PurpleSpasmAccount
*
sa
,
JsonParser
*
parser
)
{
JsonNode
*
root
=
NULL
;
JsonObject
*
obj
=
NULL
;
const
gchar
*
str_attr
=
NULL
;
if
(
sa
==
NULL
)
{
return
g_error_new
(
PURPLE_SPASM_DOMAIN
,
0
,
"invalid spasm account"
);
}
root
=
json_parser_get_root
(
parser
);
obj
=
json_node_get_object
(
root
);
str_attr
=
json_object_get_string_member
(
obj
,
"display_name"
);
sa
->
display_name
=
g_strdup
(
str_attr
);
str_attr
=
json_object_get_string_member
(
obj
,
"_id"
);
sa
->
id
=
g_strdup
(
str_attr
);
str_attr
=
json_object_get_string_member
(
obj
,
"name"
);
sa
->
name
=
g_strdup
(
str_attr
);
str_attr
=
json_object_get_string_member
(
obj
,
"type"
);
sa
->
type
=
g_strdup
(
str_attr
);
str_attr
=
json_object_get_string_member
(
obj
,
"bio"
);
sa
->
bio
=
g_strdup
(
str_attr
);
str_attr
=
json_object_get_string_member
(
obj
,
"logo"
);
sa
->
logo
=
g_strdup
(
str_attr
);
str_attr
=
json_object_get_string_member
(
obj
,
"email"
);
sa
->
email
=
g_strdup
(
str_attr
);
sa
->
email_verified
=
json_object_get_boolean_member
(
obj
,
"email_verified"
);
sa
->
partnered
=
json_object_get_boolean_member
(
obj
,
"partnered"
);
sa
->
twitter_connected
=
json_object_get_boolean_member
(
obj
,
"twitter_connected"
);
return
NULL
;
}
const
gchar
*
purple_spasm_account_get_display_name
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
display_name
;
}
const
gchar
*
purple_spasm_account_get_id
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
id
;
}
const
gchar
*
purple_spasm_account_get_name
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
name
;
}
const
gchar
*
purple_spasm_account_get_type
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
type
;
}
const
gchar
*
purple_spasm_account_get_bio
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
bio
;
}
const
gchar
*
purple_spasm_account_get_logo
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
logo
;
}
const
gchar
*
purple_spasm_account_get_email
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
NULL
);
return
sa
->
email
;
}
gboolean
purple_spasm_account_get_email_verified
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
FALSE
);
return
sa
->
email_verified
;
}
gboolean
purple_spasm_account_get_partnered
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
FALSE
);
return
sa
->
partnered
;
}
gboolean
purple_spasm_account_get_twitter_connected
(
const
PurpleSpasmAccount
*
sa
)
{
g_return_val_if_fail
(
sa
,
FALSE
);
return
sa
->
twitter_connected
;
}