public
Description: A Clutter-based Twitter client
Homepage: http://live.gnome.org/Tweet
Clone URL: git://github.com/ebassi/tweet.git
Search Repo:
Emmanuele Bassi (author)
Sat Apr 19 07:29:41 -0700 2008
commit  a643edaaa7ba328cf4f24356dbeb5c2faa5837e3
tree    a002d1ab1d3439fcbbd514ce3b803f4d8e216866
parent  455bcf01d7cb8a5c84630024c693349a9c06dafe
tweet / tests / test-status-send.c
100644 115 lines (88 sloc) 2.439 kb
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
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <twitter-glib/twitter-glib.h>
 
static GMainLoop *main_loop = NULL;
 
static gboolean
authenticate_cb (TwitterClient *client,
                 TwitterAuthState state,
                 gpointer user_data)
{
  g_print ("Authenticating...\n");
 
  return TRUE;
}
 
static void
status_received_cb (TwitterClient *client,
                    TwitterStatus *status,
                    const GError *error,
                    gpointer user_data)
{
  TwitterUser *user;
 
  if (error)
    {
      g_print ("Unable to send the status: %s\n", error->message);
 
      if (g_main_loop_is_running (main_loop))
        g_main_loop_quit (main_loop);
 
      return;
    }
 
  g_assert (TWITTER_IS_STATUS (status));
 
  user = twitter_status_get_user (status);
  if (!user)
    return;
 
  g_print ("<%s> %s\n"
           "\t-- created at: %s\n",
           twitter_user_get_name (user),
           twitter_status_get_text (status),
           twitter_status_get_created_at (status));
}
 
typedef struct {
  gchar *text;
  TwitterClient *client;
} SendStatusClosure;
 
static gboolean
send_status (gpointer data)
{
  SendStatusClosure *closure = data;
 
  twitter_client_add_status (closure->client, closure->text);
 
  g_free (closure->text);
  g_free (closure);
 
  return FALSE;
}
 
static gboolean
timeout_quit (gpointer data)
{
  if (g_main_loop_is_running (main_loop))
    g_main_loop_quit (main_loop);
 
  return FALSE;
}
 
int
main (int argc,
      char *argv[])
{
  TwitterClient *client;
  SendStatusClosure *closure;
 
  g_type_init ();
  g_thread_init (NULL);
 
  if (argc < 4)
    {
      g_print ("Usage: test-status-send <email> <password> <text>\n");
      return EXIT_FAILURE;
    }
 
  client = twitter_client_new_for_user (argv[1], argv[2]);
  g_signal_connect (client, "authenticate",
                    G_CALLBACK (authenticate_cb),
                    NULL);
  g_signal_connect (client, "status-received",
                    G_CALLBACK (status_received_cb),
                    NULL);
 
  main_loop = g_main_loop_new (NULL, FALSE);
 
  closure = g_new (SendStatusClosure, 1);
  closure->client = client;
  closure->text = g_strdup (argv[3]);
 
  g_timeout_add_seconds (1, send_status, closure);
  g_timeout_add_seconds (10, timeout_quit, NULL);
 
  g_main_loop_run (main_loop);
 
  g_object_unref (client);
  g_main_loop_unref (main_loop);
 
  return EXIT_SUCCESS;
}