From d8277800bd5899436dd09a600d71ccf4accac8da Mon Sep 17 00:00:00 2001 From: Athou Date: Sun, 19 May 2013 10:03:26 +0200 Subject: [PATCH] subscribe by url callback and subtome support --- .../frontend/rest/resources/FeedREST.java | 24 +++++++++++++++++++ src/main/resources/i18n/en.properties | 3 +++ src/main/webapp/js/controllers.js | 13 +++++++++- src/main/webapp/templates/_footer.html | 3 +++ src/main/webapp/templates/feeds.help.html | 7 ++++-- src/main/webapp/templates/feeds.html | 1 + 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/webapp/templates/_footer.html diff --git a/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java b/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java index b1e0a30d..68394500 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java @@ -1,6 +1,7 @@ package com.commafeed.frontend.rest.resources; import java.io.StringWriter; +import java.net.URI; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -229,6 +230,29 @@ public class FeedREST extends AbstractResourceREST { return Response.ok(Status.OK).build(); } + @GET + @Path("/subscribe") + @ApiOperation(value = "Subscribe to a feed", notes = "Subscribe to a feed") + public Response subscribe( + @ApiParam(value = "feed url", required = true) @QueryParam("url") String url) { + + try { + Preconditions.checkNotNull(url); + + url = prependHttp(url); + url = ((FeedInfo) fetchFeed(url).getEntity()).getUrl(); + + FeedInfo info = (FeedInfo) fetchFeed(url).getEntity(); + feedSubscriptionService.subscribe(getUser(), info.getUrl(), + info.getTitle(), null); + } catch (Exception e) { + log.info("Could not subscribe to url {} : {}", url, e.getMessage()); + } + return Response.temporaryRedirect( + URI.create(applicationSettingsService.get().getPublicUrl())) + .build(); + } + private String prependHttp(String url) { if (!url.startsWith("http")) { url = "http://" + url; diff --git a/src/main/resources/i18n/en.properties b/src/main/resources/i18n/en.properties index 001176c2..03d362f7 100644 --- a/src/main/resources/i18n/en.properties +++ b/src/main/resources/i18n/en.properties @@ -84,6 +84,9 @@ about.line2_prefix=If you encounter an issue, please report it on the issues pag about.line2_suffix= project. about.line3=If you like this project, please consider a donation to support the developer and help cover the costs of keeping this website online. about.goodies=Goodies +about.goodies.subscribe_url=Subscribe URL +about.goodies.chrome_extension=Chrome extension +about.goodies.firefox_extension=Firefox extension about.translation=Translation about.translation.message=We need your help to translate CommaFeed. about.translation.link=See how to contribute with translations. diff --git a/src/main/webapp/js/controllers.js b/src/main/webapp/js/controllers.js index 8ceb8e09..ac810a5d 100644 --- a/src/main/webapp/js/controllers.js +++ b/src/main/webapp/js/controllers.js @@ -934,4 +934,15 @@ function($scope, $location, $state, AdminSettingsService) { $scope.toUsers = function() { $state.transitionTo('admin.userlist'); }; -}]); \ No newline at end of file +}]); + +module.controller('FooterController', [ '$scope', '$location', '$state', + 'AdminSettingsService', +function($scope, $location, $state, AdminSettingsService) { + + var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf('#')); + var hostname = window.location.hostname; + $scope.subToMeUrl = baseUrl + 'rest/feed/subscribe?url={feed}'; + $scope.subToMeName = hostname.indexOf('www.commafeed.com') !== -1 ? 'CommaFeed' : 'CommaFeed (' + hostname + ')'; + +} ]); \ No newline at end of file diff --git a/src/main/webapp/templates/_footer.html b/src/main/webapp/templates/_footer.html new file mode 100644 index 00000000..450e78c7 --- /dev/null +++ b/src/main/webapp/templates/_footer.html @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/src/main/webapp/templates/feeds.help.html b/src/main/webapp/templates/feeds.help.html index ebc5e00a..cee81070 100644 --- a/src/main/webapp/templates/feeds.help.html +++ b/src/main/webapp/templates/feeds.help.html @@ -22,10 +22,13 @@

${about.goodies}

- Chrome extension + ${about.goodies.subscribe_url}: rest/feed/subscribe?url=FEED_URL_HERE

- Firefox extension + ${about.goodies.chrome_extension} +

+

+ ${about.goodies.firefox_extension}

${about.translation}

diff --git a/src/main/webapp/templates/feeds.html b/src/main/webapp/templates/feeds.html index 9ebc885b..b26b186d 100644 --- a/src/main/webapp/templates/feeds.html +++ b/src/main/webapp/templates/feeds.html @@ -13,4 +13,5 @@ +
\ No newline at end of file