Merge lp:~robru/libfriends/urlshorten into lp:libfriends

Proposed by Robert Bruce Park
Status: Merged
Merged at revision: 41
Proposed branch: lp:~robru/libfriends/urlshorten
Merge into: lp:libfriends
Prerequisite: lp:~robru/libfriends/explicit-api
Diff against target: 285 lines (+69/-81)
6 files modified
examples/example-vala.vala (+4/-4)
gtk/entry.vala (+2/-4)
src/Makefile.am (+0/-1)
src/service.vala (+41/-0)
src/urlshorten.vala (+0/-70)
tests/vala/test-service.vala (+22/-2)
To merge this branch: bzr merge lp:~robru/libfriends/urlshorten
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Robert Bruce Park Approve
Review via email: mp+142401@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks good! Now that Friends.Service has tests, please add a test for urlshorten to tests/vala/test-service.vala.

review: Needs Fixing
lp:~robru/libfriends/urlshorten updated
37. By Robert Bruce Park

Merge trunk and add test coverage for urlshorten.

Revision history for this message
Robert Bruce Park (robru) wrote :

Ok, so I had to remove some instances of service.do() from the example file, and in the process I discovered that we were missing service.retweet, so I had to add those in order for this to even compile, but it looks good now so please merge ;-)

review: Approve
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Thanks!

review: Approve
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/example-vala.vala'
2--- examples/example-vala.vala 2013-01-07 21:28:53 +0000
3+++ examples/example-vala.vala 2013-01-08 22:23:20 +0000
4@@ -69,7 +69,7 @@
5 uint acct = int.parse(args[i+1]);
6 string id = args[i+2];
7 stdout.printf("Liked...\n");
8- service.do("like", acct, id);
9+ service.like(acct, id);
10 } else {
11 PrintUsage ();
12 }
13@@ -82,7 +82,7 @@
14 uint acct = int.parse(args[i+1]);
15 string id = args[i+2];
16 stdout.printf("Unliked...\n");
17- service.do("unlike", acct, id);
18+ service.unlike(acct, id);
19 } else {
20 PrintUsage ();
21 }
22@@ -95,7 +95,7 @@
23 uint acct = int.parse(args[i+1]);
24 string id = args[i+2];
25 stdout.printf("Retweet...\n");
26- service.do("retweet", acct, id);
27+ service.retweet(acct, id);
28 } else {
29 PrintUsage ();
30 }
31@@ -126,7 +126,7 @@
32 return;
33 }
34 for(int i=1; i<args.length; i++) {
35- if (args[i] == "--send-message")
36+ if (args[i] == "--send-message")
37 if (args[i+1] != null && args[i+2] != null) {
38 string message = args[i+1];
39 uint acct = int.parse(args[i+2]);
40
41=== modified file 'gtk/entry.vala'
42--- gtk/entry.vala 2013-01-07 15:41:30 +0000
43+++ gtk/entry.vala 2013-01-08 22:23:20 +0000
44@@ -75,7 +75,7 @@
45 /**
46 * Widget that displays an entry which posts status updates to
47 * your social network accounts using friends-service. The entry
48- * is very simple and does not include any of the frills
49+ * is very simple and does not include any of the frills
50 * of {@link FriendsGtk.Entry}.
51 *
52 * @since 0.1
53@@ -122,7 +122,6 @@
54 * {@link Friends.Service}
55 */
56 private Friends.Service service;
57- private Friends.URLShorten urlshorten;
58
59 private Gdk.Color fg_color;
60 private Gdk.Color error_color;
61@@ -147,7 +146,6 @@
62 construct
63 {
64 service = new Friends.Service ();
65- urlshorten = new Friends.URLShorten ();
66
67 unowned Gtk.BindingSet binding_set;
68 binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ());
69@@ -253,7 +251,7 @@
70 {
71 var buf = get_buffer ();
72 Signal.stop_emission_by_name (buf, "insert-text") ;
73- var shrt = urlshorten.shorten (text);
74+ var shrt = service.shorten (text);
75 last_was_shortened = true;
76 buf.insert (ref iter, shrt, -1);
77 }
78
79=== modified file 'src/Makefile.am'
80--- src/Makefile.am 2012-12-10 20:46:09 +0000
81+++ src/Makefile.am 2013-01-08 22:23:20 +0000
82@@ -6,7 +6,6 @@
83
84 libfriends_la_SOURCES = \
85 service.vala \
86- urlshorten.vala \
87 utils.vala \
88 $(NULL)
89
90
91=== modified file 'src/service.vala'
92--- src/service.vala 2013-01-08 22:23:20 +0000
93+++ src/service.vala 2013-01-08 22:23:20 +0000
94@@ -27,6 +27,7 @@
95 public abstract void Do (string action, string account_id, string message_id) throws GLib.IOError;
96 public abstract async void Upload (string account_id, string uri, string description, out string result_url) throws GLib.IOError;
97 public abstract void ClearIndicators () throws GLib.IOError;
98+ public abstract string URLShorten (string url) throws GLib.IOError;
99 public abstract string GetFeatures (string protocol) throws GLib.IOError;
100 public signal void ConnectionOffline ();
101 public signal void ConnectionOnline ();
102@@ -225,6 +226,25 @@
103 }
104
105 /**
106+ * Retweet an existing tweet.
107+ *
108+ * @param account_id The {@link Ag.Account.id} to fetch.
109+ * @param message_id The id of the message you want to reshare.
110+ * @return ``true`` for success, ``false`` otherwise
111+ *
112+ * @since 0.1
113+ */
114+ public bool retweet(uint account_id, string message_id)
115+ {
116+ try {
117+ return do("retweet", account_id.to_string(), message_id);
118+ } catch (GLib.Error e) {
119+ warning (e.message);
120+ }
121+ return false;
122+ }
123+
124+ /**
125 * Fetch the messages from the user's "home" screen. On
126 * Facebook and Twitter this maps to the main feed you see on
127 * the front page; public posts by people you follow but not
128@@ -370,6 +390,27 @@
129 }
130
131 /**
132+ * Pass any URL to this method and it will shorten it for you.
133+ *
134+ * @param url The long URL you need shortened.
135+ * @return The shortened URL.
136+ *
137+ * @since 0.1
138+ */
139+ public string shorten(string url)
140+ {
141+ try
142+ {
143+ return service.URLShorten(url);
144+ }
145+ catch (GLib.IOError e)
146+ {
147+ warning (e.message);
148+ return url;
149+ }
150+ }
151+
152+ /**
153 * This method returns a list of all the possible actions
154 * supported by a given protocol. This can be used to
155 * determine what actions can be triggered by the ``do``
156
157=== removed file 'src/urlshorten.vala'
158--- src/urlshorten.vala 2013-01-04 23:30:46 +0000
159+++ src/urlshorten.vala 1970-01-01 00:00:00 +0000
160@@ -1,70 +0,0 @@
161-/*
162- * Copyright(C) 2012 Canonical Ltd.
163- *
164- * This library is free software; you can redistribute it and/or modify
165- * it under the terms of the GNU Lesser General Public License
166- * version 3.0 as published by the Free Software Foundation.
167- *
168- * This library is distributed in the hope that it will be useful,
169- * but WITHOUT ANY WARRANTY; without even the implied warranty of
170- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
171- * GNU Lesser General Public License version 3.0 for more details.
172- *
173- * You should have received a copy of the GNU Lesser General Public
174- * License along with this library. If not, see
175- * <http://www.gnu.org/licenses/>.
176- *
177- * Authored by Ken VaDine <ken.vandine@canonical.com>
178- */
179-
180-[DBus (name = "com.canonical.Friends.URLShorten")]
181-private interface URLShortenInterface : Object {
182- public abstract string Shorten (string url) throws GLib.IOError;
183-}
184-
185-[CCode (gir_namespace = "Friends", gir_version = "0.1")]
186-namespace Friends
187-{
188- public class URLShorten : Object
189- {
190- private const string url_name = "com.canonical.Friends.URLShorten";
191- private const string url_path = "/com/canonical/friends/URLShorten";
192-
193- private URLShortenInterface url_service;
194-
195- construct
196- {
197- try
198- {
199- url_service = Bus.get_proxy_sync(BusType.SESSION,
200- url_name,
201- url_path);
202- }
203- catch (GLib.IOError e)
204- {
205- warning ("Unable to get Friends URLShorten: "+e.message);
206- }
207- }
208-
209-
210- /**
211- * Pass any URL to this method and it will shorten it for you.
212- *
213- * @param url The long URL you need shortened.
214- *
215- * @since 0.1
216- */
217- public string shorten(string url)
218- {
219- try
220- {
221- return url_service.Shorten(url);
222- }
223- catch (GLib.IOError e)
224- {
225- warning (e.message);
226- return "Failed";
227- }
228- }
229- }
230-}
231
232=== modified file 'tests/vala/test-service.vala'
233--- tests/vala/test-service.vala 2013-01-08 21:47:44 +0000
234+++ tests/vala/test-service.vala 2013-01-08 22:23:20 +0000
235@@ -27,7 +27,7 @@
236 {
237 var dbusmock = new DBusMock ();
238 /* Add mock methods to the dbus interface for testing
239- * python-dbusmock docs can be found at
240+ * python-dbusmock docs can be found at
241 * http://bazaar.launchpad.net/~pitti/python-dbusmock/trunk/view/head:/README.rst
242 */
243 dbusmock.add_method ("Refresh", "", "", "");
244@@ -38,6 +38,7 @@
245 dbusmock.add_method ("Do", "sss", "", "");
246 dbusmock.add_method ("Upload", "sss", "s", "ret = 'https://something.com/test.jpg'");
247 dbusmock.add_method ("ClearIndicators", "", "", "");
248+ dbusmock.add_method ("URLShorten", "s", "s", "ret = 'http://is.gd/short'");
249
250 GLib.Test.add_data_func ("/Unit/Friends/Service/Refresh",
251 ServiceSuite.test_refresh);
252@@ -56,7 +57,8 @@
253 ServiceSuite.test_send_reply);
254 GLib.Test.add_data_func ("/Unit/Friends/Service/ClearIndicators",
255 ServiceSuite.test_clear_indicators);
256-
257+ GLib.Test.add_data_func ("/Unit/Friends/Service/URLShorten",
258+ ServiceSuite.test_url_shorten);
259 }
260
261 internal static void test_refresh ()
262@@ -195,5 +197,23 @@
263 }
264 assert (success == true);
265 }
266+
267+ internal static void test_url_shorten ()
268+ {
269+ var service = new Friends.Service ();
270+ bool success = false;
271+ string result = "";
272+ try
273+ {
274+ result = service.shorten ("http://example.com/really/really/long");
275+ success = true;
276+ }
277+ catch (GLib.IOError e)
278+ {
279+ warning ("Failed to shorten URL - %s", e.message);
280+ }
281+ assert (success == true);
282+ assert (result == "http://is.gd/short");
283+ }
284 }
285 }

Subscribers

People subscribed via source and target branches