68a2ab36be4e2d83e2626076b4ab324b0b409080
[maevies] / examples / gtranslate.cpp
1 #include <iostream>
2 #include <rest/rest/rest-proxy.h>
3 #include <glib.h>
4 #include <unistd.h>
5
6 using namespace std;
7
8 int main(int argc, char **argv)
9 {
10         GError *error = NULL;
11         RestProxy *proxy;
12         RestProxyCall *call;
13         GMainLoop *loop;
14         const gchar *payload;
15         const char *text;
16         gssize len;
17
18         g_thread_init (NULL);
19         g_type_init ();
20
21         if (argc>1)
22         {
23                 text=argv[1];
24         }
25         else
26         {
27                 text="Hola Mundo";
28         }
29         
30         proxy = rest_proxy_new ("http://ajax.googleapis.com/ajax/services/language/translate", FALSE);
31         call = rest_proxy_new_call (proxy);
32
33         rest_proxy_call_add_params (call,
34                               "v", "1.0",
35                               "q", text,
36                               "langpair", "es|en",
37                               NULL);
38         rest_proxy_call_run (call, NULL, NULL);
39
40         payload = rest_proxy_call_get_payload (call);
41         len = rest_proxy_call_get_payload_length (call);
42         write (1, payload, len);
43         cout << endl;
44
45         g_object_unref (call);
46         g_object_unref (proxy);
47 }