soup-ruby 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8417f165649590d2812c9f23b1d8d835403f8659
4
- data.tar.gz: 7bd581fed65b6d943d944ee432bafdb1fc9920fe
3
+ metadata.gz: c2da95874c0107f0397c18eeda3dfcce0a84182e
4
+ data.tar.gz: cff71ab8585c67de982cd17acd287fc0a1440125
5
5
  SHA512:
6
- metadata.gz: afec2298738caaa47d3956326fde54b703e8712b1965ea06f8dbfc491d8534106b16ab20895a417307b49487891896d058e95a58e14584d189c22b65c319deb0
7
- data.tar.gz: 5a731a4d5fbba390463b418ab0bcc4a7fc5b708b73fbd1a5d60eb59635d0f5352b5105020ee30f53ca79434082994f7ac2c06ff0915ec815cc31ccd16c08310f
6
+ metadata.gz: 71ace95d5e671f4ba190cdcdd81a30962fa522a038a516190283b36b41b99eeff95cfa047f6d7d2bcba5df0e2baf863f32bcb60c79b9ef1e1082a742d24cff1c
7
+ data.tar.gz: 254a778b00f7a2b98303eb6fe753d5e90a2fa7d8c46bcf2500aa412d6971ac392bd5a3ad0ed38768507728d99ee21df074089f5651228b699a5d43a7b110c57c
data/ext/soup/extconf.rb CHANGED
@@ -19,20 +19,37 @@ end
19
19
  # Look for headers in {gem_root}/ext/{package}
20
20
  if use_gems
21
21
  %w[
22
- glib2 gdk_pixbuf2 atk gtk2 ].each do |package|
23
- require package
24
- $CFLAGS += " -I"+Gem.loaded_specs[package].full_gem_path+"/ext/"+package
22
+ glib2 gdk_pixbuf2 atk gtk2].each do |package|
23
+ require package
24
+ if Gem.loaded_specs[package]
25
+ $CFLAGS += " -I" + Gem.loaded_specs[package].full_gem_path + "/ext/" + package
26
+ else
27
+ if fn = $".find { |n| n.sub(/[.](so|rb)$/,'') == package }
28
+ dr = $:.find { |d| File.exist?(File.join(d, fn)) }
29
+ pt = File.join(dr,fn) if dr && fn
30
+ else
31
+ pt = "??"
32
+ end
33
+ STDERR.puts "require '" + package + "' loaded '"+pt+"' instead of the gem - trying to continue, but build may fail"
34
+ end
25
35
  end
26
36
  end
27
37
  if RbConfig::CONFIG.has_key?('rubyhdrdir')
28
- $CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby'
38
+ $CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby'
29
39
  end
30
40
 
31
41
  $CFLAGS += " -I."
32
42
  have_func("rb_errinfo")
33
43
  PKGConfig.have_package("gtk+-2.0") or exit(-1)
34
44
  PKGConfig.have_package("libsoup-2.4") or exit(-1)
35
- have_header("libsoup/soup.h") or exit(-1)
45
+
46
+ unless have_header("libsoup/soup.h")
47
+ paths = Gem.find_files("libsoup/soup.h")
48
+ paths.each do |path|
49
+ $CFLAGS += " '-I#{File.dirname(path)}'"
50
+ end
51
+ have_header("libsoup/soup.h") or exit -1
52
+ end
36
53
 
37
54
  STDOUT.print("checking for new allocation framework... ") # for ruby-1.7
38
55
  if Object.respond_to? :allocate
data/ext/soup/soup.c CHANGED
@@ -50,6 +50,243 @@ static VALUE
50
50
  URI_initialize(VALUE self, VALUE __v_uri_string);
51
51
  static VALUE
52
52
  URI_to_s(VALUE self);
53
+ static VALUE flagsMessageFlags;
54
+
55
+ static VALUE flagsBaseClass;
56
+
57
+ typedef struct {
58
+ int value;
59
+ char *name;
60
+ char *fullname;
61
+ } FlagsData;
62
+
63
+ static VALUE make_flags_value(VALUE klass, int value, char *name, char *fullname)
64
+ {
65
+ FlagsData *data = NULL;
66
+
67
+ data = ALLOC(FlagsData);
68
+ data->value = value;
69
+ data->name = name;
70
+ data->fullname = fullname;
71
+
72
+ return Data_Wrap_Struct(klass, NULL, free, data);
73
+ }
74
+ static int flags_value_to_int(VALUE value, VALUE klass)
75
+ {
76
+ switch (TYPE(value))
77
+ {
78
+ case T_FIXNUM:
79
+ case T_FLOAT:
80
+ return NUM2INT(value);
81
+ break;
82
+ case T_DATA:
83
+ if (rb_obj_is_kind_of(value, flagsBaseClass))
84
+ {
85
+ FlagsData *data = NULL;
86
+
87
+ if ((klass != Qnil) && (!rb_obj_is_kind_of(value, klass)))
88
+ {
89
+ rb_raise(rb_eTypeError, "Wrong type of flags %s (%s required)", rb_obj_classname(value), rb_class2name(klass));
90
+ }
91
+
92
+ Data_Get_Struct(value, FlagsData, data);
93
+ return data->value;
94
+ }
95
+ break;
96
+ }
97
+ return 0;
98
+
99
+ }
100
+
101
+ static VALUE rubber_flags_inspect(VALUE value)
102
+ {
103
+ FlagsData *data = NULL;
104
+ volatile VALUE str = rb_str_new("#<", 2);
105
+ char number[16] = "";
106
+
107
+ Data_Get_Struct(value, FlagsData, data);
108
+
109
+ rb_str_cat2(str, rb_obj_classname(value));
110
+ rb_str_cat2(str, " - ");
111
+ rb_str_cat2(str, data->name);
112
+ rb_str_cat2(str, "(");
113
+ sprintf(number, "%i", data->value);
114
+ rb_str_cat2(str, number);
115
+ rb_str_cat2(str, ")>");
116
+
117
+ return str;
118
+ }
119
+
120
+ static VALUE rubber_flags_to_s(VALUE value)
121
+ {
122
+ FlagsData *data = NULL;
123
+
124
+ Data_Get_Struct(value, FlagsData, data);
125
+
126
+ return rb_str_new2(data->fullname);
127
+ }
128
+ static VALUE rubber_flags_name(VALUE value)
129
+ {
130
+ FlagsData *data = NULL;
131
+
132
+ Data_Get_Struct(value, FlagsData, data);
133
+
134
+ return rb_str_new2(data->name);
135
+ }
136
+
137
+ static VALUE rubber_flags_cmp(VALUE value, VALUE other)
138
+ {
139
+ VALUE a,b;
140
+ a = rb_funcall(value, rb_intern("to_i"), 0);
141
+ b = rb_funcall(other, rb_intern("to_i"), 0);
142
+ #ifdef RB_NUM_COERCE_FUNCS_NEED_OPID
143
+ return rb_num_coerce_cmp(a, b, rb_intern("=="));
144
+ #else
145
+ return rb_num_coerce_cmp(a, b);
146
+ #endif
147
+ }
148
+
149
+ static VALUE rubber_flags_to_i(VALUE value)
150
+ {
151
+ FlagsData *data = NULL;
152
+
153
+ Data_Get_Struct(value, FlagsData, data);
154
+
155
+ return INT2FIX(data->value);
156
+ }
157
+
158
+ static VALUE rubber_flags_coerce(VALUE value, VALUE other)
159
+ {
160
+ FlagsData *data = NULL;
161
+
162
+ Data_Get_Struct(value, FlagsData, data);
163
+
164
+ switch(TYPE(other))
165
+ {
166
+ case T_FIXNUM:
167
+ case T_BIGNUM:
168
+ return INT2FIX(data->value);
169
+ case T_FLOAT:
170
+ return Qnil;
171
+ default:
172
+ return Qnil;
173
+ }
174
+ }
175
+
176
+ static VALUE rubber_flags_and(VALUE value, VALUE other)
177
+ {
178
+ FlagsData *data = NULL;
179
+ int original = 0;
180
+ int other_num = 0;
181
+
182
+ Data_Get_Struct(value, FlagsData, data);
183
+
184
+ original = data->value;
185
+
186
+ other_num = flags_value_to_int(value, CLASS_OF(value));
187
+
188
+ // return INT2NUM(original & other_num);
189
+ return make_flags_value(CLASS_OF(value), original & other_num, "", "");
190
+ }
191
+
192
+ static VALUE rubber_flags_or(VALUE value, VALUE other)
193
+ {
194
+ FlagsData *data = NULL;
195
+ int original = 0;
196
+ int other_num = 0;
197
+
198
+ Data_Get_Struct(value, FlagsData, data);
199
+
200
+ original = data->value;
201
+
202
+ other_num = flags_value_to_int(value, CLASS_OF(value));
203
+
204
+ return make_flags_value(CLASS_OF(value), original | other_num, "", "");
205
+ }
206
+
207
+
208
+
209
+ static VALUE flagsMessageFlags_SOUP_MESSAGE_NO_REDIRECT = Qnil;
210
+ static VALUE flagsMessageFlags_SOUP_MESSAGE_CAN_REBUILD = Qnil;
211
+ static VALUE flagsMessageFlags_SOUP_MESSAGE_CONTENT_DECODED = Qnil;
212
+ static VALUE flagsMessageFlags_SOUP_MESSAGE_CERTIFICATE_TRUSTED = Qnil;
213
+ static VALUE flagsMessageFlags_SOUP_MESSAGE_NEW_CONNECTION = Qnil;
214
+ static VALUE flagsMessageFlags_SOUP_MESSAGE_IDEMPOTENT = Qnil;
215
+ static VALUE rubber_flagsMessageFlags_flags_inspect(VALUE value)
216
+ {
217
+ FlagsData *data = NULL;
218
+ volatile VALUE str = rb_str_new("#<", 2);
219
+ char number[16] = "";
220
+ int c=0;
221
+
222
+ Data_Get_Struct(value, FlagsData, data);
223
+
224
+ rb_str_cat2(str, rb_obj_classname(value));
225
+ rb_str_cat2(str, " - ");
226
+ if ((data->value & SOUP_MESSAGE_NO_REDIRECT)==SOUP_MESSAGE_NO_REDIRECT) {
227
+ if (c>0)
228
+ rb_str_cat2(str, ", ");
229
+ rb_str_cat2(str, "no-redirect");
230
+ c ++;
231
+ }
232
+ if ((data->value & SOUP_MESSAGE_CAN_REBUILD)==SOUP_MESSAGE_CAN_REBUILD) {
233
+ if (c>0)
234
+ rb_str_cat2(str, ", ");
235
+ rb_str_cat2(str, "can-rebuild");
236
+ c ++;
237
+ }
238
+ if ((data->value & SOUP_MESSAGE_CONTENT_DECODED)==SOUP_MESSAGE_CONTENT_DECODED) {
239
+ if (c>0)
240
+ rb_str_cat2(str, ", ");
241
+ rb_str_cat2(str, "content-decoded");
242
+ c ++;
243
+ }
244
+ if ((data->value & SOUP_MESSAGE_CERTIFICATE_TRUSTED)==SOUP_MESSAGE_CERTIFICATE_TRUSTED) {
245
+ if (c>0)
246
+ rb_str_cat2(str, ", ");
247
+ rb_str_cat2(str, "certificate-trusted");
248
+ c ++;
249
+ }
250
+ if ((data->value & SOUP_MESSAGE_NEW_CONNECTION)==SOUP_MESSAGE_NEW_CONNECTION) {
251
+ if (c>0)
252
+ rb_str_cat2(str, ", ");
253
+ rb_str_cat2(str, "new-connection");
254
+ c ++;
255
+ }
256
+ if ((data->value & SOUP_MESSAGE_IDEMPOTENT)==SOUP_MESSAGE_IDEMPOTENT) {
257
+ if (c>0)
258
+ rb_str_cat2(str, ", ");
259
+ rb_str_cat2(str, "idempotent");
260
+ c ++;
261
+ }
262
+ rb_str_cat2(str, " (");
263
+ sprintf(number, "%i", data->value);
264
+ rb_str_cat2(str, number);
265
+ rb_str_cat2(str, ")>");
266
+
267
+ return str;
268
+ }
269
+ typedef int MessageFlags;
270
+ #ifdef __GNUC__
271
+ // No point in declaring these unless we're using GCC
272
+ // They're ahead of any code that uses them anyway.
273
+ static VALUE flags_MessageFlags_to_ruby(int value)
274
+ __attribute__ ((unused))
275
+ ;
276
+ static int flags_ruby_to_MessageFlags(VALUE val)
277
+ __attribute__ ((unused))
278
+ ;
279
+ #endif
280
+
281
+ static VALUE flags_MessageFlags_to_ruby(int value) { switch(value) {
282
+ case SOUP_MESSAGE_NO_REDIRECT: return flagsMessageFlags_SOUP_MESSAGE_NO_REDIRECT;
283
+ case SOUP_MESSAGE_CAN_REBUILD: return flagsMessageFlags_SOUP_MESSAGE_CAN_REBUILD;
284
+ case SOUP_MESSAGE_CONTENT_DECODED: return flagsMessageFlags_SOUP_MESSAGE_CONTENT_DECODED;
285
+ case SOUP_MESSAGE_CERTIFICATE_TRUSTED: return flagsMessageFlags_SOUP_MESSAGE_CERTIFICATE_TRUSTED;
286
+ case SOUP_MESSAGE_NEW_CONNECTION: return flagsMessageFlags_SOUP_MESSAGE_NEW_CONNECTION;
287
+ case SOUP_MESSAGE_IDEMPOTENT: return flagsMessageFlags_SOUP_MESSAGE_IDEMPOTENT;
288
+ }; return make_flags_value(flagsMessageFlags, value, "various", "Various"); }
289
+ static int flags_ruby_to_MessageFlags(VALUE val) { return flags_value_to_int(val, flagsMessageFlags); }
53
290
  static VALUE cMessage;
54
291
  static VALUE
55
292
  Message_initialize(VALUE self, VALUE __v_method, VALUE __v_uri);
@@ -60,6 +297,18 @@ Message_unset_request_header(VALUE self, VALUE __v_name);
60
297
  static VALUE
61
298
  Message_set_request_body(VALUE self, VALUE __v_type, VALUE body);
62
299
  static VALUE
300
+ Message_set_response(VALUE self, VALUE __v_content_type, VALUE body);
301
+ static VALUE
302
+ Message_set_status(int __p_argc, VALUE *__p_argv, VALUE self);
303
+ static VALUE
304
+ Message_set_redirect(VALUE self, VALUE __v_status_code, VALUE __v_redirect_uri);
305
+ static VALUE
306
+ Message_is_keepalive_query(VALUE self);
307
+ static VALUE
308
+ Message_flags_equals(VALUE self, VALUE __v_flags);
309
+ static VALUE
310
+ Message_flags(VALUE self);
311
+ static VALUE
63
312
  Message_get_response_header(VALUE self, VALUE __v_name);
64
313
  static VALUE
65
314
  Message_each_response_header(VALUE self);
@@ -225,7 +474,7 @@ Message_initialize(VALUE self, VALUE __v_method, VALUE __v_uri)
225
474
  __orig_method = method = ( NIL_P(__v_method) ? NULL : StringValuePtr(__v_method) );
226
475
  __orig_uri = uri = ( NIL_P(__v_uri) ? NULL : StringValuePtr(__v_uri) );
227
476
 
228
- #line 98 "/home/geoff/Projects/soup/ext/soup/soup.cr"
477
+ #line 100 "/home/geoff/Projects/soup/ext/soup/soup.cr"
229
478
  INIT(self, soup_message_new(method, uri));
230
479
 
231
480
  return Qnil;
@@ -240,7 +489,7 @@ Message_set_request_header(VALUE self, VALUE __v_name, VALUE __v_value)
240
489
  __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) );
241
490
  __orig_value = value = ( NIL_P(__v_value) ? NULL : StringValuePtr(__v_value) );
242
491
 
243
- #line 102 "/home/geoff/Projects/soup/ext/soup/soup.cr"
492
+ #line 104 "/home/geoff/Projects/soup/ext/soup/soup.cr"
244
493
  soup_message_headers_replace(_self->request_headers, name, value);
245
494
 
246
495
  return self;
@@ -253,7 +502,7 @@ Message_unset_request_header(VALUE self, VALUE __v_name)
253
502
  SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
254
503
  __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) );
255
504
 
256
- #line 106 "/home/geoff/Projects/soup/ext/soup/soup.cr"
505
+ #line 108 "/home/geoff/Projects/soup/ext/soup/soup.cr"
257
506
  soup_message_headers_remove(_self->request_headers, name);
258
507
 
259
508
  return Qnil;
@@ -267,12 +516,106 @@ Message_set_request_body(VALUE self, VALUE __v_type, VALUE body)
267
516
  __orig_type = type = ( NIL_P(__v_type) ? NULL : StringValuePtr(__v_type) );
268
517
  Check_Type(body, T_STRING);
269
518
 
270
- #line 110 "/home/geoff/Projects/soup/ext/soup/soup.cr"
519
+ #line 112 "/home/geoff/Projects/soup/ext/soup/soup.cr"
271
520
  soup_message_set_request(_self, type, SOUP_MEMORY_COPY, RSTRING_PTR(body), RSTRING_LEN(body));
272
521
 
273
522
  return self;
274
523
  }
275
524
 
525
+ static VALUE
526
+ Message_set_response(VALUE self, VALUE __v_content_type, VALUE body)
527
+ {
528
+ char * content_type; char * __orig_content_type;
529
+ SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
530
+ __orig_content_type = content_type = ( NIL_P(__v_content_type) ? NULL : StringValuePtr(__v_content_type) );
531
+ Check_Type(body, T_STRING);
532
+
533
+ #line 116 "/home/geoff/Projects/soup/ext/soup/soup.cr"
534
+ soup_message_set_response(_self, content_type, SOUP_MEMORY_COPY, RSTRING_PTR(body), RSTRING_LEN(body));
535
+
536
+ return self;
537
+ }
538
+
539
+ static VALUE
540
+ Message_set_status(int __p_argc, VALUE *__p_argv, VALUE self)
541
+ {
542
+ VALUE __v_status_code = Qnil;
543
+ int status_code; int __orig_status_code;
544
+ VALUE __v_reason = Qnil;
545
+ char * reason; char * __orig_reason;
546
+ SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
547
+
548
+ /* Scan arguments */
549
+ rb_scan_args(__p_argc, __p_argv, "11",&__v_status_code, &__v_reason);
550
+
551
+ /* Set defaults */
552
+ __orig_status_code = status_code = NUM2INT(__v_status_code);
553
+
554
+ if (__p_argc > 1)
555
+ __orig_reason = reason = ( NIL_P(__v_reason) ? NULL : StringValuePtr(__v_reason) );
556
+ else
557
+ reason = NULL;
558
+
559
+
560
+ #line 120 "/home/geoff/Projects/soup/ext/soup/soup.cr"
561
+ if (reason) { soup_message_set_status_full(_self, status_code, reason);
562
+ } else { soup_message_set_status(_self, status_code);
563
+ }
564
+ return self;
565
+ }
566
+
567
+ static VALUE
568
+ Message_set_redirect(VALUE self, VALUE __v_status_code, VALUE __v_redirect_uri)
569
+ {
570
+ int status_code; int __orig_status_code;
571
+ char * redirect_uri; char * __orig_redirect_uri;
572
+ SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
573
+ __orig_status_code = status_code = NUM2INT(__v_status_code);
574
+ __orig_redirect_uri = redirect_uri = ( NIL_P(__v_redirect_uri) ? NULL : StringValuePtr(__v_redirect_uri) );
575
+
576
+ #line 128 "/home/geoff/Projects/soup/ext/soup/soup.cr"
577
+ soup_message_set_redirect(_self, status_code, redirect_uri);
578
+
579
+ return self;
580
+ }
581
+
582
+ static VALUE
583
+ Message_is_keepalive_query(VALUE self)
584
+ {
585
+ VALUE __p_retval = Qnil;
586
+ SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
587
+
588
+ #line 132 "/home/geoff/Projects/soup/ext/soup/soup.cr"
589
+ do { __p_retval = ((soup_message_is_keepalive(_self)) ? Qtrue : Qfalse); goto out; } while(0);
590
+ out:
591
+ return __p_retval;
592
+ }
593
+
594
+ static VALUE
595
+ Message_flags_equals(VALUE self, VALUE __v_flags)
596
+ {
597
+ MessageFlags flags; MessageFlags __orig_flags;
598
+ SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
599
+ __orig_flags = flags = flags_ruby_to_MessageFlags((__v_flags));
600
+
601
+ #line 136 "/home/geoff/Projects/soup/ext/soup/soup.cr"
602
+ soup_message_set_flags(_self, flags);
603
+
604
+ return __v_flags;
605
+ }
606
+
607
+ static VALUE
608
+ Message_flags(VALUE self)
609
+ {
610
+ VALUE __p_retval = Qnil;
611
+ SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
612
+
613
+ #line 140 "/home/geoff/Projects/soup/ext/soup/soup.cr"
614
+ do { __p_retval = flags_MessageFlags_to_ruby((soup_message_get_flags(_self))); goto out; } while(0);
615
+ out:
616
+ return __p_retval;
617
+ }
618
+
276
619
  static VALUE
277
620
  Message_get_response_header(VALUE self, VALUE __v_name)
278
621
  {
@@ -281,7 +624,7 @@ Message_get_response_header(VALUE self, VALUE __v_name)
281
624
  SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
282
625
  __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) );
283
626
 
284
- #line 114 "/home/geoff/Projects/soup/ext/soup/soup.cr"
627
+ #line 144 "/home/geoff/Projects/soup/ext/soup/soup.cr"
285
628
  do { __p_retval = rb_str_new2(soup_message_headers_get_one(_self->response_headers, name)); goto out; } while(0);
286
629
  out:
287
630
  return __p_retval;
@@ -292,7 +635,7 @@ Message_each_response_header(VALUE self)
292
635
  {
293
636
  SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
294
637
 
295
- #line 118 "/home/geoff/Projects/soup/ext/soup/soup.cr"
638
+ #line 148 "/home/geoff/Projects/soup/ext/soup/soup.cr"
296
639
 
297
640
  do {
298
641
  VALUE block =
@@ -312,7 +655,7 @@ Message_response_body(VALUE self)
312
655
  VALUE __p_retval = Qnil;
313
656
  SoupMessage *_self = ((SoupMessage*)RVAL2GOBJ(self));
314
657
 
315
- #line 124 "/home/geoff/Projects/soup/ext/soup/soup.cr"
658
+ #line 154 "/home/geoff/Projects/soup/ext/soup/soup.cr"
316
659
 
317
660
  do {
318
661
  SoupBuffer * buffer =
@@ -369,11 +712,49 @@ Init_soup(void)
369
712
  cURI = G_DEF_CLASS(SOUP_TYPE_URI, "URI", mSoup);
370
713
  rb_define_method(cURI, "initialize", URI_initialize, 1);
371
714
  rb_define_method(cURI, "to_s", URI_to_s, 0);
715
+ flagsBaseClass = rb_define_class("Flags", rb_cObject);
716
+ rb_define_method(flagsBaseClass, "inspect", rubber_flags_inspect, 0);
717
+ rb_define_method(flagsBaseClass, "to_i", rubber_flags_to_i, 0);
718
+ rb_define_method(flagsBaseClass, "coerce", rubber_flags_coerce, 1);
719
+ rb_define_method(flagsBaseClass, "to_s", rubber_flags_to_s, 0);
720
+ rb_define_method(flagsBaseClass, "to_str", rubber_flags_to_s, 0);
721
+ rb_define_method(flagsBaseClass, "fullname", rubber_flags_to_s, 0);
722
+ rb_define_method(flagsBaseClass, "name", rubber_flags_name, 0);
723
+ rb_define_method(flagsBaseClass, "<=>", rubber_flags_cmp, 0);
724
+ rb_define_method(flagsBaseClass, "&", rubber_flags_and, 1);
725
+ rb_define_method(flagsBaseClass, "|", rubber_flags_or, 1);
726
+
727
+ flagsMessageFlags = rb_define_class_under(mSoup, "MessageFlags", flagsBaseClass);
728
+ rb_define_method(flagsMessageFlags, "inspect", rubber_flagsMessageFlags_flags_inspect, 0);
729
+ flagsMessageFlags_SOUP_MESSAGE_NO_REDIRECT = make_flags_value(flagsMessageFlags, SOUP_MESSAGE_NO_REDIRECT, "no-redirect", "SOUP_MESSAGE_NO_REDIRECT");
730
+ rb_obj_freeze(flagsMessageFlags_SOUP_MESSAGE_NO_REDIRECT);
731
+ rb_define_const(flagsMessageFlags, "NO_REDIRECT", flagsMessageFlags_SOUP_MESSAGE_NO_REDIRECT);
732
+ flagsMessageFlags_SOUP_MESSAGE_CAN_REBUILD = make_flags_value(flagsMessageFlags, SOUP_MESSAGE_CAN_REBUILD, "can-rebuild", "SOUP_MESSAGE_CAN_REBUILD");
733
+ rb_obj_freeze(flagsMessageFlags_SOUP_MESSAGE_CAN_REBUILD);
734
+ rb_define_const(flagsMessageFlags, "CAN_REBUILD", flagsMessageFlags_SOUP_MESSAGE_CAN_REBUILD);
735
+ flagsMessageFlags_SOUP_MESSAGE_CONTENT_DECODED = make_flags_value(flagsMessageFlags, SOUP_MESSAGE_CONTENT_DECODED, "content-decoded", "SOUP_MESSAGE_CONTENT_DECODED");
736
+ rb_obj_freeze(flagsMessageFlags_SOUP_MESSAGE_CONTENT_DECODED);
737
+ rb_define_const(flagsMessageFlags, "CONTENT_DECODED", flagsMessageFlags_SOUP_MESSAGE_CONTENT_DECODED);
738
+ flagsMessageFlags_SOUP_MESSAGE_CERTIFICATE_TRUSTED = make_flags_value(flagsMessageFlags, SOUP_MESSAGE_CERTIFICATE_TRUSTED, "certificate-trusted", "SOUP_MESSAGE_CERTIFICATE_TRUSTED");
739
+ rb_obj_freeze(flagsMessageFlags_SOUP_MESSAGE_CERTIFICATE_TRUSTED);
740
+ rb_define_const(flagsMessageFlags, "CERTIFICATE_TRUSTED", flagsMessageFlags_SOUP_MESSAGE_CERTIFICATE_TRUSTED);
741
+ flagsMessageFlags_SOUP_MESSAGE_NEW_CONNECTION = make_flags_value(flagsMessageFlags, SOUP_MESSAGE_NEW_CONNECTION, "new-connection", "SOUP_MESSAGE_NEW_CONNECTION");
742
+ rb_obj_freeze(flagsMessageFlags_SOUP_MESSAGE_NEW_CONNECTION);
743
+ rb_define_const(flagsMessageFlags, "NEW_CONNECTION", flagsMessageFlags_SOUP_MESSAGE_NEW_CONNECTION);
744
+ flagsMessageFlags_SOUP_MESSAGE_IDEMPOTENT = make_flags_value(flagsMessageFlags, SOUP_MESSAGE_IDEMPOTENT, "idempotent", "SOUP_MESSAGE_IDEMPOTENT");
745
+ rb_obj_freeze(flagsMessageFlags_SOUP_MESSAGE_IDEMPOTENT);
746
+ rb_define_const(flagsMessageFlags, "IDEMPOTENT", flagsMessageFlags_SOUP_MESSAGE_IDEMPOTENT);
372
747
  cMessage = G_DEF_CLASS(SOUP_TYPE_MESSAGE, "Message", mSoup);
373
748
  rb_define_method(cMessage, "initialize", Message_initialize, 2);
374
749
  rb_define_method(cMessage, "set_request_header", Message_set_request_header, 2);
375
750
  rb_define_method(cMessage, "unset_request_header", Message_unset_request_header, 1);
376
751
  rb_define_method(cMessage, "set_request_body", Message_set_request_body, 2);
752
+ rb_define_method(cMessage, "set_response", Message_set_response, 2);
753
+ rb_define_method(cMessage, "set_status", Message_set_status, -1);
754
+ rb_define_method(cMessage, "set_redirect", Message_set_redirect, 2);
755
+ rb_define_method(cMessage, "is_keepalive?", Message_is_keepalive_query, 0);
756
+ rb_define_method(cMessage, "flags=", Message_flags_equals, 1);
757
+ rb_define_method(cMessage, "flags", Message_flags, 0);
377
758
  rb_define_method(cMessage, "get_response_header", Message_get_response_header, 1);
378
759
  rb_define_method(cMessage, "each_response_header", Message_each_response_header, 0);
379
760
  rb_define_method(cMessage, "response_body", Message_response_body, 0);
data/ext/soup/soup.cr CHANGED
@@ -93,6 +93,8 @@ module Soup
93
93
  end
94
94
  end
95
95
 
96
+ flags MessageFlags (SOUP_MESSAGE_NO_REDIRECT, SOUP_MESSAGE_CAN_REBUILD, SOUP_MESSAGE_CONTENT_DECODED, SOUP_MESSAGE_CERTIFICATE_TRUSTED, SOUP_MESSAGE_NEW_CONNECTION, SOUP_MESSAGE_IDEMPOTENT)
97
+
96
98
  gobject Message < SOUP_TYPE_MESSAGE
97
99
  @type SoupMessage
98
100
  def initialize(char * method, char * uri)
@@ -111,6 +113,34 @@ module Soup
111
113
  soup_message_set_request(_self, type, SOUP_MEMORY_COPY, RSTRING_PTR(body), RSTRING_LEN(body));
112
114
  end
113
115
 
116
+ def set_response(char *content_type, T_STRING body)
117
+ soup_message_set_response(_self, content_type, SOUP_MEMORY_COPY, RSTRING_PTR(body), RSTRING_LEN(body));
118
+ end
119
+
120
+ def set_status(int status_code, char *reason = NULL)
121
+ if (reason) {
122
+ soup_message_set_status_full(_self, status_code, reason);
123
+ } else {
124
+ soup_message_set_status(_self, status_code);
125
+ }
126
+ end
127
+
128
+ def set_redirect(int status_code, char *redirect_uri)
129
+ soup_message_set_redirect(_self, status_code, redirect_uri);
130
+ end
131
+
132
+ def bool:is_keepalive?
133
+ return soup_message_is_keepalive(_self);
134
+ end
135
+
136
+ def flags=(MessageFlags flags)
137
+ soup_message_set_flags(_self, flags);
138
+ end
139
+
140
+ def MessageFlags:flags
141
+ return soup_message_get_flags(_self);
142
+ end
143
+
114
144
  def char *:get_response_header(char *name)
115
145
  return soup_message_headers_get_one(_self->response_headers, name);
116
146
  end
data/ext/soup/soup.rd CHANGED
@@ -23,6 +23,7 @@
23
23
 
24
24
  --- Soup::URI#to_s
25
25
 
26
+ == flags Soup::MessageFlags
26
27
  == class Soup::Message
27
28
  --- Soup::Message.new(String method, String uri)
28
29
 
@@ -36,6 +37,22 @@
36
37
  --- Soup::Message#set_request_body(String type, String body)
37
38
 
38
39
 
40
+ --- Soup::Message#set_response(String content_type, String body)
41
+
42
+
43
+ --- Soup::Message#set_status(Integer status_code, String reason)
44
+
45
+
46
+ --- Soup::Message#set_redirect(Integer status_code, String redirect_uri)
47
+
48
+
49
+ --- Soup::Message#is_keepalive?
50
+
51
+ --- Soup::Message#flags=(MessageFlags flags)
52
+
53
+
54
+ --- Soup::Message#flags
55
+
39
56
  --- Soup::Message#get_response_header(String name)
40
57
 
41
58
 
data/lib/soup/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Soup
2
- BINDINGS_VERSION= [0,0,2]
2
+ BINDINGS_VERSION= [0,0,4]
3
3
  def BINDINGS_VERSION.to_s
4
4
  join('.')
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soup-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Youngs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-05 00:00:00.000000000 Z
11
+ date: 2013-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubber-generate
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.0.0.rc.2
67
+ rubygems_version: 2.0.3
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Soup bindings using rubber-generate