public
Description: A Clutter-based Twitter client
Homepage: http://live.gnome.org/Tweet
Clone URL: git://github.com/ebassi/tweet.git
Search Repo:
Huge overhauling of TwitterClient

Use the new Twitter API functions and remove the exposure of the
TwitterTimeline and TwitterUserList objects.

TwitterClient will emit a ::status-received and a ::user-received
each time a new Status and User object are received, respectively.
If we get a collection of statuses or users, we schedule a lazy
emission using a loop over an idle handler. This should keep the
library as much asynchronous as possible, and with as little
overhead as possible as well.

Warning: the reference counting hell is dangerously near; needs
testing.

TwitterClient still has gaping holes in it, but the tests we wrote
earlier work correctly, and it's possible to read and write statuses.
Emmanuele Bassi (author)
Thu Apr 10 13:47:12 -0700 2008
commit  f6ee8549f0d87063ff656c0903478ec54febb27b
tree    8d2bbf24dc93c5e9e6e2b858a9dae10c587ed9a4
parent  9a3d1704859f75941ae0d80f8348e11cf6b1099d
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
...
18
19
20
 
 
21
22
23
24
25
26
27
28
 
29
30
31
32
33
34
35
36
37
38
...
58
59
60
61
62
 
63
64
65
66
...
91
92
93
 
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
...
100
101
102
 
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
105
106
107
108
...
138
139
140
141
142
 
 
143
144
145
 
146
147
148
149
 
150
151
152
153
154
155
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
 
 
198
199
 
 
 
 
 
 
 
 
200
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
211
212
213
 
 
 
 
 
 
 
 
 
 
 
 
214
215
216
217
 
 
 
 
 
218
219
220
221
 
 
 
222
223
224
 
225
226
 
 
227
228
229
230
 
231
232
233
 
234
235
236
237
 
 
238
239
240
241
242
 
 
 
 
 
243
244
 
 
 
 
 
 
 
245
246
247
 
 
 
 
 
 
 
 
248
249
250
 
 
 
 
251
252
253
 
 
 
 
254
255
 
 
 
 
256
257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
259
260
261
 
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
297
298
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
301
302
303
304
305
 
306
307
308
309
 
310
311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
313
314
 
315
316
 
 
 
317
318
 
 
319
320
321
322
323
 
324
325
326
327
328
329
 
 
 
 
 
330
331
332
333
334
335
336
337
 
338
339
340
341
342
343
344
345
346
347
 
348
349
 
 
350
351
352
353
354
 
 
355
356
357
358
 
359
360
361
362
363
364
...
363
364
365
366
 
367
368
369
370
371
372
373
374
375
 
376
377
378
379
380
381
382
 
383
384
385
386
387
388
389
390
391
392
393
...
392
393
394
395
 
396
397
398
399
400
401
402
403
404
 
405
406
407
408
409
410
411
412
413
414
415
416
 
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
...
430
431
432
433
 
434
435
436
437
438
439
440
441
442
 
443
444
445
446
447
448
449
450
451
452
453
454
 
455
456
 
457
458
459
 
 
 
 
 
460
461
 
 
 
 
 
 
 
 
 
 
 
 
462
463
464
465
466
 
 
467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
469
 
470
471
472
473
474
 
475
476
477
 
478
479
480
481
 
482
483
 
484
485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
...
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
...
57
58
59
60
61
62
63
64
65
 
66
67
68
69
70
 
 
 
 
 
71
72
73
74
...
94
95
96
 
97
98
99
100
101
102
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
206
207
208
 
 
209
210
211
212
 
213
214
215
216
 
217
218
219
220
221
222
223
...
243
244
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
247
248
249
250
251
252
 
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
 
 
 
302
303
304
305
306
307
 
 
 
308
309
310
311
 
 
312
313
 
314
315
316
 
 
 
317
318
 
 
319
320
321
322
 
323
324
325
 
 
 
 
326
327
328
329
330
331
 
332
333
334
335
336
337
338
339
 
 
340
341
342
343
344
345
346
347
348
 
 
349
350
351
352
353
 
 
354
355
356
357
358
 
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
 
 
 
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
...
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
 
 
 
 
 
523
524
 
 
 
525
526
 
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
 
 
566
567
 
568
569
570
571
 
572
573
574
575
576
 
 
577
578
 
 
 
 
 
579
580
581
582
583
584
 
 
 
 
 
 
 
585
586
 
 
 
 
 
 
 
 
 
587
588
 
589
590
591
 
 
 
 
592
593
594
 
 
 
595
596
597
598
599
600
601
...
600
601
602
 
603
604
605
606
 
 
 
 
 
 
607
608
609
610
611
612
613
 
614
615
616
 
 
617
618
619
620
621
622
623
...
622
623
624
 
625
626
627
628
 
 
 
 
 
 
629
630
 
 
 
 
 
631
632
633
634
635
 
636
637
638
 
 
 
 
 
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
...
645
646
647
 
648
649
650
651
 
 
 
 
 
 
652
653
 
 
 
 
 
654
655
656
657
658
 
659
660
661
662
663
 
 
664
665
666
667
668
669
 
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
 
 
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
 
739
740
741
742
743
 
744
745
746
 
747
748
749
750
 
751
752
753
754
755
 
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
0
@@ -1,3 +1,42 @@
0
+/* twitter-client.h: Wrapper for the Twitter API
0
+ * Copyright (C) 2008 Emmanuele Bassi <ebassi@gnome.org>
0
+ *
0
+ * This file is part of Twitter-GLib.
0
+ *
0
+ * This library is free software; you can redistribute it and/or
0
+ * modify it under the terms of the GNU Lesser General Public
0
+ * License as published by the Free Software Foundation; either
0
+ * version 2 of the License, or (at your option) any later version.
0
+ *
0
+ * This library is distributed in the hope that it will be useful,
0
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0
+ * Lesser General Public License for more details.
0
+ */
0
+
0
+/**
0
+ * SECTION:twitter-client
0
+ * @short_description: Wrapper for the Twitter API
0
+ *
0
+ * #TwitterClient is the main object wrapping the details of the
0
+ * Twitter web API.
0
+ *
0
+ * In order to use Twitter through #TwitterClient, a new instance
0
+ * should be created using twitter_client_new() or
0
+ * twitter_client_new_for_user(). #TwitterClient handles every
0
+ * operation asynchronously, thus requiring a #GMainLoop running.
0
+ * Every result will emit one of the #TwitterClient signals; in
0
+ * case of error, the #GError parameter of the signals will be
0
+ * set.
0
+ *
0
+ * Authentication is handled automatically by setting the
0
+ * TwitterClient:email and TwitterClient:password properties.
0
+ * These two properties can be set at construction time or by
0
+ * using twitter_client_set_user(). Interactive authentication
0
+ * can be implemented by using the TwitterClient::authenticate
0
+ * signal as well.
0
+ */
0
+
0
 #ifdef HAVE_CONFIG_H
0
 #include "config.h"
0
 #endif
0
0
0
0
@@ -18,20 +57,17 @@
0
 
0
 #include <libsoup/soup.h>
0
 
0
+#include "twitter-api.h"
0
+#include "twitter-client.h"
0
 #include "twitter-common.h"
0
 #include "twitter-enum-types.h"
0
 #include "twitter-marshal.h"
0
 #include "twitter-private.h"
0
-#include "twitter-client.h"
0
 #include "twitter-status.h"
0
 #include "twitter-timeline.h"
0
 #include "twitter-user.h"
0
+#include "twitter-user-list.h"
0
 
0
-#define TWITTER_API_PUBLIC_TIMELINE "http://twitter.com/statuses/public_timeline.json"
0
-#define TWITTER_API_FRIENDS_TIMELINE "http://twitter.com/statuses/friends_timeline"
0
-#define TWITTER_API_USER_TIMELINE "http://twitter.com/statuses/user_timeline"
0
-#define TWITTER_API_SHOW "http://twitter.com/statuses/show/"
0
-
0
 #define TWITTER_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TWITTER_TYPE_CLIENT, TwitterClientPrivate))
0
 
0
 struct _TwitterClientPrivate
0
0
@@ -58,8 +94,8 @@
0
 enum
0
 {
0
   AUTHENTICATE,
0
- TIMELINE_RECEIVED,
0
   STATUS_RECEIVED,
0
+ USER_RECEIVED,
0
 
0
   LAST_SIGNAL
0
 };
0
0
@@ -91,7 +127,24 @@
0
                              const GValue *value,
0
                              GParamSpec *pspec)
0
 {
0
+ TwitterClientPrivate *priv = TWITTER_CLIENT (gobject)->priv;
0
 
0
+ switch (prop_id)
0
+ {
0
+ case PROP_EMAIL:
0
+ g_free (priv->email);
0
+ priv->email = g_value_dup_string (value);
0
+ break;
0
+
0
+ case PROP_PASSWORD:
0
+ g_free (priv->password);
0
+ priv->password = g_value_dup_string (value);
0
+ break;
0
+
0
+ default:
0
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
0
+ break;
0
+ }
0
 }
0
 
0
 static void
0
0
@@ -100,7 +153,22 @@
0
                              GValue *value,
0
                              GParamSpec *pspec)
0
 {
0
+ TwitterClientPrivate *priv = TWITTER_CLIENT (gobject)->priv;
0
 
0
+ switch (prop_id)
0
+ {
0
+ case PROP_EMAIL:
0
+ g_value_set_string (value, priv->email);
0
+ break;
0
+
0
+ case PROP_PASSWORD:
0
+ g_value_set_string (value, priv->password);
0
+ break;
0
+
0
+ default:
0
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
0
+ break;
0
+ }
0
 }
0
 
0
 static void
0
0
0
@@ -138,15 +206,15 @@
0
                   _twitter_marshal_BOOLEAN__ENUM,
0
                   G_TYPE_BOOLEAN, 1,
0
                   TWITTER_TYPE_AUTH_STATE);
0
- client_signals[TIMELINE_RECEIVED] =
0
- g_signal_new ("timeline-received",
0
+ client_signals[USER_RECEIVED] =
0
+ g_signal_new ("user-received",
0
                   G_TYPE_FROM_CLASS (gobject_class),
0
                   G_SIGNAL_RUN_LAST,
0
- G_STRUCT_OFFSET (TwitterClientClass, timeline_received),
0
+ G_STRUCT_OFFSET (TwitterClientClass, user_received),
0
                   NULL, NULL,
0
                   _twitter_marshal_VOID__OBJECT_POINTER,
0
                   G_TYPE_NONE, 2,
0
- TWITTER_TYPE_TIMELINE,
0
+ TWITTER_TYPE_USER,
0
                   G_TYPE_POINTER);
0
   client_signals[STATUS_RECEIVED] =
0
     g_signal_new ("status-received",
0
0
0
0
@@ -175,30 +243,37 @@
0
                                          NULL);
0
 }
0
 
0
-TwitterClient *
0
-twitter_client_new (void)
0
-{
0
- return g_object_new (TWITTER_TYPE_CLIENT, NULL);
0
-}
0
-
0
-TwitterClient *
0
-twitter_client_new_for_user (const gchar *email,
0
- const gchar *password)
0
-{
0
- return g_object_new (TWITTER_TYPE_CLIENT,
0
- "email", email,
0
- "password", password,
0
- NULL);
0
-}
0
-
0
 typedef enum {
0
   PUBLIC_TIMELINE,
0
   FRIENDS_TIMELINE,
0
   USER_TIMELINE,
0
+ STATUS_SHOW,
0
+ UPDATE,
0
   REPLIES,
0
- SHOW
0
+ DESTROY,
0
+ FRIENDS,
0
+ FOLLOWERS,
0
+ FEATURED,
0
+ VERIFY_CREDENTIALS,
0
+ END_SESSION,
0
+
0
+ N_CLIENT_ACTIONS
0
 } ClientAction;
0
 
0
+static const gchar *action_names[N_CLIENT_ACTIONS] = {
0
+ "public-timeline",
0
+ "friends-timeline",
0
+ "user-timeline",
0
+ "status-show",
0
+ "update",
0
+ "replies",
0
+ "destroy",
0
+ "friends",
0
+ "followers",
0
+ "verify-credentials",
0
+ "end-session"
0
+};
0
+
0
 typedef struct {
0
   ClientAction action;
0
   TwitterClient *client;
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
@@ -211,55 +286,161 @@
0
   TwitterStatus *status;
0
 } GetStatusClosure;
0
 
0
+typedef struct {
0
+ ClientAction action;
0
+ TwitterClient *client;
0
+ TwitterUserList *user_list;
0
+} GetUserListClosure;
0
+
0
+typedef struct {
0
+ ClientAction action;
0
+ TwitterClient *client;
0
+ TwitterUser *user;
0
+} GetUserClosure;
0
+
0
 static void
0
-get_timeline_cb (SoupSession *session,
0
- SoupMessage *msg,
0
- gpointer user_data)
0
+twitter_client_auth (SoupSession *session,
0
+ SoupMessage *msg,
0
+ SoupAuth *auth,
0
+ gboolean retrying,
0
+ gpointer user_data)
0
 {
0
- GetTimelineClosure *closure = user_data;
0
- TwitterClient *client = closure->client;
0
- guint status;
0
+ TwitterClient *client = user_data;
0
+ TwitterClientPrivate *priv = client->priv;
0
+ gboolean retval = FALSE;
0
 
0
- status = msg->status_code;
0
- if (!SOUP_STATUS_IS_SUCCESSFUL (status))
0
+ if (!retrying)
0
     {
0
- GError *error = NULL;
0
+ g_signal_emit (client, client_signals[AUTHENTICATE], 0,
0
+ TWITTER_AUTH_NEGOTIATING, &retval);
0
 
0
- g_set_error (&error, TWITTER_ERROR,
0
- twitter_error_from_status (status),
0
- msg->reason_phrase);
0
+ soup_auth_authenticate (auth, priv->email, priv->password);
0
 
0
- g_signal_emit (client, client_signals[TIMELINE_RECEIVED], 0,
0
- closure->timeline, error);
0
+ priv->auth_complete = TRUE;
0
     }
0
   else
0
     {
0
- gchar *buffer;
0
+ g_signal_emit (client, client_signals[AUTHENTICATE], 0,
0
+ TWITTER_AUTH_RETRY, &retval);
0
 
0
- buffer = g_strndup (msg->response_body->data,
0
- msg->response_body->length);
0
- if (G_UNLIKELY (!buffer))
0
- g_warning ("No data received");
0
+ if (G_LIKELY (retval))
0
+ {
0
+ soup_auth_authenticate (auth, priv->email, priv->password);
0
+ priv->auth_complete = TRUE;
0
+ }
0
       else
0
- twitter_timeline_load_from_data (closure->timeline, buffer);
0
+ {
0
+ g_signal_emit (client, client_signals[AUTHENTICATE], 0,
0
+ TWITTER_AUTH_FAILED, &retval);
0
+ priv->auth_complete = FALSE;
0
+ }
0
+ }
0
+}
0
 
0
- g_signal_emit (client, client_signals[TIMELINE_RECEIVED], 0,
0
- closure->timeline, NULL);
0
+static void
0
+twitter_client_queue_message (TwitterClient *client,
0
+ SoupMessage *msg,
0
+ gboolean requires_auth,
0
+ SoupSessionCallback callback,
0
+ gpointer data)
0
+{
0
+ TwitterClientPrivate *priv = client->priv;
0
 
0
- g_free (buffer);
0
- }
0
+ if (requires_auth && !priv->auth_id)
0
+ priv->auth_id = g_signal_connect (priv->session_async, "authenticate",
0
+ G_CALLBACK (twitter_client_auth),
0
+ client);
0
 
0
- g_object_unref (closure->timeline);
0
- g_object_unref (closure->client);
0
+ soup_session_queue_message (priv->session_async, msg,
0
+ callback,
0
+ data);
0
+}
0
 
0
- g_free (closure);
0
+TwitterClient *
0
+twitter_client_new (void)
0
+{
0
+ return g_object_new (TWITTER_TYPE_CLIENT, NULL);
0
 }
0
 
0
+TwitterClient *
0
+twitter_client_new_for_user (const gchar *email,
0
+ const gchar *password)
0
+{
0
+ return g_object_new (TWITTER_TYPE_CLIENT,
0
+ "email", email,
0
+ "password", password,
0
+ NULL);
0
+}
0
+
0
+void
0
+twitter_client_set_user (TwitterClient *client,
0
+ const gchar *email,
0
+ const gchar *password)
0
+{
0
+ TwitterClientPrivate *priv;
0
+
0
+ g_return_if_fail (TWITTER_IS_CLIENT (client));
0
+ g_return_if_fail (email != NULL);
0
+ g_return_if_fail (password != NULL);
0
+
0
+ priv = client->priv;
0
+
0
+ g_free (priv->email);
0
+ g_free (priv->password);
0
+
0
+ priv->email = g_strdup (email);
0
+ priv->password = g_strdup (password);
0
+
0
+ priv->auth_complete = FALSE;
0
+
0
+ g_object_notify (G_OBJECT (client), "email");
0
+ g_object_notify (G_OBJECT (client), "password");
0
+}
0
+
0
+void
0
+twitter_client_get_user (TwitterClient *client,
0
+ gchar **email,
0
+ gchar **password)
0
+{
0
+ g_return_if_fail (TWITTER_IS_CLIENT (client));
0
+
0
+ if (email)
0
+ *email = g_strdup (client->priv->email);
0
+ if (password)
0
+ *password = g_strdup (client->priv->password);
0
+}
0
+
0
+typedef struct {
0
+ TwitterClient *client;
0
+ GList *users;
0
+ guint n_users;
0
+ guint current_user;
0
+} EmitUserClosure;
0
+
0
+static gboolean
0
+do_emit_user_received (gpointer data)
0
+{
0
+ return FALSE;
0
+}
0
+
0
 static void
0
-get_status_cb (SoupSession *session,
0
- SoupMessage *msg,
0
- gpointer user_data)
0
+cleanup_emit_user_received (gpointer data)
0
 {
0
+
0
+}
0
+
0
+static void
0
+emit_user_received (TwitterClient *client,
0
+ TwitterUserList *list)
0
+{
0
+
0
+}
0
+
0
+static void
0
+get_user_cb (SoupSession *session,
0
+ SoupMessage *msg,
0
+ gpointer user_data)
0
+{
0
   GetStatusClosure *closure = user_data;
0
   TwitterClient *client = closure->client;
0
 
0
0
0
0
0
0
0
0
0
0
0
0
0
0
@@ -297,65 +478,121 @@
0
   g_free (closure);
0
 }
0
 
0
+void
0
+twitter_client_verify_user (TwitterClient *client)
0
+{
0
+
0
+}
0
+
0
+void
0
+twitter_client_end_session (TwitterClient *client)
0
+{
0
+
0
+}
0
+
0
+typedef struct {
0
+ TwitterClient *client;
0
+ TwitterTimeline *timeline;
0
+ guint n_status;
0
+ guint current_status;
0
+} EmitStatusClosure;
0
+
0
+static gboolean
0
+do_emit_status_received (gpointer data)
0
+{
0
+ EmitStatusClosure *closure = data;
0
+ TwitterStatus *status;
0
+
0
+ status = twitter_timeline_get_pos (closure->timeline,
0
+ closure->current_status);
0
+ if (!status)
0
+ return FALSE;
0
+
0
+ g_signal_emit (closure->client, client_signals[STATUS_RECEIVED], 0,
0
+ status, NULL);
0
+
0
+ closure->current_status += 1;
0
+
0
+ if (closure->current_status == closure->n_status)
0
+ return FALSE;
0
+
0
+ return TRUE;
0
+}
0
+
0
 static void
0
-twitter_client_auth (SoupSession *session,
0
- SoupMessage *msg,
0
- SoupAuth *auth,
0
- gboolean retrying,
0
- gpointer user_data)
0
+cleanup_emit_status_received (gpointer data)
0
 {
0
- TwitterClient *client = user_data;
0
- TwitterClientPrivate *priv = client->priv;
0
- gboolean retval = FALSE;
0
+ EmitStatusClosure *closure = data;
0
 
0
- if (!retrying)
0
+ g_object_unref (closure->client);
0
+ g_object_unref (closure->timeline);
0
+
0
+ g_free (closure);
0
+}
0
+
0
+static void
0
+emit_status_received (TwitterClient *client,
0
+ TwitterTimeline *timeline)
0
+{
0
+ EmitStatusClosure *closure;
0
+ guint count;
0
+
0
+ count = twitter_timeline_get_count (timeline);
0
+
0
+ closure = g_new (EmitStatusClosure, 1);
0
+ closure->client = g_object_ref (client);
0
+ closure->timeline = g_object_ref (timeline);
0
+ closure->n_status = count;
0
+ closure->current_status = 0;
0
+
0
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
0
+ do_emit_status_received,
0
+ closure,
0
+ cleanup_emit_status_received);
0
+}
0
+
0
+static void
0
+get_timeline_cb (SoupSession *session,
0
+ SoupMessage *msg,
0
+ gpointer user_data)
0
+{
0
+ GetTimelineClosure *closure = user_data;
0
+ TwitterClient *client = closure->client;
0
+ guint status;
0
+
0
+ status = msg->status_code;
0
+ if (!SOUP_STATUS_IS_SUCCESSFUL (status))
0
     {
0
- g_signal_emit (client, client_signals[AUTHENTICATE], 0,
0
- TWITTER_AUTH_NEGOTIATING, &retval);
0
+ GError *error = NULL;
0
 
0
- soup_auth_authenticate (auth, priv->email, priv->password);
0
+ g_set_error (&error, TWITTER_ERROR,
0
+ twitter_error_from_status (status),
0
+ msg->reason_phrase);
0
 
0
- priv->auth_complete = TRUE;
0
+ g_signal_emit (client, client_signals[STATUS_RECEIVED], 0,
0
+ NULL, error);
0
     }
0
   else
0
     {
0
- g_signal_emit (client, client_signals[AUTHENTICATE], 0,
0
- TWITTER_AUTH_RETRY, &retval);
0
+ gchar *buffer;
0
 
0
- if (G_LIKELY (retval))
0
- {
0
- soup_auth_authenticate (auth, priv->email, priv->password);
0
- priv->auth_complete = TRUE;
0
- }
0
+ buffer = g_strndup (msg->response_body->data,
0
+ msg->response_body->length);
0
+
0
+ if (G_UNLIKELY (!buffer))
0
+ g_warning ("No data received");
0
       else
0
- {
0
- g_signal_emit (client, client_signals[AUTHENTICATE], 0,
0
- TWITTER_AUTH_FAILED, &retval);
0
- priv->auth_complete = FALSE;
0
- }
0
- }
0
-}
0
+ twitter_timeline_load_from_data (closure->timeline, buffer);
0
 
0
-static void
0
-twitter_client_queue_message (TwitterClient *client,
0
- const gchar *url,
0
- gboolean requires_auth,
0
- SoupSessionCallback callback,
0
- gpointer data)
0
-{
0
- TwitterClientPrivate *priv = client->priv;
0
- SoupMessage *msg;
0
+ emit_status_received (closure->client, closure->timeline);
0
 
0
- msg = soup_message_new (SOUP_METHOD_GET, url);
0
+ g_free (buffer);
0
+ }
0
 
0
- if (requires_auth && !priv->auth_id)
0
- priv->auth_id = g_signal_connect (priv->session_async, "authenticate",
0
- G_CALLBACK (twitter_client_auth),
0
- client);
0
+ g_object_unref (closure->timeline);
0
+ g_object_unref (closure->client);
0
 
0
- soup_session_queue_message (priv->session_async, msg,
0
- callback,
0
- data);
0
+ g_free (closure);
0
 }
0
 
0
 void
0
0
0
0
@@ -363,27 +600,20 @@
0
                                     guint since_id)
0
 {
0
   GetTimelineClosure *clos;
0
- gchar *url;
0
+ SoupMessage *msg;
0
 
0
   g_return_if_fail (TWITTER_IS_CLIENT (client));
0
 
0
- if (since_id > 0)