Class: StropheRuby::Stanza
- Inherits:
-
Object
- Object
- StropheRuby::Stanza
- Defined in:
- ext/strophe_ruby/strophe_ruby.c
Class Method Summary collapse
-
.new ⇒ Object
Create a new stanza.
Instance Method Summary collapse
-
#add_child(rb_child) ⇒ Object
Add a child element to a stanza (hint: message stanzas have a body element…).
-
#attribute(rb_attribute) ⇒ Object
Get the attribute of a stanza.
-
#child_by_name(rb_name) ⇒ Object
Get the child of a stanza by its name.
-
#children ⇒ Object
Get the children of the stanza.
-
#clone ⇒ Object
Clone a stanza.
-
#copy ⇒ Object
Copy a stanza.
-
#id ⇒ Object
Get the id of a stanza.
-
#id=(rb_id) ⇒ Object
Set the id of a stanza.
-
#name ⇒ Object
Get the name of a stanza (message, presence, iq).
-
#name=(rb_name) ⇒ Object
Set the name of a stanza (message, presence, iq).
-
#next ⇒ Object
TODO: Test this!.
-
#ns ⇒ Object
Get the namespace of a stanza TODO: Test this!.
-
#ns=(rb_ns) ⇒ Object
Set the namespace of a stanza.
-
#set_attribute(rb_attribute, rb_val) ⇒ Object
Set the value of a stanza attribute (eg. stanza.set_attribute(“to”,“[email protected]”).
-
#text ⇒ Object
Get the text of a stanza.
-
#text=(rb_text) ⇒ Object
Set the text of a stanza.
-
#type ⇒ Object
Get the type of a stanza.
-
#type=(rb_type) ⇒ Object
Set the type of a stanza.
Class Method Details
.new ⇒ Object
Create a new stanza
343 344 345 346 347 348 349 350 351 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 343 VALUE t_xmpp_stanza_new(VALUE class) { //Get the context in a format that C can understand xmpp_ctx_t *ctx; VALUE rb_conn = rb_gv_get("rb_conn"); Data_Get_Struct(rb_iv_get(rb_conn,"@ctx"), xmpp_ctx_t, ctx); xmpp_stanza_t *stanza = xmpp_stanza_new(ctx); VALUE tdata = Data_Wrap_Struct(class, 0, t_xmpp_stanza_release, stanza); } |
Instance Method Details
#add_child(rb_child) ⇒ Object
Add a child element to a stanza (hint: message stanzas have a body element…)
549 550 551 552 553 554 555 556 557 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 549 static VALUE t_xmpp_stanza_add_child(VALUE self, VALUE rb_child) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); xmpp_stanza_t *child; Data_Get_Struct(rb_child, xmpp_stanza_t, child); int res = xmpp_stanza_add_child(stanza,child); return INT2FIX(res); } |
#attribute(rb_attribute) ⇒ Object
Get the attribute of a stanza. eg. message_stanza.child_by_name(“body”).text
420 421 422 423 424 425 426 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 420 static VALUE t_xmpp_stanza_get_attribute(VALUE self, VALUE rb_attribute) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *val = xmpp_stanza_get_attribute(stanza,STR2CSTR(rb_attribute)); return rb_str_new2(val); } |
#child_by_name(rb_name) ⇒ Object
Get the child of a stanza by its name. eg. body_stanza = message_stanza.child_by_name(“body”)
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 391 static VALUE t_xmpp_stanza_get_child_by_name(VALUE self, VALUE rb_name) { xmpp_stanza_t *stanza; xmpp_stanza_t *child; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *name = STR2CSTR(rb_name); child = xmpp_stanza_get_child_by_name(stanza, name); if(child) { VALUE rb_child = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, child); return rb_child; } else { return Qnil; } } |
#children ⇒ Object
Get the children of the stanza. For example, message stanzas have a “body” child that contains another stanza that contains the actual message. If you have the top level stanza you can do something like : body_stanza = message_stanza.children
376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 376 static VALUE t_xmpp_stanza_get_children(VALUE self) { xmpp_stanza_t *stanza; xmpp_stanza_t *children; Data_Get_Struct(self, xmpp_stanza_t, stanza); children = xmpp_stanza_get_children(stanza); if(children) { VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, children); return tdata; } else return Qnil; } |
#clone ⇒ Object
Clone a stanza. TODO: Test this!
354 355 356 357 358 359 360 361 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 354 static VALUE t_xmpp_stanza_clone(VALUE self) { xmpp_stanza_t *stanza; xmpp_stanza_t *new_stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); new_stanza = xmpp_stanza_clone(stanza); VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, new_stanza); return tdata; } |
#copy ⇒ Object
Copy a stanza. TODO: Test this!
364 365 366 367 368 369 370 371 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 364 static VALUE t_xmpp_stanza_copy(VALUE self) { xmpp_stanza_t *stanza; xmpp_stanza_t *new_stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); new_stanza = xmpp_stanza_copy(stanza); VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, new_stanza); return tdata; } |
#id ⇒ Object
Get the id of a stanza. TODO:Test this!
473 474 475 476 477 478 479 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 473 static VALUE t_xmpp_stanza_get_id(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *id = xmpp_stanza_get_id(stanza); return rb_str_new2(id); } |
#id=(rb_id) ⇒ Object
Set the id of a stanza. TODO:Test this!
538 539 540 541 542 543 544 545 546 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 538 static VALUE t_xmpp_stanza_set_id(VALUE self, VALUE rb_id) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *id = STR2CSTR(rb_id); xmpp_stanza_set_id(stanza, id); return Qtrue; } |
#name ⇒ Object
Get the name of a stanza (message, presence, iq)
451 452 453 454 455 456 457 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 451 static VALUE t_xmpp_stanza_get_name(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *name = xmpp_stanza_get_name(stanza); return rb_str_new2(name); } |
#name=(rb_name) ⇒ Object
Set the name of a stanza (message, presence, iq)
516 517 518 519 520 521 522 523 524 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 516 static VALUE t_xmpp_stanza_set_name(VALUE self, VALUE rb_name) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *name = STR2CSTR(rb_name); xmpp_stanza_set_name(stanza, name); return Qtrue; } |
#next ⇒ Object
TODO: Test this!
408 409 410 411 412 413 414 415 416 417 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 408 static VALUE t_xmpp_stanza_get_next(VALUE self) { xmpp_stanza_t *stanza; xmpp_stanza_t *next; Data_Get_Struct(self, xmpp_stanza_t, stanza); next = xmpp_stanza_get_next(stanza); VALUE tdata = Data_Wrap_Struct(cStanza, 0, t_xmpp_stanza_release, next); return tdata; } |
#ns ⇒ Object
Get the namespace of a stanza TODO: Test this!
429 430 431 432 433 434 435 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 429 static VALUE t_xmpp_stanza_get_ns(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *ns = xmpp_stanza_get_ns(stanza); return rb_str_new2(ns); } |
#ns=(rb_ns) ⇒ Object
Set the namespace of a stanza. TODO:Test this!
494 495 496 497 498 499 500 501 502 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 494 static VALUE t_xmpp_stanza_set_ns(VALUE self, VALUE rb_ns) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *ns = STR2CSTR(rb_ns); xmpp_stanza_set_ns(stanza, ns); return Qtrue; } |
#set_attribute(rb_attribute, rb_val) ⇒ Object
Set the value of a stanza attribute (eg. stanza.set_attribute(“to”,“[email protected]”)
482 483 484 485 486 487 488 489 490 491 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 482 static VALUE t_xmpp_stanza_set_attribute(VALUE self, VALUE rb_attribute, VALUE rb_val) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *attribute = STR2CSTR(rb_attribute); char *val = STR2CSTR(rb_val); xmpp_stanza_set_attribute(stanza, attribute, val); return Qtrue; } |
#text ⇒ Object
Get the text of a stanza.
438 439 440 441 442 443 444 445 446 447 448 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 438 static VALUE t_xmpp_stanza_get_text(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *text = xmpp_stanza_get_text(stanza); if(text) return rb_str_new2(text); else return rb_str_new2(""); } |
#text=(rb_text) ⇒ Object
Set the text of a stanza
505 506 507 508 509 510 511 512 513 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 505 static VALUE t_xmpp_stanza_set_text(VALUE self, VALUE rb_text) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *text = STR2CSTR(rb_text); xmpp_stanza_set_text(stanza, text); return rb_text; } |
#type ⇒ Object
Get the type of a stanza. For example, if the name is ‘message’, type can be ‘chat’, ‘normal’ and so on
460 461 462 463 464 465 466 467 468 469 470 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 460 static VALUE t_xmpp_stanza_get_type(VALUE self) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *type = xmpp_stanza_get_type(stanza); if(type) return rb_str_new2(type); else return Qnil; } |
#type=(rb_type) ⇒ Object
Set the type of a stanza. For example if the name is ‘message’, the type can be ‘chat’, ‘normal’ and so on
527 528 529 530 531 532 533 534 535 |
# File 'ext/strophe_ruby/strophe_ruby.c', line 527 static VALUE t_xmpp_stanza_set_type(VALUE self, VALUE rb_type) { xmpp_stanza_t *stanza; Data_Get_Struct(self, xmpp_stanza_t, stanza); char *type = STR2CSTR(rb_type); xmpp_stanza_set_type(stanza, type); return Qtrue; } |