diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/continuous-twitter.c | 90 | ||||
-rw-r--r-- | examples/demo/demo-rest-page.c | 165 | ||||
-rw-r--r-- | examples/demo/demo-rest-page.ui | 73 | ||||
-rw-r--r-- | examples/meson.build | 3 | ||||
-rw-r--r-- | examples/post-twitter-media.c | 101 | ||||
-rw-r--r-- | examples/post-twitter.c | 77 |
6 files changed, 1 insertions, 508 deletions
diff --git a/examples/continuous-twitter.c b/examples/continuous-twitter.c deleted file mode 100644 index 7a915e0..0000000 --- a/examples/continuous-twitter.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford <rob@linux.intel.com> - * Ross Burton <ross@linux.intel.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU Lesser General Public License, - * version 2.1, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include <rest/oauth-proxy.h> -#include <stdio.h> - -static void -_call_continous_cb (RestProxyCall *call, - const gchar *buf, - gsize len, - const GError *error, - GObject *weak_object, - gpointer userdata) -{ - g_message ("%s", buf); -} - -int -main (int argc, char **argv) -{ - RestProxy *proxy; - RestProxyCall *call; - GError *error = NULL; - char pin[256]; - GMainLoop *loop; - - loop = g_main_loop_new (NULL, FALSE); - - /* Create the proxy */ - proxy = oauth_proxy_new ("UfXFxDbUjk41scg0kmkFwA", - "pYQlfI2ZQ1zVK0f01dnfhFTWzizBGDnhNJIw6xwto", - "https://api.twitter.com/", FALSE); - - /* First stage authentication, this gets a request token */ - if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) - g_error ("Cannot get request token: %s", error->message); - - /* From the token construct a URL for the user to visit */ - g_print ("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", - oauth_proxy_get_token (OAUTH_PROXY (proxy))); - - fgets (pin, sizeof (pin), stdin); - g_strchomp (pin); - - /* Second stage authentication, this gets an access token */ - if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) - g_error ("Cannot get access token: %s", error->message); - - /* We're now authenticated */ - - /* Post the status message */ - call = rest_proxy_new_call (proxy); - g_object_set (proxy, "url-format", "http://stream.twitter.com/", NULL); - rest_proxy_call_set_function (call, "1/statuses/filter.json"); - rest_proxy_call_set_method (call, "GET"); - rest_proxy_call_add_param (call, "track", "Cameron"); - rest_proxy_call_add_param (call, "delimited", "length"); - - rest_proxy_call_continuous (call, - _call_continous_cb, - NULL, - NULL, - NULL); - - g_main_loop_run (loop); - - g_object_unref (call); - g_object_unref (proxy); - - return 0; -} diff --git a/examples/demo/demo-rest-page.c b/examples/demo/demo-rest-page.c index e36fee7..d33d7b6 100644 --- a/examples/demo/demo-rest-page.c +++ b/examples/demo/demo-rest-page.c @@ -52,12 +52,6 @@ struct _DemoRestPage GtkWidget *digest_username; GtkWidget *digest_password; - /* oauth 1 auth */ - GtkWidget *oauth1_client_identifier; - GtkWidget *oauth1_client_secret; - GtkWidget *oauth1_get_access_token; - RestProxy *oauth1_proxy; - /* oauth 2 auth */ GtkWidget *oauth2_client_identifier; GtkWidget *oauth2_client_secret; @@ -73,7 +67,6 @@ typedef enum { AUTHMODE_NO, AUTHMODE_BASIC, AUTHMODE_DIGEST, - AUTHMODE_OAUTH1, AUTHMODE_OAUTH2 } AuthMode; @@ -90,7 +83,6 @@ demo_rest_page_finalize (GObject *object) { DemoRestPage *self = (DemoRestPage *)object; - g_clear_object (&self->oauth1_proxy); g_clear_object (&self->oauth2_proxy); g_clear_pointer (&self->pkce, rest_pkce_code_challenge_free); @@ -111,8 +103,6 @@ get_current_auth_mode (DemoRestPage *self) return AUTHMODE_BASIC; else if (g_strcmp0 (stack_name, "digest") == 0) return AUTHMODE_DIGEST; - else if (g_strcmp0 (stack_name, "oauth1") == 0) - return AUTHMODE_OAUTH1; else if (g_strcmp0 (stack_name, "oauth2") == 0) return AUTHMODE_OAUTH2; @@ -135,9 +125,7 @@ set_oauth_btn_active (DemoRestPage *self, { gtk_button_set_label (btn, "Get access token..."); gtk_widget_set_css_classes (GTK_WIDGET (btn), (const char*[]){ "suggested-action", NULL }); - if (proxy == self->oauth1_proxy) - g_clear_object (&self->oauth1_proxy); - else if (proxy == self->oauth2_proxy) + if (proxy == self->oauth2_proxy) g_clear_object (&self->oauth2_proxy); } } @@ -196,23 +184,6 @@ set_text_response (DemoRestPage *self, } static void -demo_rest_page_fetched_oauth1_access_token (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - DemoRestPage *self = (DemoRestPage *)user_data; - RestProxy *proxy = (RestProxy *)object; - g_autoptr(GError) error = NULL; - - g_assert (G_IS_OBJECT (object)); - g_assert (G_IS_ASYNC_RESULT (result)); - - oauth_proxy_access_token_finish (OAUTH_PROXY (proxy), result, &error); - if (error) - set_oauth_btn_active (self, GTK_BUTTON (self->oauth1_get_access_token), proxy, FALSE); -} - -static void demo_rest_page_fetched_oauth2_access_token (GObject *object, GAsyncResult *result, gpointer user_data) @@ -232,35 +203,6 @@ demo_rest_page_fetched_oauth2_access_token (GObject *object, } static void -oauth1_dialog_response (GtkDialog *dialog, - gint response_id, - DemoRestPage *self) -{ - switch (response_id) - { - case GTK_RESPONSE_OK: - { - const gchar *verifier = NULL; - GtkWidget *content_area = gtk_dialog_get_content_area (dialog); - GtkWidget *box = gtk_widget_get_first_child (content_area); - GtkWidget *entry = gtk_widget_get_last_child (box); - - verifier = gtk_editable_get_text (GTK_EDITABLE (entry)); - oauth_proxy_access_token_async (OAUTH_PROXY (self->oauth1_proxy), - "access_token", - verifier, - NULL, - demo_rest_page_fetched_oauth1_access_token, - self); - break; - } - case GTK_RESPONSE_CANCEL: - set_oauth_btn_active (self, GTK_BUTTON (self->oauth1_get_access_token), self->oauth1_proxy, FALSE); - break; - } -} - -static void oauth2_dialog_response (GtkDialog *dialog, gint response_id, DemoRestPage *self) @@ -290,48 +232,6 @@ oauth2_dialog_response (GtkDialog *dialog, } static GtkWidget * -demo_rest_page_create_oauth1_dialog (DemoRestPage *self, - RestProxy *proxy) -{ - GtkWidget *dialog = NULL; - GtkWidget *content_area; - GtkWidget *box, *lbl, *token_lbl, *verifier_entry; - g_autofree char *token_str = NULL; - - dialog = gtk_dialog_new_with_buttons ("Get Verifier...", - GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR, - "Ok", - GTK_RESPONSE_OK, - "Cancel", - GTK_RESPONSE_CANCEL, - NULL); - - content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); - gtk_widget_set_margin_top (content_area, 6); - gtk_widget_set_margin_start (content_area, 6); - gtk_widget_set_margin_bottom (content_area, 6); - gtk_widget_set_margin_end (content_area, 6); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - lbl = gtk_label_new ("Open a browser and authorize this application..."); - gtk_box_append (GTK_BOX (box), lbl); - token_str = g_strdup_printf ("Use this token: %s", oauth_proxy_get_token (OAUTH_PROXY (proxy))); - token_lbl = gtk_label_new (token_str); - gtk_label_set_selectable (GTK_LABEL (token_lbl), TRUE); - gtk_box_append (GTK_BOX (box), token_lbl); - verifier_entry = gtk_entry_new (); - gtk_box_append (GTK_BOX (box), verifier_entry); - - gtk_box_append (GTK_BOX (content_area), box); - - g_signal_connect (dialog, "response", G_CALLBACK (oauth1_dialog_response), self); - g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_window_destroy), dialog); - - return dialog; -} - -static GtkWidget * demo_rest_page_create_oauth2_dialog (DemoRestPage *self, RestProxy *proxy) { @@ -378,57 +278,6 @@ demo_rest_page_create_oauth2_dialog (DemoRestPage *self, } static void -demo_rest_page_fetched_oauth1_request_token (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - DemoRestPage *self = (DemoRestPage *)user_data; - RestProxy *proxy = (RestProxy *)object; - GtkWidget *dialog = NULL; - g_autoptr(GError) error = NULL; - - g_assert (G_IS_OBJECT (object)); - g_assert (G_IS_ASYNC_RESULT (result)); - - oauth_proxy_request_token_finish (OAUTH_PROXY (proxy), result, &error); - if (error) - { - set_oauth_btn_active (self, GTK_BUTTON (self->oauth1_get_access_token), proxy, FALSE); - return; - } - - /* here we show a dialog requesting the user to a browser for authentication */ - dialog = demo_rest_page_create_oauth1_dialog (self, proxy); - - gtk_widget_show (dialog); -} - -static void -on_oauth1_get_access_token_clicked (GtkButton *btn, - gpointer user_data) -{ - DemoRestPage *self = (DemoRestPage *)user_data; - const char *url = NULL; - const char *consumer_key = NULL, *consumer_secret = NULL; - const char *function = NULL; - - if (self->oauth1_proxy != NULL) - { - set_oauth_btn_active (self, btn, self->oauth1_proxy, FALSE); - return; - } - - url = gtk_editable_get_text (GTK_EDITABLE (self->host)); - consumer_key = gtk_editable_get_text (GTK_EDITABLE (self->oauth1_client_identifier)); - consumer_secret = gtk_editable_get_text (GTK_EDITABLE (self->oauth1_client_secret)); - function = gtk_editable_get_text (GTK_EDITABLE (self->function)); - - self->oauth1_proxy = oauth_proxy_new (consumer_key, consumer_secret, url, FALSE); - oauth_proxy_request_token_async (OAUTH_PROXY (self->oauth1_proxy), function, "https://www.gnome.org", NULL, demo_rest_page_fetched_oauth1_request_token, self); - set_oauth_btn_active (self, btn, self->oauth1_proxy, TRUE); -} - -static void on_oauth2_get_access_token_clicked (GtkButton *btn, gpointer user_data) { @@ -533,13 +382,6 @@ on_send_clicked (GtkButton *btn, proxy = rest_proxy_new_with_authentication (url, FALSE, username, password); break; } - case AUTHMODE_OAUTH1: - { - g_object_set (self->oauth1_proxy, "url-format", url, NULL); - proxy = self->oauth1_proxy; - - break; - } case AUTHMODE_OAUTH2: { proxy = rest_proxy_new (url, FALSE); @@ -620,10 +462,6 @@ demo_rest_page_class_init (DemoRestPageClass *klass) /* digest auth */ gtk_widget_class_bind_template_child (widget_class, DemoRestPage, digest_username); gtk_widget_class_bind_template_child (widget_class, DemoRestPage, digest_password); - /* oauth 1 auth */ - gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth1_client_identifier); - gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth1_client_secret); - gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth1_get_access_token); /* oauth 2 auth */ gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth2_client_identifier); gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth2_client_secret); @@ -635,7 +473,6 @@ demo_rest_page_class_init (DemoRestPageClass *klass) /* callbacks */ gtk_widget_class_bind_template_callback (widget_class, on_send_clicked); gtk_widget_class_bind_template_callback (widget_class, on_auth_method_activated); - gtk_widget_class_bind_template_callback (widget_class, on_oauth1_get_access_token_clicked); gtk_widget_class_bind_template_callback (widget_class, on_oauth2_get_access_token_clicked); } diff --git a/examples/demo/demo-rest-page.ui b/examples/demo/demo-rest-page.ui index a5771c8..3bfc004 100644 --- a/examples/demo/demo-rest-page.ui +++ b/examples/demo/demo-rest-page.ui @@ -81,7 +81,6 @@ <item>No Auth</item> <item>Basic</item> <item>Digest</item> - <item>OAuth1</item> <item>OAuth2</item> </items> </object> @@ -199,78 +198,6 @@ </child> <child> <object class="GtkStackPage"> - <property name="name">oauth1</property> - <property name="child"> - <object class="GtkGrid"> - <property name="column-spacing">8</property> - <property name="row-spacing">6</property> - <child> - <object class="GtkLabel"> - <property name="hexpand">true</property> - <property name="label">Client Identifier:</property> - <property name="xalign">1.0</property> - <layout> - <property name="column">0</property> - <property name="row">0</property> - </layout> - </object> - </child> - <child> - <object class="GtkEntry" id="oauth1_client_identifier"> - <property name="hexpand">true</property> - <layout> - <property name="column">1</property> - <property name="row">0</property> - </layout> - </object> - </child> - <child> - <object class="GtkImage"> - <property name="icon-name">dialog-question-symbolic</property> - <property name="tooltip-text">Typically the consumer key and secret can be obtained from the oauth provider.</property> - <layout> - <property name="column">2</property> - <property name="row">0</property> - </layout> - </object> - </child> - <child> - <object class="GtkLabel"> - <property name="label">Client Secret:</property> - <property name="xalign">1.0</property> - <layout> - <property name="column">0</property> - <property name="row">1</property> - </layout> - </object> - </child> - <child> - <object class="GtkEntry" id="oauth1_client_secret"> - <layout> - <property name="column">1</property> - <property name="row">1</property> - </layout> - </object> - </child> - <child> - <object class="GtkButton" id="oauth1_get_access_token"> - <property name="label">Get access token...</property> - <layout> - <property name="column">1</property> - <property name="row">2</property> - </layout> - <signal name="clicked" handler="on_oauth1_get_access_token_clicked" swapped="no" object="DemoRestPage"/> - <style> - <class name="suggested-action"/> - </style> - </object> - </child> - </object> - </property> - </object> - </child> - <child> - <object class="GtkStackPage"> <property name="name">oauth2</property> <property name="child"> <object class="GtkGrid"> diff --git a/examples/meson.build b/examples/meson.build index 37ea0ca..34c8f33 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -2,11 +2,8 @@ example_names = [ 'test-raw', 'test-xml', 'dump-xml', - 'post-twitter', - 'post-twitter-media', 'get-flickr-favorites', 'lastfm-shout', - 'continuous-twitter', 'gitlab-oauth2-example', ] diff --git a/examples/post-twitter-media.c b/examples/post-twitter-media.c deleted file mode 100644 index afae309..0000000 --- a/examples/post-twitter-media.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford <rob@linux.intel.com> - * Ross Burton <ross@linux.intel.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU Lesser General Public License, - * version 2.1, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include <rest/oauth-proxy.h> -#include <stdio.h> - - -int -main (int argc, char **argv) -{ - RestProxy *proxy; - RestProxyCall *call; - RestParam *img_param; - GError *error = NULL; - char pin[256]; - gsize length; - gchar *contents; - - if (argc != 2) { - g_printerr ("$ post-twitter-media \"message\"\n"); - return -1; - } - - /* Create the proxy */ - proxy = oauth_proxy_new ("UfXFxDbUjk41scg0kmkFwA", - "pYQlfI2ZQ1zVK0f01dnfhFTWzizBGDnhNJIw6xwto", - "https://api.twitter.com/", FALSE); - - /* First stage authentication, this gets a request token */ - if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) - g_error ("Cannot get request token: %s", error->message); - - /* From the token construct a URL for the user to visit */ - g_print ("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", - oauth_proxy_get_token (OAUTH_PROXY (proxy))); - - - fgets (pin, sizeof(pin), stdin); - g_strchomp (pin); - - - /* Second stage authentication, this gets an access token */ - if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) - g_error ("Cannot get access token: %s", error->message); - - /* We're now authenticated */ - - - /* In order to send an image to twitter, we first need to load it ourselves. */ - if (!g_file_get_contents("test-media.png", &contents, &length, NULL)){ - g_error("reading file failed."); - return -1; - } - - - /* Create the multipart/form-data parameter */ - img_param = rest_param_new_full("media[]", REST_MEMORY_COPY, contents, - length, "multipart/form-data", "test-media.png"); - - - /* Post the status message */ - call = rest_proxy_new_call (REST_PROXY(proxy)); - rest_proxy_call_set_function (call, "1.1/statuses/update_with_media.json"); - rest_proxy_call_set_method (call, "POST"); - rest_proxy_call_add_param (call, "status", argv[1]); - rest_proxy_call_add_param_full(call, img_param); - - if (!rest_proxy_call_sync (call, &error)) { - g_message("Return Code: %u", rest_proxy_call_get_status_code(call)); - g_message("Payload: %s", rest_proxy_call_get_payload(call)); - g_error ("Cannot make call: %s", error->message); - } - - /* TODO: parse the XML and print something useful */ - g_print ("%s\n", rest_proxy_call_get_payload (call)); - - g_object_unref (call); - g_object_unref (proxy); - g_free (contents); - - return 0; -} diff --git a/examples/post-twitter.c b/examples/post-twitter.c deleted file mode 100644 index d87eb24..0000000 --- a/examples/post-twitter.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford <rob@linux.intel.com> - * Ross Burton <ross@linux.intel.com> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU Lesser General Public License, - * version 2.1, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include <rest/oauth-proxy.h> -#include <stdio.h> - -int -main (int argc, char **argv) -{ - RestProxy *proxy; - RestProxyCall *call; - GError *error = NULL; - char pin[256]; - - if (argc != 2) { - g_printerr ("$ post-twitter \"message\"\n"); - return 1; - } - - /* Create the proxy */ - proxy = oauth_proxy_new ("UfXFxDbUjk41scg0kmkFwA", - "pYQlfI2ZQ1zVK0f01dnfhFTWzizBGDnhNJIw6xwto", - "https://api.twitter.com/", FALSE); - - /* First stage authentication, this gets a request token */ - if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) - g_error ("Cannot get request token: %s", error->message); - - /* From the token construct a URL for the user to visit */ - g_print ("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", - oauth_proxy_get_token (OAUTH_PROXY (proxy))); - - fgets (pin, sizeof (pin), stdin); - g_strchomp (pin); - - /* Second stage authentication, this gets an access token */ - if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) - g_error ("Cannot get access token: %s", error->message); - - /* We're now authenticated */ - - /* Post the status message */ - call = rest_proxy_new_call (proxy); - rest_proxy_call_set_function (call, "1/statuses/update.xml"); - rest_proxy_call_set_method (call, "POST"); - rest_proxy_call_add_param (call, "status", argv[1]); - - if (!rest_proxy_call_sync (call, &error)) - g_error ("Cannot make call: %s", error->message); - - /* TODO: parse the XML and print something useful */ - g_print ("%s\n", rest_proxy_call_get_payload (call)); - - g_object_unref (call); - g_object_unref (proxy); - - return 0; -} |