~tristan957/harvest-almanac

ref: 3e4722b8fc00df0fbbb320a4ac7d9155d485a1ea harvest-almanac/harvest-glib/harvest-response-metadata.c -rw-r--r-- 2.8 KiB
3e4722b8Tristan Partin harvest-almanac: added support for updating company 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "config.h"

#define G_LOG_DOMAIN "HarvestResponseMetadata"

#include <glib-object.h>
#include <glib/gi18n-lib.h>

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

struct _HarvestResponseMetadata
{
	GObject parent_instance;

	HttpStatusCode expected_status;
	GType body_type;
};

G_DEFINE_TYPE(HarvestResponseMetadata, harvest_response_metadata, G_TYPE_OBJECT)

enum HarvestResponseMetadataProps
{
	PROP_0,
	PROP_EXPECTED_STATUS,
	PROP_BODY_TYPE,
	N_PROPS
};

static GParamSpec *obj_properties[N_PROPS];

static void
harvest_response_metadata_get_property(GObject *obj, guint prop_id, GValue *val, GParamSpec *pspec)
{
	HarvestResponseMetadata *self = HARVEST_RESPONSE_METADATA(obj);

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

static void
harvest_response_metadata_set_property(
	GObject *obj, guint prop_id, const GValue *val, GParamSpec *pspec)
{
	HarvestResponseMetadata *self = HARVEST_RESPONSE_METADATA(obj);

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

static void
harvest_response_metadata_class_init(HarvestResponseMetadataClass *klass)
{
	GObjectClass *obj_class = G_OBJECT_CLASS(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,
		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);

	g_object_class_install_properties(obj_class, N_PROPS, obj_properties);
}

static void
harvest_response_metadata_init(G_GNUC_UNUSED HarvestResponseMetadata *self)
{}

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

HttpStatusCode
harvest_response_metadata_get_expected_status(HarvestResponseMetadata *self)
{
	return self->expected_status;
}

GType
harvest_response_metadata_get_body_type(HarvestResponseMetadata *self)
{
	return self->body_type;
}