ruburple 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/ruburple_ext.c CHANGED
@@ -55,10 +55,13 @@ static VALUE rb_ruburple_protocol_account_chat;
55
55
  static VALUE rb_ruburple_protocol_account_savedstatus;
56
56
  static VALUE rb_ruburple_protocol_connection;
57
57
  static VALUE rb_ruburple_blist_status;
58
+ static VALUE rb_ruburple_blist_presence;
58
59
  static VALUE rb_ruburple_blist;
59
60
  static VALUE rb_ruburple_blist_buddy_icon;
60
61
  static VALUE rb_ruburple_blist_buddy;
61
62
  static VALUE rb_ruburple_blist_node;
63
+ static VALUE rb_ruburple_blist_contact;
64
+ static VALUE rb_ruburple_blist_chat;
62
65
  static VALUE rb_ruburple_blist_group;
63
66
  static VALUE rb_ruburple_handle;
64
67
  static VALUE rb_ruburple_cipher;
@@ -112,6 +115,7 @@ static VALUE delete_method_id;
112
115
  #define RB_RUBURPLE_PLUGIN(purple_plugin_pointer) Data_Wrap_Struct(rb_ruburple_plugin, NULL, NULL, purple_plugin_pointer)
113
116
  #define RB_RUBURPLE_PROTOCOL_INFO(purple_plugin_info_pointer) Data_Wrap_Struct(rb_ruburple_protocol_info, NULL, NULL, purple_plugin_info_pointer)
114
117
  #define RB_RUBURPLE_BLIST_STATUS(purple_status_pointer) Data_Wrap_Struct(rb_ruburple_blist_status, NULL, NULL, purple_status_pointer)
118
+ #define RB_RUBURPLE_BLIST_PRESENCE(purple_presence_pointer) Data_Wrap_Struct(rb_ruburple_blist_presence, NULL, NULL, purple_presence_pointer)
115
119
  #define RB_RUBURPLE_BLIST(purple_blist_pointer) Data_Wrap_Struct(rb_ruburple_blist, NULL, NULL, purple_blist_pointer)
116
120
  #define RB_RUBURPLE_BLIST_BUDDY(purple_buddy_pointer) Data_Wrap_Struct(rb_ruburple_blist_buddy, NULL, NULL, purple_buddy_pointer)
117
121
  #define RB_RUBURPLE_BLIST_NODE(purple_blist_node_pointer) Data_Wrap_Struct(rb_ruburple_blist_node, NULL, NULL, purple_blist_node_pointer)
@@ -136,6 +140,9 @@ static VALUE delete_method_id;
136
140
  #define PURPLE_SAVEDSTATUS(rb_ruburple_protocol_account_savedstatus,purple_saved_status_pointer) Data_Get_Struct(rb_ruburple_protocol_account_savedstatus, PurpleSavedStatus, purple_saved_status_pointer)
137
141
  #define RUBURPLE_SIGNAL_HANDLER(rb_ruburple_subscription,ruburple_signal_handler_pointer) Data_Get_Struct(rb_ruburple_subscription, RuburpleSignalHandler, ruburple_signal_handler_pointer)
138
142
  #define PURPLE_CONNECTION(rb_ruburple_protocol_connection,purple_connection_pointer) Data_Get_Struct(rb_ruburple_protocol_connection, PurpleConnection, purple_connection_pointer)
143
+ #define PURPLE_BUDDY(rb_ruburple_blist_buddy,purple_buddy_pointer) Data_Get_Struct(rb_ruburple_blist_buddy, PurpleBuddy, purple_buddy_pointer)
144
+ #define PURPLE_PRESENCE(rb_ruburple_blist_presence,purple_presence_pointer) Data_Get_Struct(rb_ruburple_blist_presence, PurplePresence, purple_presence_pointer)
145
+ #define PURPLE_STATUS(rb_ruburple_blist_status,purple_status_pointer) Data_Get_Struct(rb_ruburple_blist_status, PurpleStatus, purple_status_pointer)
139
146
  #define GPOINTER(rb_ruburple_pointer,gpointer) Data_Get_Struct(rb_ruburple_pointer, void, gpointer)
140
147
 
141
148
  /*
@@ -684,26 +691,6 @@ rb_ruburple_protocol_account_get_alias(VALUE self)
684
691
  return rb_str_new2(rval);
685
692
  }
686
693
 
687
- static gpointer
688
- ruburple_protocol_account_set_alias(gpointer data)
689
- {
690
- gpointer *args = (gpointer *) data;
691
- purple_account_set_alias((PurpleAccount *) args[0], (char *) args[1]);
692
- return NULL;
693
- }
694
-
695
- static VALUE
696
- rb_ruburple_protocol_account_set_alias(VALUE self, VALUE alias)
697
- {
698
- gpointer args[2];
699
- PurpleAccount *account;
700
- PURPLE_ACCOUNT(self, account);
701
- args[0] = (gpointer) account;
702
- args[1] = (gpointer) RSTRING(alias)->ptr;
703
- call_and_get_result(ruburple_protocol_account_set_alias, args);
704
- return Qnil;
705
- }
706
-
707
694
  static gpointer
708
695
  ruburple_protocol_account_set_savedstatus(gpointer data)
709
696
  {
@@ -1231,6 +1218,143 @@ rb_ruburple_protocol_connection_get_account(VALUE self)
1231
1218
  return RB_RUBURPLE_PROTOCOL_ACCOUNT((PurpleAccount *) call_and_get_result(ruburple_protocol_connection_get_account, (gpointer) plugin));
1232
1219
  }
1233
1220
 
1221
+ static gpointer
1222
+ ruburple_protocol_account_get_buddy(gpointer data)
1223
+ {
1224
+ gpointer *args = (gpointer *) data;
1225
+ return purple_find_buddy((PurpleAccount *) args[0], (char *) args[1]);
1226
+ }
1227
+
1228
+ static VALUE
1229
+ rb_ruburple_protocol_account_has_buddy(VALUE self, VALUE name)
1230
+ {
1231
+ PurpleAccount *account;
1232
+ gpointer args[2];
1233
+ PurpleBuddy *buddy;
1234
+ PURPLE_ACCOUNT(self, account);
1235
+ args[0] = (gpointer) account;
1236
+ args[1] = (gpointer) RSTRING(name)->ptr;
1237
+ buddy = (PurpleBuddy *) call_and_get_result(ruburple_protocol_account_get_buddy, args);
1238
+ return buddy == NULL ? Qfalse : Qtrue;
1239
+ }
1240
+
1241
+ static VALUE
1242
+ rb_ruburple_protocol_account_get_buddy(VALUE self, VALUE name)
1243
+ {
1244
+ PurpleAccount *account;
1245
+ gpointer args[2];
1246
+ PurpleBuddy *buddy;
1247
+ PURPLE_ACCOUNT(self, account);
1248
+ args[0] = (gpointer) account;
1249
+ args[1] = (gpointer) RSTRING(name)->ptr;
1250
+ buddy = (PurpleBuddy *) call_and_get_result(ruburple_protocol_account_get_buddy, args);
1251
+ RETURN_QNIL_IF_NULL(buddy);
1252
+ return RB_RUBURPLE_BLIST_BUDDY(buddy);
1253
+ }
1254
+
1255
+ static gpointer
1256
+ ruburple_protocol_account_get_buddies(gpointer data)
1257
+ {
1258
+ gpointer *args = (gpointer *) data;
1259
+ return purple_find_buddies((PurpleAccount *) args[0], (char *) args[1]);
1260
+ }
1261
+
1262
+ static VALUE
1263
+ rb_ruburple_protocol_account_get_buddies(int argc, VALUE *argv, VALUE self)
1264
+ {
1265
+ PurpleAccount *account;
1266
+ GList *iter;
1267
+ VALUE return_value = rb_ary_new();
1268
+ gpointer args[2];
1269
+
1270
+ PURPLE_ACCOUNT(self, account);
1271
+ args[0] = (gpointer) account;
1272
+ if (argc > 1)
1273
+ rb_raise(rb_eRuntimeError, "Ruburple::Protocol::Account#buddies(USERNAME = nil) takes at most 1 argument");
1274
+ else if (argc == 1)
1275
+ args[1] = RSTRING(argv[0])->ptr;
1276
+ else
1277
+ args[1] = NULL;
1278
+
1279
+ for (iter = (GList *) call_and_get_result(ruburple_protocol_account_get_buddies, args); iter; iter = iter->next) {
1280
+ rb_ary_push(return_value, RB_RUBURPLE_BLIST_BUDDY(iter->data));
1281
+ }
1282
+
1283
+ return return_value;
1284
+ }
1285
+
1286
+ static gpointer
1287
+ ruburple_blist_buddy_get_account(gpointer data)
1288
+ {
1289
+ return (gpointer) purple_buddy_get_account((PurpleBuddy *) data);
1290
+ }
1291
+
1292
+ static VALUE
1293
+ rb_ruburple_blist_buddy_get_account(VALUE self)
1294
+ {
1295
+ PurpleBuddy *buddy;
1296
+ PURPLE_BUDDY(self, buddy);
1297
+ return RB_RUBURPLE_PROTOCOL_ACCOUNT((PurpleAccount *) call_and_get_result(ruburple_blist_buddy_get_account, (gpointer) buddy));
1298
+ }
1299
+
1300
+ static gpointer
1301
+ ruburple_blist_buddy_get_name(gpointer data)
1302
+ {
1303
+ return (gpointer) purple_buddy_get_name((PurpleBuddy *) data);
1304
+ }
1305
+
1306
+ static VALUE
1307
+ rb_ruburple_blist_buddy_get_name(VALUE self)
1308
+ {
1309
+ PurpleBuddy *buddy;
1310
+ PURPLE_BUDDY(self, buddy);
1311
+ return rb_str_new2((char *) call_and_get_result(ruburple_blist_buddy_get_name, (gpointer) buddy));
1312
+ }
1313
+
1314
+ static gpointer
1315
+ ruburple_blist_buddy_get_presence(gpointer data)
1316
+ {
1317
+ return (gpointer) purple_buddy_get_presence((PurpleBuddy *) data);
1318
+ }
1319
+
1320
+ static VALUE
1321
+ rb_ruburple_blist_buddy_get_presence(VALUE self)
1322
+ {
1323
+ PurpleBuddy *buddy;
1324
+ PURPLE_BUDDY(self, buddy);
1325
+ return RB_RUBURPLE_BLIST_PRESENCE((PurplePresence *) call_and_get_result(ruburple_blist_buddy_get_presence, (gpointer) buddy));
1326
+ }
1327
+
1328
+ static gpointer
1329
+ ruburple_blist_presence_get_active_status(gpointer data)
1330
+ {
1331
+ PurplePresence *presence = (PurplePresence *) data;
1332
+ return purple_presence_get_active_status(presence);
1333
+ }
1334
+
1335
+ static VALUE
1336
+ rb_ruburple_blist_presence_get_active_status(VALUE self)
1337
+ {
1338
+ PurplePresence *presence;
1339
+ PURPLE_PRESENCE(self, presence);
1340
+ return RB_RUBURPLE_BLIST_STATUS((PurpleStatus *) call_and_get_result(ruburple_blist_presence_get_active_status, (gpointer) presence));
1341
+ }
1342
+
1343
+ static gpointer
1344
+ ruburple_blist_status_get_name(gpointer data)
1345
+ {
1346
+ PurpleStatus *status = (PurpleStatus *) data;
1347
+ return (gpointer) purple_status_get_name(status);
1348
+ }
1349
+
1350
+ static VALUE
1351
+ rb_ruburple_blist_status_get_name(VALUE self)
1352
+ {
1353
+ PurpleStatus *status;
1354
+ PURPLE_STATUS(self, status);
1355
+ return rb_str_new2((char *) call_and_get_result(ruburple_blist_status_get_name, (gpointer) status));
1356
+ }
1357
+
1234
1358
  #ifdef __cplusplus
1235
1359
  extern "C" {
1236
1360
  #endif
@@ -1323,7 +1447,9 @@ extern "C" {
1323
1447
  rb_define_method(rb_ruburple_protocol_account, "username", rb_ruburple_protocol_account_get_username, 0);
1324
1448
  rb_define_method(rb_ruburple_protocol_account, "password", rb_ruburple_protocol_account_get_password, 0);
1325
1449
  rb_define_method(rb_ruburple_protocol_account, "alias", rb_ruburple_protocol_account_get_alias, 0);
1326
- rb_define_method(rb_ruburple_protocol_account, "alias=", rb_ruburple_protocol_account_set_alias, 1);
1450
+ rb_define_method(rb_ruburple_protocol_account, "has_buddy?", rb_ruburple_protocol_account_has_buddy, 1);
1451
+ rb_define_method(rb_ruburple_protocol_account, "get_buddy", rb_ruburple_protocol_account_get_buddy, 1);
1452
+ rb_define_method(rb_ruburple_protocol_account, "buddies", rb_ruburple_protocol_account_get_buddies, -1);
1327
1453
 
1328
1454
  rb_ruburple_protocol_account_conversation = rb_define_class_under(rb_ruburple_protocol_account, "Conversation", rb_cObject);
1329
1455
 
@@ -1334,6 +1460,7 @@ extern "C" {
1334
1460
  rb_ruburple_blist = rb_define_class_under(rb_ruburple, "BuddyList", rb_cObject);
1335
1461
 
1336
1462
  rb_ruburple_blist_status = rb_define_class_under(rb_ruburple_blist, "Status", rb_cObject);
1463
+ rb_define_method(rb_ruburple_blist_status, "name", rb_ruburple_blist_status_get_name, 0);
1337
1464
  rb_define_const(rb_ruburple_blist_status, "STATUS_UNSET", INT2NUM(PURPLE_STATUS_UNSET));
1338
1465
  rb_define_const(rb_ruburple_blist_status, "STATUS_OFFLINE", INT2NUM(PURPLE_STATUS_OFFLINE));
1339
1466
  rb_define_const(rb_ruburple_blist_status, "STATUS_AVAILABLE", INT2NUM(PURPLE_STATUS_AVAILABLE));
@@ -1352,9 +1479,19 @@ extern "C" {
1352
1479
 
1353
1480
  rb_ruburple_blist_node = rb_define_class_under(rb_ruburple_blist, "Node", rb_cObject);
1354
1481
 
1355
- rb_ruburple_blist_buddy = rb_define_class_under(rb_ruburple_blist, "Buddy", rb_cObject);
1482
+ rb_ruburple_blist_buddy = rb_define_class_under(rb_ruburple_blist, "Buddy", rb_ruburple_blist_node);
1483
+ rb_define_method(rb_ruburple_blist_buddy, "account", rb_ruburple_blist_buddy_get_account, 0);
1484
+ rb_define_method(rb_ruburple_blist_buddy, "name", rb_ruburple_blist_buddy_get_name, 0);
1485
+ rb_define_method(rb_ruburple_blist_buddy, "presence", rb_ruburple_blist_buddy_get_presence, 0);
1486
+
1487
+ rb_ruburple_blist_presence = rb_define_class_under(rb_ruburple_blist, "Presence", rb_cObject);
1488
+ rb_define_method(rb_ruburple_blist_presence, "active_status", rb_ruburple_blist_presence_get_active_status, 0);
1489
+
1490
+ rb_ruburple_blist_group = rb_define_class_under(rb_ruburple_blist, "Group", rb_ruburple_blist_node);
1491
+
1492
+ rb_ruburple_blist_contact = rb_define_class_under(rb_ruburple_blist, "Contact", rb_ruburple_blist_node);
1356
1493
 
1357
- rb_ruburple_blist_group = rb_define_class_under(rb_ruburple_blist, "Group", rb_cObject);
1494
+ rb_ruburple_blist_chat = rb_define_class_under(rb_ruburple_blist, "Chat", rb_ruburple_blist_node);
1358
1495
 
1359
1496
  rb_ruburple_blist_buddy_icon = rb_define_class_under(rb_ruburple_blist, "BuddyIcon", rb_cObject);
1360
1497
 
@@ -10,7 +10,9 @@ class RuburpleTest < Test::Unit::TestCase
10
10
 
11
11
  @@events = {}
12
12
 
13
+ puts "testing init..."
13
14
  Ruburple::init
15
+ puts "testing subscribe..."
14
16
  Ruburple::subscribe(:signed_on, (Proc.new do |c|
15
17
  puts "got signed_on from #{c.account.username}"
16
18
  @@events[:signed_on] << c
@@ -27,28 +29,51 @@ class RuburpleTest < Test::Unit::TestCase
27
29
  }
28
30
  end
29
31
 
30
- def test_msn
31
- test_operations("MSN")
32
+ def test_protocols
33
+ $TEST_ACCOUNTS.keys.each do |key|
34
+ test_operations(key)
35
+ end
32
36
  end
33
37
 
34
38
  private
35
39
 
36
40
  def test_operations(protocol)
41
+ puts "testing #{protocol}..."
37
42
  test_accounts = $TEST_ACCOUNTS[protocol]
38
43
  p = Ruburple::get_protocol(protocol)
44
+ puts "testing sign on..."
39
45
  a1 = p.get_account(test_accounts.first.username, test_accounts.first.password)
40
- a1.connect
41
46
  a2 = p.get_account(test_accounts.last.username, test_accounts.last.password)
42
- a2.connect
43
- puts "testing sign on..."
47
+ a1.connect
44
48
  assert_within(30) do
45
- a1_signed_on = @@events[:signed_on].find do |e|
46
- e.account.username == test_accounts.first.username
49
+ @@events[:signed_on].find do |e|
50
+ e.account.username == a1.username
47
51
  end
48
- a2_signed_on = @@events[:signed_on].find do |e|
49
- e.account.username == test_accounts.last.username
52
+ end
53
+ puts "testing buddies..."
54
+ assert(a1.has_buddy?(a2.username))
55
+ assert(buddy2 = a1.buddies.find do |b|
56
+ b.name == a2.username
57
+ end)
58
+ puts "testing presence..."
59
+ assert_equal("Offline", buddy2.presence.active_status.name)
60
+ a2.connect
61
+ assert_within(30) do
62
+ @@events[:signed_on].find do |e|
63
+ e.account.username == a2.username
50
64
  end
51
- a1_signed_on && a2_signed_on
65
+ end
66
+ puts "testing buddies..."
67
+ assert(a2.has_buddy?(a1.username))
68
+ assert(buddy1 = a2.buddies.find do |b|
69
+ b.name == a1.username
70
+ end)
71
+ puts "testing presence..."
72
+ assert_within(30) do
73
+ buddy1.presence.active_status.name == "Available"
74
+ end
75
+ assert_within(30) do
76
+ buddy2.presence.active_status.name == "Available"
52
77
  end
53
78
  puts "testing send im..."
54
79
  a1.connection.send_im(a2.username, "hello a2")
@@ -62,6 +87,14 @@ class RuburpleTest < Test::Unit::TestCase
62
87
  end
63
88
  a1_got_message && a2_got_message
64
89
  end
90
+ puts "testing close..."
91
+ a1.connection.close
92
+ puts "testing presence..."
93
+ assert_within(30) do
94
+ buddy1.presence.active_status.name == "Offline"
95
+ end
96
+ puts "testing close..."
97
+ a2.connection.close
65
98
  end
66
99
 
67
100
 
@@ -1,4 +1,7 @@
1
1
 
2
+ #
3
+ # These accounts should be on each others buddy lists for the tests to run.
4
+ #
2
5
  $TEST_ACCOUNTS = {
3
6
  "MSN" => [
4
7
  TestAccount.new("MSN", "some@msn.account", "some_msn_password"),
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ruburple
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
6
+ version: 0.0.5
7
7
  date: 2007-05-07 00:00:00 +02:00
8
8
  summary: An ruby extension to libpurple.
9
9
  require_paths: