[libgdata/wip/rishi/drive: 1/4] core: Set parsed GDataAccessRule fields in JSON



commit c89f085e515a01ce1a67f540e4730f70888fcb9f
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Apr 27 18:57:09 2015 +0200

    core: Set parsed GDataAccessRule fields in JSON
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 gdata/gdata-access-rule.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index 25b5f23..23691f7 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -98,6 +98,7 @@ static void gdata_access_rule_get_property (GObject *object, guint property_id,
 static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError 
**error);
 static gboolean parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
 static gboolean post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error);
+static void get_json (GDataParsable *parsable, JsonBuilder *builder);
 
 struct _GDataAccessRulePrivate {
        gchar *domain;
@@ -140,6 +141,7 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
 
        parsable_class->parse_json = parse_json;
        parsable_class->post_parse_json = post_parse_json;
+       parsable_class->get_json = get_json;
 
        entry_class->kind_term = "http://schemas.google.com/acl/2007#accessRule";;
 
@@ -552,6 +554,41 @@ post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error)
        return TRUE;
 }
 
+static void
+get_json (GDataParsable *parsable, JsonBuilder *builder)
+{
+       GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
+
+       GDATA_PARSABLE_CLASS (gdata_access_rule_parent_class)->get_json (parsable, builder);
+
+       if (priv->key != NULL && priv->key[0] != '\0') {
+               json_builder_set_member_name (builder, "authKey");
+               json_builder_add_string_value (builder, priv->key);
+       }
+
+       if (priv->role != NULL && priv->role[0] != '\0') {
+               json_builder_set_member_name (builder, "role");
+               json_builder_add_string_value (builder, priv->role);
+       }
+
+       if (priv->scope_type != NULL && priv->scope_type[0] != '\0') {
+               const gchar *scope_type;
+
+               if (g_strcmp0 (priv->scope_type, GDATA_ACCESS_SCOPE_DEFAULT) == 0)
+                       scope_type = "anyone";
+               else
+                       scope_type = priv->scope_type;
+
+               json_builder_set_member_name (builder, "type");
+               json_builder_add_string_value (builder, scope_type);
+       }
+
+       if (priv->scope_value != NULL && priv->scope_value[0] != '\0') {
+               json_builder_set_member_name (builder, "value");
+               json_builder_add_string_value (builder, priv->scope_value);
+       }
+}
+
 /**
  * gdata_access_rule_new:
  * @id: the access rule's ID, or %NULL


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]