~tristan957/harvest-almanac

7bb9d430e827c8a5c2410d0873024b18f4c1394a — Tristan Partin 1 year, 9 months ago 3e4722b
harvest-glib: made use of more enums in GValus
M harvest-glib/harvest-request.c => harvest-glib/harvest-request.c +6 -5
@@ 6,6 6,7 @@
#include <glib/gi18n-lib.h>
#include <json-glib/json-glib.h>

#include "harvest-enum-types.h"
#include "harvest-http.h"
#include "harvest-request.h"
#include "harvest-response-metadata.h"


@@ 68,7 69,7 @@ harvest_request_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpe

	switch (prop_id) {
	case PROP_HTTP_METHOD:
		g_value_set_int(val, priv->http_method);
		g_value_set_enum(val, (gint) priv->http_method);
		break;
	case PROP_ENDPOINT:
		g_value_set_string(val, priv->endpoint);


@@ 95,7 96,7 @@ harvest_request_set_property(GObject *obj, guint prop_id, const GValue *val, GPa

	switch (prop_id) {
	case PROP_HTTP_METHOD:
		priv->http_method = g_value_get_int(val);
		priv->http_method = (HttpMethod) g_value_get_enum(val);
		break;
	case PROP_ENDPOINT:
		g_free(priv->endpoint);


@@ 134,9 135,9 @@ harvest_request_class_init(HarvestRequestClass *klass)
	obj_signals[SIGNAL_COMPLETED] = g_signal_new("completed", G_TYPE_FROM_CLASS(klass),
		G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, HARVEST_TYPE_RESPONSE);

	obj_properties[PROP_HTTP_METHOD]  = g_param_spec_int("http-method", _("HTTP Method"),
		 _("The HTTP method by which to send the request."), HTTP_METHOD_GET, HTTP_METHOD_DELETE,
		 HTTP_METHOD_GET, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
	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);
	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);

M harvest-glib/harvest-response-metadata.c => harvest-glib/harvest-response-metadata.c +12 -11
@@ 5,6 5,7 @@
#include <glib-object.h>
#include <glib/gi18n-lib.h>

#include "harvest-enum-types.h"
#include "harvest-http.h"
#include "harvest-response-metadata.h"



@@ 35,10 36,10 @@ harvest_response_metadata_get_property(GObject *obj, guint prop_id, GValue *val,

	switch (prop_id) {
	case PROP_EXPECTED_STATUS:
		g_value_set_int(val, self->expected_status);
		g_value_set_enum(val, (gint) self->expected_status);
		break;
	case PROP_BODY_TYPE:
		g_value_set_uint64(val, self->body_type);
		g_value_set_gtype(val, self->body_type);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);


@@ 53,10 54,10 @@ harvest_response_metadata_set_property(

	switch (prop_id) {
	case PROP_EXPECTED_STATUS:
		self->expected_status = g_value_get_int(val);
		self->expected_status = (HttpStatusCode) g_value_get_enum(val);
		break;
	case PROP_BODY_TYPE:
		self->body_type = g_value_get_uint64(val);
		self->body_type = g_value_get_gtype(val);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);


@@ 71,13 72,13 @@ harvest_response_metadata_class_init(HarvestResponseMetadataClass *klass)
	obj_class->get_property = harvest_response_metadata_get_property;
	obj_class->set_property = harvest_response_metadata_set_property;

	obj_properties[PROP_EXPECTED_STATUS] = g_param_spec_int("expected-status", _("Expected Status"),
		_("The expected status code the response should come back with."), HTTP_STATUS_OK,
		HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK,
	obj_properties[PROP_EXPECTED_STATUS] = g_param_spec_enum("expected-status",
		_("Expected Status"), _("The expected status code the response should come back with."),
		HTTP_TYPE_STATUS_CODE, HTTP_STATUS_OK,
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
	obj_properties[PROP_BODY_TYPE]		 = g_param_spec_uint64("body-type", _("Body Type"),
		  _("The GType of the response body."), G_TYPE_NONE, __UINT64_MAX__, G_TYPE_NONE,
		  G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
	obj_properties[PROP_BODY_TYPE]
		= g_param_spec_gtype("body-type", _("Body Type"), _("The GType of the response body."),
			G_TYPE_NONE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);

	g_object_class_install_properties(obj_class, N_PROPS, obj_properties);
}


@@ 87,7 88,7 @@ harvest_response_metadata_init(G_GNUC_UNUSED HarvestResponseMetadata *self)
{}

HarvestResponseMetadata *
harvest_response_metadata_new(const GType body_type, const HttpStatusCode expected_status)
harvest_response_metadata_new(GType body_type, HttpStatusCode expected_status)
{
	return g_object_new(HARVEST_TYPE_RESPONSE_METADATA, "body-type", body_type, "expected-status",
		expected_status, NULL);

M harvest-glib/harvest-response-metadata.h => harvest-glib/harvest-response-metadata.h +1 -1
@@ 15,7 15,7 @@ G_DECLARE_FINAL_TYPE(
	HarvestResponseMetadata, harvest_response_metadata, HARVEST, RESPONSE_METADATA, GObject)

HarvestResponseMetadata *harvest_response_metadata_new(
	const GType body_type, const HttpStatusCode expected_status);
	GType body_type, HttpStatusCode expected_status) G_GNUC_WARN_UNUSED_RESULT;
HttpStatusCode harvest_response_metadata_get_expected_status(
	HarvestResponseMetadata *self) G_GNUC_CONST;
GType harvest_response_metadata_get_body_type(HarvestResponseMetadata *self) G_GNUC_CONST;

M harvest-glib/harvest-response.c => harvest-glib/harvest-response.c +5 -5
@@ 5,6 5,7 @@
#include <glib-object.h>
#include <glib/gi18n-lib.h>

#include "harvest-enum-types.h"
#include "harvest-http.h"
#include "harvest-response.h"



@@ 47,7 48,7 @@ harvest_response_get_property(GObject *obj, guint prop_id, GValue *val, GParamSp
		g_value_set_boxed(val, self->err);
		break;
	case PROP_STATUS_CODE:
		g_value_set_int(val, self->status_code);
		g_value_set_enum(val, (gint) self->status_code);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);


@@ 71,7 72,7 @@ harvest_response_set_property(GObject *obj, guint prop_id, const GValue *val, GP
		self->err = g_value_dup_boxed(val);
		break;
	case PROP_STATUS_CODE:
		self->status_code = g_value_get_int(val);
		self->status_code = (HttpStatusCode) g_value_get_enum(val);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);


@@ 92,9 93,8 @@ harvest_response_class_init(HarvestResponseClass *klass)
	obj_properties[PROP_ERROR]
		= g_param_spec_boxed("error", _("Error"), _("Why the request errored out."), G_TYPE_ERROR,
			G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
	obj_properties[PROP_STATUS_CODE] = g_param_spec_int("status-code", _("Status Code"),
		_("Status code the response came back with"), HTTP_STATUS_OK,
		HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK,
	obj_properties[PROP_STATUS_CODE] = g_param_spec_enum("status-code", _("Status Code"),
		_("Status code the response came back with."), HTTP_TYPE_STATUS_CODE, HTTP_STATUS_OK,
		G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

	g_object_class_install_properties(obj_class, N_PROPS, obj_properties);