grim/purple-spasm

Parents 20d0ebf41d4b
Children 9f3edb85a08c
Almost working login stuff. The saved token doesn't seem to work though, not sure why yet
  • +1 -0
    Makefile
  • +122 -1
    spasm-account.c
  • +11 -0
    spasm-account.h
  • +1 -0
    spasm-const.h
  • +61 -0
    spasm-rest.c
  • +27 -0
    spasm.h
  • --- a/Makefile Thu May 11 20:46:20 2017 -0500
    +++ b/Makefile Fri May 12 00:58:27 2017 -0500
    @@ -14,6 +14,7 @@
    spasm-user.c
    PLUGIN_HEADERS := \
    + spasm.h \
    spasm-account.h \
    spasm-auth.h \
    spasm-const.h \
    --- a/spasm-account.c Thu May 11 20:46:20 2017 -0500
    +++ b/spasm-account.c Fri May 12 00:58:27 2017 -0500
    @@ -19,6 +19,7 @@
    #include "debug.h"
    +#include "spasm.h"
    #include "spasm-account.h"
    struct _PurpleSpasmAccount {
    @@ -26,7 +27,19 @@
    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;
    };
    /******************************************************************************
    @@ -104,7 +117,115 @@
    GError *
    purple_spasm_account_update_profile(PurpleSpasmAccount *sa, JsonParser *parser) {
    - purple_debug_info("spasm", "Updating profile");
    + 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;
    +}
    --- a/spasm-account.h Thu May 11 20:46:20 2017 -0500
    +++ b/spasm-account.h Fri May 12 00:58:27 2017 -0500
    @@ -48,6 +48,17 @@
    GError *purple_spasm_account_update_profile(PurpleSpasmAccount *sa, JsonParser *parser);
    +const gchar *purple_spasm_account_get_display_name(const PurpleSpasmAccount *sa);
    +const gchar *purple_spasm_account_get_id(const PurpleSpasmAccount *sa);
    +const gchar *purple_spasm_account_get_name(const PurpleSpasmAccount *sa);
    +const gchar *purple_spasm_account_get_type(const PurpleSpasmAccount *sa);
    +const gchar *purple_spasm_account_get_bio(const PurpleSpasmAccount *sa);
    +const gchar *purple_spasm_account_get_logo(const PurpleSpasmAccount *sa);
    +const gchar *purple_spasm_account_get_email(const PurpleSpasmAccount *sa);
    +gboolean purple_spasm_account_get_email_verified(const PurpleSpasmAccount *sa);
    +gboolean purple_spasm_account_get_partnered(const PurpleSpasmAccount *sa);
    +gboolean purple_spasm_account_get_twitter_connected(const PurpleSpasmAccount *sa);
    +
    G_END_DECLS
    #endif /* PURPLE_SPASM_ACCOUNT_H */
    --- a/spasm-const.h Thu May 11 20:46:20 2017 -0500
    +++ b/spasm-const.h Fri May 12 00:58:27 2017 -0500
    @@ -22,6 +22,7 @@
    #define PURPLE_SPASM_PLUGIN_ID "prpl-grim-spasm"
    #define PURPLE_SPASM_BASE_URL "https://api.twitch.tv/kraken/"
    +#define PURPLE_SPASM_WEBSOCKET_URL "wss://pubsub-edge.twitch.tv"
    #define PURPLE_SPASM_CONTENT_TYPE "application/vnd.twitchtv.v5+json"
    #define PURPLE_SPASM_OAUTH2_CLIENT_ID "w7le4wyxwbipv6kf5qmqogwkqskl12"
    #define PURPLE_SPASM_OAUTH2_SCOPES "user_read chat_login"
    --- a/spasm-rest.c Thu May 11 20:46:20 2017 -0500
    +++ b/spasm-rest.c Fri May 12 00:58:27 2017 -0500
    @@ -19,6 +19,9 @@
    #include <libsoup/soup.h>
    +#include "debug.h"
    +
    +#include "spasm.h"
    #include "spasm-const.h"
    #include "spasm-rest.h"
    @@ -41,6 +44,8 @@
    GInputStream *istream = NULL;
    GError *error = NULL;
    JsonParser *parser = NULL;
    + JsonNode *root = NULL;
    + JsonObject *json_obj = NULL;
    PurpleSpasmRestCallbackData *cb_data = (PurpleSpasmRestCallbackData *)data;
    istream = soup_session_send_finish(SOUP_SESSION(obj), res, &error);
    @@ -58,11 +63,67 @@
    cb_data->cb(cb_data->sa, NULL, error, cb_data->data);
    g_free(cb_data);
    + g_object_unref(G_OBJECT(parser));
    +
    + return;
    + }
    +
    + root = json_parser_get_root(parser);
    + if(root == NULL || !JSON_NODE_HOLDS_OBJECT(root)) {
    + error = g_error_new(
    + PURPLE_SPASM_DOMAIN,
    + 0,
    + "invalid json response"
    + );
    +
    + cb_data->cb(cb_data->sa, NULL, error, cb_data->data);
    +
    + g_error_free(error);
    + g_free(cb_data);
    + g_object_unref(G_OBJECT(parser));
    +
    + return;
    + }
    +
    + json_obj = json_node_get_object(root);
    + if(json_obj == NULL) {
    + error = g_error_new(
    + PURPLE_SPASM_DOMAIN,
    + 0,
    + "json is not an object"
    + );
    +
    + cb_data->cb(cb_data->sa, NULL, error, cb_data->data);
    +
    + g_error_free(error);
    + g_free(cb_data);
    + g_object_unref(G_OBJECT(parser));
    +
    + return;
    + }
    +
    + if(json_object_has_member(json_obj, "error")) {
    + purple_debug_info("spasm", "error: %s\n", json_object_get_string_member(json_obj, "error"));
    + error = g_error_new(
    + PURPLE_SPASM_DOMAIN,
    + 0,
    + "error : %s : %" G_GINT64_FORMAT,
    + json_object_get_string_member(json_obj, "message"),
    + json_object_get_int_member(json_obj, "status")
    + );
    +
    + cb_data->cb(cb_data->sa, NULL, error, cb_data->data);
    +
    + g_error_free(error);
    + g_free(cb_data);
    + g_object_unref(G_OBJECT(parser));
    return;
    }
    cb_data->cb(cb_data->sa, parser, NULL, cb_data->data);
    +
    + g_object_unref(G_OBJECT(parser));
    }
    /******************************************************************************
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/spasm.h Fri May 12 00:58:27 2017 -0500
    @@ -0,0 +1,27 @@
    +/*
    + * 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.
    + */
    +
    +#ifndef PURPLE_SPASM_H
    +#define PURPLE_SPASM_H
    +
    +#include <glib.h>
    +
    +#define PURPLE_SPASM_DOMAIN (g_quark_from_static_string("purple-spasm"))
    +
    +#endif /* PURPLE_SPASM_H */
    \ No newline at end of file