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