@@ 135,19 135,19 @@ harvest_request_class_init(HarvestRequestClass *klass)
obj_properties[PROP_HTTP_METHOD] = g_param_spec_enum("http-method", _("HTTP Method"),
_("The HTTP method by which to send the request."), HTTP_TYPE_METHOD, HTTP_METHOD_GET,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ENDPOINT] = g_param_spec_string("endpoint", _("Endpoint"),
_("The server endpoint to send the request to."), NULL,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_QUERY_PARAMS] = g_param_spec_string("query-params", _("Query Params"),
_("The query params to send the request with."), NULL,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_DATA]
= g_param_spec_object("data", _("Data"), _("The data to send in the body of the request."),
- G_TYPE_OBJECT, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ G_TYPE_OBJECT, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_RESPONSE_METADATA] = g_param_spec_object("response-metadata", _("Response"),
_("An object containing meta information of the response."), HARVEST_TYPE_RESPONSE_METADATA,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties(obj_class, N_PROPS, obj_properties);
}
@@ 11,35 11,19 @@
struct _HarvestLATERequest
{
- HarvestRequest parent_instance;
+ GObject parent_instance;
- int user_id;
- int client_id;
- int project_id;
- gboolean is_billed : 1;
- gboolean is_running : 1;
+ GVariant *user_id; // int
+ GVariant *client_id; // int
+ GVariant *project_id; // int
+ GVariant *is_billed; // gboolean
+ GVariant *is_running; // gboolean
GDateTime *updated_since;
GDateTime *from;
GDateTime *to;
- unsigned int page;
- unsigned int per_page;
};
-typedef struct _HarvestLATERequestPrivate
-{
- gboolean user_id : 1;
- gboolean client_id : 1;
- gboolean project_id : 1;
- gboolean is_billed : 1;
- gboolean is_running : 1;
- gboolean updated_since : 1;
- gboolean from : 1;
- gboolean to : 1;
- gboolean page : 1;
- gboolean per_page : 1;
-} HarvestLATERequestPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE(HarvestLATERequest, harvest_late_request, HARVEST_TYPE_REQUEST)
+G_DEFINE_TYPE(HarvestLATERequest, harvest_late_request, HARVEST_TYPE_REQUEST)
enum HarvestLATERequest
{
@@ 47,13 31,11 @@ enum HarvestLATERequest
PROP_USER_ID,
PROP_CLIENT_ID,
PROP_PROJECT_ID,
- PROPIS_BILLED,
+ PROP_IS_BILLED,
PROP_IS_RUNNING,
PROP_UPDATED_SINCE,
PROP_FROM,
PROP_TO,
- PROP_PAGE,
- PROP_PER_PAGE,
N_PROPS,
};
@@ 64,6 46,16 @@ harvest_late_request_finalize(GObject *obj)
{
HarvestLATERequest *self = HARVEST_LATE_REQUEST(obj);
+ if (self->user_id != NULL)
+ g_variant_unref(self->user_id);
+ if (self->client_id != NULL)
+ g_variant_unref(self->client_id);
+ if (self->project_id != NULL)
+ g_variant_unref(self->project_id);
+ if (self->is_billed != NULL)
+ g_variant_unref(self->is_billed);
+ if (self->is_running != NULL)
+ g_variant_unref(self->is_running);
if (self->from != NULL)
g_date_time_unref(self->from);
if (self->to != NULL)
@@ 77,16 69,14 @@ harvest_late_request_finalize(GObject *obj)
static const char *G_GNUC_CONST G_GNUC_WARN_UNUSED_RESULT
harvest_late_request_serialize_params(HarvestLATERequest *self)
{
- HarvestLATERequestPrivate *priv = harvest_late_request_get_instance_private(self);
-
g_autoptr(GString) string = g_string_new(NULL);
- if (priv->user_id)
- g_string_append_printf(string, "&user_id=%d", self->user_id);
- if (priv->client_id)
- g_string_append_printf(string, "&client_id=%d", self->client_id);
+ if (self->user_id != NULL)
+ g_string_append_printf(string, "&user_id=%d", g_variant_get_int32(self->user_id));
+ if (self->client_id != NULL)
+ g_string_append_printf(string, "&client_id=%d", g_variant_get_int32(self->client_id));
- return g_strdup_printf(string->str);
+ return g_strdup(string->str);
}
static void
@@ 96,11 86,17 @@ harvest_late_request_get_property(GObject *obj, guint prop_id, GValue *val, GPar
switch (prop_id) {
case PROP_USER_ID:
- g_value_set_int(val, self->user_id);
+ g_value_set_variant(val, self->user_id);
break;
case PROP_CLIENT_ID:
- g_value_set_int(val, self->client_id);
+ g_value_set_variant(val, self->client_id);
break;
+ case PROP_PROJECT_ID:
+ case PROP_IS_BILLED:
+ case PROP_IS_RUNNING:
+ case PROP_UPDATED_SINCE:
+ case PROP_FROM:
+ case PROP_TO:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
}
@@ 109,18 105,21 @@ harvest_late_request_get_property(GObject *obj, guint prop_id, GValue *val, GPar
static void
harvest_late_request_set_property(GObject *obj, guint prop_id, const GValue *val, GParamSpec *pspec)
{
- HarvestLATERequest *self = HARVEST_LATE_REQUEST(obj);
- HarvestLATERequestPrivate *priv = harvest_late_request_get_instance_private(self);
+ HarvestLATERequest *self = HARVEST_LATE_REQUEST(obj);
switch (prop_id) {
case PROP_USER_ID:
- priv->user_id = TRUE;
- self->user_id = g_value_get_int(val);
+ self->user_id = g_value_dup_variant(val);
break;
case PROP_CLIENT_ID:
- priv->client_id = TRUE;
- self->client_id = g_value_get_int(val);
+ self->client_id = g_value_dup_variant(val);
break;
+ case PROP_PROJECT_ID:
+ case PROP_IS_BILLED:
+ case PROP_IS_RUNNING:
+ case PROP_UPDATED_SINCE:
+ case PROP_FROM:
+ case PROP_TO:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
}
@@ 136,10 135,10 @@ harvest_late_request_class_init(HarvestLATERequestClass *klass)
obj_class->set_property = harvest_late_request_set_property;
// TODO: Finish implemeting this
- obj_properties[PROP_USER_ID] = g_param_spec_int("user_id", _("User ID"), _(""), 0, INT_MAX, 0,
- G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- obj_properties[PROP_CLIENT_ID] = g_param_spec_int("client_id", _("Client ID"), _(""), 0,
- INT_MAX, 0, G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_USER_ID] = g_param_spec_variant("user-id", _("User ID"), _(""),
+ G_VARIANT_TYPE_INT32, NULL, G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_CLIENT_ID] = g_param_spec_variant("client-id", _("Client ID"), _(""),
+ G_VARIANT_TYPE_INT32, NULL, G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties(obj_class, 3, obj_properties);
}
@@ 151,24 150,26 @@ harvest_late_request_init(G_GNUC_UNUSED HarvestLATERequest *self)
HarvestLATERequest *
harvest_late_request_new(const char *first_prop_name, ...)
{
- va_list var_args;
+ HarvestLATERequest *req = NULL;
// Short-circuit for calls supplying no properties
if (first_prop_name == NULL) {
- return HARVEST_LATE_REQUEST(
+ req = HARVEST_LATE_REQUEST(
g_object_new_with_properties(HARVEST_TYPE_LATE_REQUEST, 0, NULL, NULL));
+ } else {
+ va_list var_args;
+ va_start(var_args, first_prop_name);
+ req = HARVEST_LATE_REQUEST(
+ g_object_new_valist(HARVEST_TYPE_LATE_REQUEST, first_prop_name, var_args));
+ va_end(var_args);
}
- va_start(var_args, first_prop_name);
- HarvestLATERequest *self = HARVEST_LATE_REQUEST(
- g_object_new_valist(HARVEST_TYPE_LATE_REQUEST, first_prop_name, var_args));
- va_end(var_args);
-
- g_autofree char *endpoint = g_strdup("/time_entries");
g_autoptr(HarvestResponseMetadata) response_metadata
= harvest_response_metadata_new(G_TYPE_NONE, HTTP_STATUS_OK);
- g_object_set(self, "http-method", HTTP_METHOD_GET, "endpoint", endpoint, "query-params",
- harvest_late_request_serialize_params(self), "response-metadata", response_metadata, NULL);
- return self;
+ g_object_set(req, "http-method", HTTP_METHOD_GET, "endpoint", "/time_entries",
+ "response-metadata", response_metadata, "query-params",
+ harvest_late_request_serialize_params(req), NULL);
+
+ return req;
}