Class: PurpleRuby::Account

Inherits:
Object
  • Object
show all
Defined in:
ext/purple_ruby.c

Instance Method Summary collapse

Instance Method Details

#add_buddy(buddy) ⇒ Object



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# File 'ext/purple_ruby.c', line 770

static VALUE add_buddy(VALUE self, VALUE buddy)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  
	PurpleBuddy* pb = purple_buddy_new(account, RSTRING_PTR(buddy), NULL);
  
  char* group = _("Buddies");
  PurpleGroup* grp = purple_find_group(group);
	if (!grp)
	{
		grp = purple_group_new(group);
		purple_blist_add_group(grp, NULL);
	}
  
  purple_blist_add_buddy(pb, NULL, grp, NULL);
  purple_account_add_buddy(account, pb);
  return Qtrue;
}

#common_send(name, message) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
# File 'ext/purple_ruby.c', line 690

static VALUE common_send(VALUE self, VALUE name, VALUE message)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  
  if (purple_account_is_connected(account)) {
     PurpleBuddy* buddy = purple_find_buddy(account, RSTRING_PTR(name));
     if (buddy != NULL) {
       PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, RSTRING_PTR(name), account);
       if (conv == NULL) {
         conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
                                        buddy->account, buddy->name);
       }
       purple_conv_im_send(PURPLE_CONV_IM(conv), RSTRING_PTR(message));
       return INT2FIX(0);
     } else {
       return Qnil;
     }
  } else {
    return Qnil;    
  }
}

#deleteObject



824
825
826
827
828
829
830
# File 'ext/purple_ruby.c', line 824

static VALUE acc_delete(VALUE self)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  purple_accounts_delete(account);
  return Qnil;
}

#get_bool_setting(name, default_value) ⇒ Object



734
735
736
737
738
739
740
741
# File 'ext/purple_ruby.c', line 734

static VALUE get_bool_setting(VALUE self, VALUE name, VALUE default_value)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  gboolean value = purple_account_get_bool(account, RSTRING_PTR(name), 
    (default_value == Qfalse || default_value == Qnil) ? FALSE : TRUE); 
  return (TRUE == value) ? Qtrue : Qfalse;
}

#get_string_setting(name, default_value) ⇒ Object



743
744
745
746
747
748
749
# File 'ext/purple_ruby.c', line 743

static VALUE get_string_setting(VALUE self, VALUE name, VALUE default_value)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  const char* value = purple_account_get_string(account, RSTRING_PTR(name), RSTRING_PTR(default_value));
  return (NULL == value) ? Qnil : rb_str_new2(value);
}

#has_buddy?(buddy) ⇒ Boolean

Returns:

  • (Boolean)


813
814
815
816
817
818
819
820
821
822
# File 'ext/purple_ruby.c', line 813

static VALUE has_buddy(VALUE self, VALUE buddy)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  if (purple_find_buddy(account, RSTRING_PTR(buddy)) != NULL) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

#logoutObject



638
639
640
641
642
643
644
645
# File 'ext/purple_ruby.c', line 638

static VALUE logout(VALUE self)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  purple_account_disconnect(account);

  return Qnil;
}

#protocol_idObject



720
721
722
723
724
725
# File 'ext/purple_ruby.c', line 720

static VALUE protocol_id(VALUE self)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  return rb_str_new2(purple_account_get_protocol_id(account));
}

#protocol_nameObject



727
728
729
730
731
732
# File 'ext/purple_ruby.c', line 727

static VALUE protocol_name(VALUE self)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  return rb_str_new2(purple_account_get_protocol_name(account));
}

#remove_buddy(buddy) ⇒ Object



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
# File 'ext/purple_ruby.c', line 790

static VALUE remove_buddy(VALUE self, VALUE buddy)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  
	PurpleBuddy* pb = purple_find_buddy(account, RSTRING_PTR(buddy));
	if (NULL == pb) {
	  rb_raise(rb_eRuntimeError, "Failed to remove buddy for %s : %s does not exist", purple_account_get_username(account), RSTRING_PTR(buddy));
	}
	
	char* group = _("Buddies");
  PurpleGroup* grp = purple_find_group(group);
	if (!grp)
	{
		grp = purple_group_new(group);
		purple_blist_add_group(grp, NULL);
	}
	
	purple_blist_remove_buddy(pb);
	purple_account_remove_buddy(account, pb, grp);
  return Qtrue;
}

#send_im(name, message) ⇒ Object



677
678
679
680
681
682
683
684
685
686
687
688
# File 'ext/purple_ruby.c', line 677

static VALUE send_im(VALUE self, VALUE name, VALUE message)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  
  if (purple_account_is_connected(account)) {
    int i = serv_send_im(purple_account_get_connection(account), RSTRING_PTR(name), RSTRING_PTR(message), 0);
    return INT2FIX(i);
  } else {
    return Qnil;
  }
}

#usernameObject



713
714
715
716
717
718
# File 'ext/purple_ruby.c', line 713

static VALUE username(VALUE self)
{
  PurpleAccount *account;
  Data_Get_Struct(self, PurpleAccount, account);
  return rb_str_new2(purple_account_get_username(account));
}