2
* Copyright (C) 2013 Bastien Nocera <hadess@hadess.net>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General
15
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17
* Author: Bastien Nocera <hadess@hadess.net>
22
#define GOA_API_IS_SUBJECT_TO_CHANGE
25
#include <rest/rest-proxy.h>
26
#include <rest/rest-proxy-call.h>
29
main (int argc, char **argv)
34
GoaAccount *account = NULL;
35
GoaOAuth2Based *oauth2 = NULL;
36
char *access_token = NULL;
40
const char *tweet_id = NULL;
42
if (argc != 2 && argc != 3) {
43
g_print ("Usage: %s URL [TWEET ID]\n", argv[0]);
50
client = goa_client_new_sync (NULL, &error);
52
g_error ("Could not create GoaClient: %s", error->message);
56
accounts = goa_client_get_accounts (client);
58
/* Find a Pocket account */
59
for (l = accounts; l != NULL; l = l->next) {
60
GoaObject *object = GOA_OBJECT (l->data);
62
account = goa_object_peek_account (object);
63
if (g_strcmp0 (goa_account_get_provider_type (account), "pocket") == 0) {
64
g_object_ref (account);
65
oauth2 = goa_object_get_oauth2_based (object);
70
g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
75
if (!goa_oauth2_based_call_get_access_token_sync (oauth2, &access_token, NULL, NULL, &error)) {
76
g_error ("Could not get access token: %s", error->message);
80
g_print ("Got access tokens\n");
82
proxy = rest_proxy_new ("https://getpocket.com/", FALSE);
83
call = rest_proxy_new_call (proxy);
84
rest_proxy_call_set_method (call, "POST");
85
rest_proxy_call_set_function (call, "v3/add");
86
rest_proxy_call_add_param (call, "consumer_key", goa_oauth2_based_get_client_id (oauth2));
87
rest_proxy_call_add_param (call, "access_token", access_token);
88
rest_proxy_call_add_param (call, "url", url);
90
rest_proxy_call_add_param (call, "tweet_id", tweet_id);
92
g_print ("Adding to Pocket...\n");
94
if (!rest_proxy_call_sync (call, &error)) {
95
g_error ("Cannot add to Pocket: %s", error->message);