Moved the examples folder to the trunk (as the examples should be related to the...
authorspenap <bulfaiter@gmail.com>
Tue, 27 Oct 2009 20:27:28 +0000 (20:27 +0000)
committerspenap <bulfaiter@gmail.com>
Tue, 27 Oct 2009 20:27:28 +0000 (20:27 +0000)
would affect an example)

Created a simple Makefile to get the sample compiling and linking.

git-svn-id: file:///svnroot/maevies/trunk@4 a96798e0-47ce-444a-94a4-1d14e63744fc

examples/Makefile [new file with mode: 0644]
examples/gtranslate.cpp [new file with mode: 0644]

diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644 (file)
index 0000000..5ab5c43
--- /dev/null
@@ -0,0 +1,16 @@
+CC = g++
+
+LIBS = `pkg-config rest --libs`
+
+FLAGS = `pkg-config rest --cflags`
+
+gtranslate: gtranslate.o
+       $(CC) -o gtranslate gtranslate.o $(LIBS)
+
+gtranslate.o: gtranslate.cpp
+       $(CC) -c gtranslate.cpp $(FLAGS)
+
+all: gtranslate
+
+clean:
+       rm -rf gtranslate gtranslate.o *~
diff --git a/examples/gtranslate.cpp b/examples/gtranslate.cpp
new file mode 100644 (file)
index 0000000..68a2ab3
--- /dev/null
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <rest/rest/rest-proxy.h>
+#include <glib.h>
+#include <unistd.h>
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+        GError *error = NULL;
+        RestProxy *proxy;
+        RestProxyCall *call;
+        GMainLoop *loop;
+       const gchar *payload;
+       const char *text;
+       gssize len;
+
+        g_thread_init (NULL);
+        g_type_init ();
+
+       if (argc>1)
+       {
+               text=argv[1];
+       }
+       else
+       {
+               text="Hola Mundo";
+       }
+       
+       proxy = rest_proxy_new ("http://ajax.googleapis.com/ajax/services/language/translate", FALSE);
+        call = rest_proxy_new_call (proxy);
+
+       rest_proxy_call_add_params (call,
+                              "v", "1.0",
+                              "q", text,
+                              "langpair", "es|en",
+                              NULL);
+       rest_proxy_call_run (call, NULL, NULL);
+
+       payload = rest_proxy_call_get_payload (call);
+       len = rest_proxy_call_get_payload_length (call);
+       write (1, payload, len);
+       cout << endl;
+
+       g_object_unref (call);
+       g_object_unref (proxy);
+}