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
=== modified file 'examples/example-vala.vala'
--- examples/example-vala.vala 2013-01-07 21:28:53 +0000
+++ examples/example-vala.vala 2013-01-08 22:23:20 +0000
@@ -69,7 +69,7 @@
69 uint acct = int.parse(args[i+1]);69 uint acct = int.parse(args[i+1]);
70 string id = args[i+2];70 string id = args[i+2];
71 stdout.printf("Liked...\n");71 stdout.printf("Liked...\n");
72 service.do("like", acct, id);72 service.like(acct, id);
73 } else {73 } else {
74 PrintUsage ();74 PrintUsage ();
75 }75 }
@@ -82,7 +82,7 @@
82 uint acct = int.parse(args[i+1]);82 uint acct = int.parse(args[i+1]);
83 string id = args[i+2];83 string id = args[i+2];
84 stdout.printf("Unliked...\n");84 stdout.printf("Unliked...\n");
85 service.do("unlike", acct, id);85 service.unlike(acct, id);
86 } else {86 } else {
87 PrintUsage ();87 PrintUsage ();
88 }88 }
@@ -95,7 +95,7 @@
95 uint acct = int.parse(args[i+1]);95 uint acct = int.parse(args[i+1]);
96 string id = args[i+2];96 string id = args[i+2];
97 stdout.printf("Retweet...\n");97 stdout.printf("Retweet...\n");
98 service.do("retweet", acct, id);98 service.retweet(acct, id);
99 } else {99 } else {
100 PrintUsage ();100 PrintUsage ();
101 }101 }
@@ -126,7 +126,7 @@
126 return;126 return;
127 }127 }
128 for(int i=1; i<args.length; i++) {128 for(int i=1; i<args.length; i++) {
129 if (args[i] == "--send-message") 129 if (args[i] == "--send-message")
130 if (args[i+1] != null && args[i+2] != null) {130 if (args[i+1] != null && args[i+2] != null) {
131 string message = args[i+1];131 string message = args[i+1];
132 uint acct = int.parse(args[i+2]);132 uint acct = int.parse(args[i+2]);
133133
=== modified file 'gtk/entry.vala'
--- gtk/entry.vala 2013-01-07 15:41:30 +0000
+++ gtk/entry.vala 2013-01-08 22:23:20 +0000
@@ -75,7 +75,7 @@
75 /**75 /**
76 * Widget that displays an entry which posts status updates to76 * Widget that displays an entry which posts status updates to
77 * your social network accounts using friends-service. The entry77 * your social network accounts using friends-service. The entry
78 * is very simple and does not include any of the frills 78 * is very simple and does not include any of the frills
79 * of {@link FriendsGtk.Entry}.79 * of {@link FriendsGtk.Entry}.
80 *80 *
81 * @since 0.181 * @since 0.1
@@ -122,7 +122,6 @@
122 * {@link Friends.Service}122 * {@link Friends.Service}
123 */123 */
124 private Friends.Service service;124 private Friends.Service service;
125 private Friends.URLShorten urlshorten;
126125
127 private Gdk.Color fg_color;126 private Gdk.Color fg_color;
128 private Gdk.Color error_color;127 private Gdk.Color error_color;
@@ -147,7 +146,6 @@
147 construct146 construct
148 {147 {
149 service = new Friends.Service ();148 service = new Friends.Service ();
150 urlshorten = new Friends.URLShorten ();
151149
152 unowned Gtk.BindingSet binding_set;150 unowned Gtk.BindingSet binding_set;
153 binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ());151 binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ());
@@ -253,7 +251,7 @@
253 {251 {
254 var buf = get_buffer ();252 var buf = get_buffer ();
255 Signal.stop_emission_by_name (buf, "insert-text") ;253 Signal.stop_emission_by_name (buf, "insert-text") ;
256 var shrt = urlshorten.shorten (text);254 var shrt = service.shorten (text);
257 last_was_shortened = true;255 last_was_shortened = true;
258 buf.insert (ref iter, shrt, -1);256 buf.insert (ref iter, shrt, -1);
259 }257 }
260258
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2012-12-10 20:46:09 +0000
+++ src/Makefile.am 2013-01-08 22:23:20 +0000
@@ -6,7 +6,6 @@
66
7libfriends_la_SOURCES = \7libfriends_la_SOURCES = \
8 service.vala \8 service.vala \
9 urlshorten.vala \
10 utils.vala \9 utils.vala \
11 $(NULL)10 $(NULL)
1211
1312
=== modified file 'src/service.vala'
--- src/service.vala 2013-01-08 22:23:20 +0000
+++ src/service.vala 2013-01-08 22:23:20 +0000
@@ -27,6 +27,7 @@
27 public abstract void Do (string action, string account_id, string message_id) throws GLib.IOError;27 public abstract void Do (string action, string account_id, string message_id) throws GLib.IOError;
28 public abstract async void Upload (string account_id, string uri, string description, out string result_url) throws GLib.IOError;28 public abstract async void Upload (string account_id, string uri, string description, out string result_url) throws GLib.IOError;
29 public abstract void ClearIndicators () throws GLib.IOError;29 public abstract void ClearIndicators () throws GLib.IOError;
30 public abstract string URLShorten (string url) throws GLib.IOError;
30 public abstract string GetFeatures (string protocol) throws GLib.IOError;31 public abstract string GetFeatures (string protocol) throws GLib.IOError;
31 public signal void ConnectionOffline ();32 public signal void ConnectionOffline ();
32 public signal void ConnectionOnline ();33 public signal void ConnectionOnline ();
@@ -225,6 +226,25 @@
225 }226 }
226227
227 /**228 /**
229 * Retweet an existing tweet.
230 *
231 * @param account_id The {@link Ag.Account.id} to fetch.
232 * @param message_id The id of the message you want to reshare.
233 * @return ``true`` for success, ``false`` otherwise
234 *
235 * @since 0.1
236 */
237 public bool retweet(uint account_id, string message_id)
238 {
239 try {
240 return do("retweet", account_id.to_string(), message_id);
241 } catch (GLib.Error e) {
242 warning (e.message);
243 }
244 return false;
245 }
246
247 /**
228 * Fetch the messages from the user's "home" screen. On248 * Fetch the messages from the user's "home" screen. On
229 * Facebook and Twitter this maps to the main feed you see on249 * Facebook and Twitter this maps to the main feed you see on
230 * the front page; public posts by people you follow but not250 * the front page; public posts by people you follow but not
@@ -370,6 +390,27 @@
370 }390 }
371391
372 /**392 /**
393 * Pass any URL to this method and it will shorten it for you.
394 *
395 * @param url The long URL you need shortened.
396 * @return The shortened URL.
397 *
398 * @since 0.1
399 */
400 public string shorten(string url)
401 {
402 try
403 {
404 return service.URLShorten(url);
405 }
406 catch (GLib.IOError e)
407 {
408 warning (e.message);
409 return url;
410 }
411 }
412
413 /**
373 * This method returns a list of all the possible actions414 * This method returns a list of all the possible actions
374 * supported by a given protocol. This can be used to415 * supported by a given protocol. This can be used to
375 * determine what actions can be triggered by the ``do``416 * determine what actions can be triggered by the ``do``
376417
=== removed file 'src/urlshorten.vala'
--- src/urlshorten.vala 2013-01-04 23:30:46 +0000
+++ src/urlshorten.vala 1970-01-01 00:00:00 +0000
@@ -1,70 +0,0 @@
1/*
2 * Copyright(C) 2012 Canonical Ltd.
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License
6 * version 3.0 as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License version 3.0 for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * Authored by Ken VaDine <ken.vandine@canonical.com>
18 */
19
20[DBus (name = "com.canonical.Friends.URLShorten")]
21private interface URLShortenInterface : Object {
22 public abstract string Shorten (string url) throws GLib.IOError;
23}
24
25[CCode (gir_namespace = "Friends", gir_version = "0.1")]
26namespace Friends
27{
28 public class URLShorten : Object
29 {
30 private const string url_name = "com.canonical.Friends.URLShorten";
31 private const string url_path = "/com/canonical/friends/URLShorten";
32
33 private URLShortenInterface url_service;
34
35 construct
36 {
37 try
38 {
39 url_service = Bus.get_proxy_sync(BusType.SESSION,
40 url_name,
41 url_path);
42 }
43 catch (GLib.IOError e)
44 {
45 warning ("Unable to get Friends URLShorten: "+e.message);
46 }
47 }
48
49
50 /**
51 * Pass any URL to this method and it will shorten it for you.
52 *
53 * @param url The long URL you need shortened.
54 *
55 * @since 0.1
56 */
57 public string shorten(string url)
58 {
59 try
60 {
61 return url_service.Shorten(url);
62 }
63 catch (GLib.IOError e)
64 {
65 warning (e.message);
66 return "Failed";
67 }
68 }
69 }
70}
710
=== modified file 'tests/vala/test-service.vala'
--- tests/vala/test-service.vala 2013-01-08 21:47:44 +0000
+++ tests/vala/test-service.vala 2013-01-08 22:23:20 +0000
@@ -27,7 +27,7 @@
27 {27 {
28 var dbusmock = new DBusMock ();28 var dbusmock = new DBusMock ();
29 /* Add mock methods to the dbus interface for testing29 /* Add mock methods to the dbus interface for testing
30 * python-dbusmock docs can be found at 30 * python-dbusmock docs can be found at
31 * http://bazaar.launchpad.net/~pitti/python-dbusmock/trunk/view/head:/README.rst31 * http://bazaar.launchpad.net/~pitti/python-dbusmock/trunk/view/head:/README.rst
32 */32 */
33 dbusmock.add_method ("Refresh", "", "", "");33 dbusmock.add_method ("Refresh", "", "", "");
@@ -38,6 +38,7 @@
38 dbusmock.add_method ("Do", "sss", "", "");38 dbusmock.add_method ("Do", "sss", "", "");
39 dbusmock.add_method ("Upload", "sss", "s", "ret = 'https://something.com/test.jpg'");39 dbusmock.add_method ("Upload", "sss", "s", "ret = 'https://something.com/test.jpg'");
40 dbusmock.add_method ("ClearIndicators", "", "", "");40 dbusmock.add_method ("ClearIndicators", "", "", "");
41 dbusmock.add_method ("URLShorten", "s", "s", "ret = 'http://is.gd/short'");
4142
42 GLib.Test.add_data_func ("/Unit/Friends/Service/Refresh",43 GLib.Test.add_data_func ("/Unit/Friends/Service/Refresh",
43 ServiceSuite.test_refresh);44 ServiceSuite.test_refresh);
@@ -56,7 +57,8 @@
56 ServiceSuite.test_send_reply);57 ServiceSuite.test_send_reply);
57 GLib.Test.add_data_func ("/Unit/Friends/Service/ClearIndicators",58 GLib.Test.add_data_func ("/Unit/Friends/Service/ClearIndicators",
58 ServiceSuite.test_clear_indicators);59 ServiceSuite.test_clear_indicators);
5960 GLib.Test.add_data_func ("/Unit/Friends/Service/URLShorten",
61 ServiceSuite.test_url_shorten);
60 }62 }
6163
62 internal static void test_refresh ()64 internal static void test_refresh ()
@@ -195,5 +197,23 @@
195 }197 }
196 assert (success == true);198 assert (success == true);
197 }199 }
200
201 internal static void test_url_shorten ()
202 {
203 var service = new Friends.Service ();
204 bool success = false;
205 string result = "";
206 try
207 {
208 result = service.shorten ("http://example.com/really/really/long");
209 success = true;
210 }
211 catch (GLib.IOError e)
212 {
213 warning ("Failed to shorten URL - %s", e.message);
214 }
215 assert (success == true);
216 assert (result == "http://is.gd/short");
217 }
198 }218 }
199}219}

Subscribers

People subscribed via source and target branches