public
Description: A Clutter-based Twitter client
Homepage: http://live.gnome.org/Tweet
Clone URL: git://github.com/ebassi/tweet.git
Search Repo:
Simple test case for the status command

This test case sends a status using the status command and the
authentication.

Like the user-timeline test, this unit never runs more than
ten seconds.
Emmanuele Bassi (author)
Thu Apr 10 13:23:07 -0700 2008
commit  1b5f36224ac979ff4f0f624bca33301d95e4ca70
tree    80bc56e1d4be1171badeda5fcc134a23a4257054
parent  6b1ca6f34af56aa7ed0430a260fc3ac3ebc6c093
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
0
@@ -1 +1,116 @@
0
+#include <stdio.h>
0
+#include <stdlib.h>
0
+#include <glib.h>
0
+#include <twitter-glib/twitter-glib.h>
0
+
0
+static GMainLoop *main_loop = NULL;
0
+
0
+static gboolean
0
+authenticate_cb (TwitterClient *client,
0
+ TwitterAuthState state,
0
+ gpointer user_data)
0
+{
0
+ g_print ("Authenticating...\n");
0
+
0
+ return TRUE;
0
+}
0
+
0
+static void
0
+status_received_cb (TwitterClient *client,
0
+ TwitterStatus *status,
0
+ const GError *error,
0
+ gpointer user_data)
0
+{
0
+ TwitterUser *user;
0
+
0
+ if (error)
0
+ {
0
+ g_print ("Unable to send the status: %s\n", error->message);
0
+
0
+ if (g_main_loop_is_running (main_loop))
0
+ g_main_loop_quit (main_loop);
0
+
0
+ return;
0
+ }
0
+
0
+ g_assert (TWITTER_IS_STATUS (status));
0
+
0
+ user = twitter_status_get_user (status);
0
+ if (!user)
0
+ return;
0
+
0
+ g_print ("<%s> %s\n"
0
+ "\t-- created at: %s\n",
0
+ twitter_user_get_name (user),
0
+ twitter_status_get_text (status),
0
+ twitter_status_get_created_at (status));
0
+}
0
+
0
+typedef struct {
0
+ gchar *text;
0
+ TwitterClient *client;
0
+} SendStatusClosure;
0
+
0
+static gboolean
0
+send_status (gpointer data)
0
+{
0
+ SendStatusClosure *closure = data;
0
+
0
+ twitter_client_add_status (closure->client, closure->text);
0
+
0
+ g_free (closure->text);
0
+ g_free (closure);
0
+
0
+ return FALSE;
0
+}
0
+
0
+static gboolean
0
+timeout_quit (gpointer data)
0
+{
0
+ if (g_main_loop_is_running (main_loop))
0
+ g_main_loop_quit (main_loop);
0
+
0
+ return FALSE;
0
+}
0
+
0
+int
0
+main (int argc,
0
+ char *argv[])
0
+{
0
+ TwitterClient *client;
0
+ SendStatusClosure *closure;
0
+
0
+ g_type_init ();
0
+ g_thread_init (NULL);
0
+
0
+ if (argc < 4)
0
+ {
0
+ g_print ("Usage: test-status-send <email> <password> <text>\n");
0
+ return EXIT_FAILURE;
0
+ }
0
+
0
+ client = twitter_client_new_for_user (argv[1], argv[2]);
0
+ g_signal_connect (client, "authenticate",
0
+ G_CALLBACK (authenticate_cb),
0
+ NULL);
0
+ g_signal_connect (client, "status-received",
0
+ G_CALLBACK (status_received_cb),
0
+ NULL);
0
+
0
+ main_loop = g_main_loop_new (NULL, FALSE);
0
+
0
+ closure = g_new (SendStatusClosure, 1);
0
+ closure->client = client;
0
+ closure->text = g_strdup (argv[3]);
0
+
0
+ g_timeout_add_seconds (1, send_status, closure);
0
+ g_timeout_add_seconds (10, timeout_quit, NULL);
0
+
0
+ g_main_loop_run (main_loop);
0
+
0
+ g_object_unref (client);
0
+ g_main_loop_unref (main_loop);
0
+
0
+ return EXIT_SUCCESS;
0
+}

Comments

    No one has commented yet.