1 /***************************************************************************
2 * This file is part of libmygpo-qt                                         *
3 * Copyright (c) 2010 - 2013 Stefan Derkits <stefan@derkits.at>             *
4 * Copyright (c) 2010 - 2011 Christian Wagner <christian.wagner86@gmx.at>   *
5 * Copyright (c) 2010 - 2011 Felix Winter <ixos01@gmail.com>                *
6 *                                                                          *
7 * This library is free software; you can redistribute it and/or            *
8 * modify it under the terms of the GNU Lesser General Public               *
9 * License as published by the Free Software Foundation; either             *
10 * version 2.1 of the License, or (at your option) any later version.       *
11 *                                                                          *
12 * This library is distributed in the hope that it will be useful,          *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
15 * Lesser General Public License for more details.                          *
16 *                                                                          *
17 * You should have received a copy of the GNU Lesser General Public         *
18 * License along with this library; if not, write to the Free Software      *
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *
20 * USA                                                                      *
21 ***************************************************************************/
22 
23 #ifndef LIBMYGPO_QT_URLBUILDER_H
24 #define LIBMYGPO_QT_URLBUILDER_H
25 
26 #include <QString>
27 
28 namespace mygpo
29 {
30 /**
31 * Helper class to generate request URL's.
32 * Helps to generate URL's for the gpodder requests.
33 * This class uses the singleton pattern, to retrieve a
34 * reference to the singleton object use the function instance().
35 */
36 
37 class UrlBuilder
38 {
39 
40 public:
41 
42     enum Format
43     {
44         JSON,
45         OPML,
46         TEXT,
47         XML
48     };
49 
50     /**
51     * @param i Any value between 1..100. If i <= 0 it will be set to 1.
52     * @return Request URL to retrieve a list of the top 'i' podcasts.
53     */
54     static QString getToplistUrl( uint i, Format f = JSON );
55 
56     /**
57      * @param i Any value between 1..100. If i <= 0 it will be set to 1.
58      * @return Rquest URL to retrieve 'i' podcast suggestions.
59      */
60     static QString getSuggestionsUrl( uint i, Format f = JSON );
61 
62     /**
63      * @param query The query to search in the podcasts name/descrption.
64      * @return Request URL to retrieve podcasts related to the query.
65      */
66     static QString getPodcastSearchUrl( const QString& query, Format f = JSON );
67 
68     static QString getSubscriptionsUrl( const QString& username, const QString& device, Format f = JSON );
69     /**
70      * @param i Amount of tags. If i == 0 it will be set to 1.
71      * @return Request URL to retrieve the 'i' most used tags.
72      */
73     static QString getTopTagsUrl( uint i );
74 
75     /**
76      * @param i Amount of podcasts. If i == 0 it will be set to 1.
77      * @return Request URL to retrieve the 'i' most-subscribed podcats that are tagged with tag.
78      */
79     static QString getPodcastsOfTagUrl( const QString& tag, uint i );
80 
81     /**
82      * @param url The URL of the podcast
83      * @return Request URL to retrieve information about the podcast with the given url.
84      */
85     static QString getPodcastDataUrl( const QString& url );
86 
87     /**
88      * @param podcastUrl URL of the podcast
89      * @param episodeUrl URL of the episode that belongs to the podcast-url
90      * @return Request URL to retrieve information about the episode with the given episode-url.
91      */
92     static QString getEpisodeDataUrl( const QString& podcastUrl, const QString& episodeUrl );
93 
94     /**
95      * @param username User name (gpodder.net). You need to be logged in with username.
96      * @return Request URL to retrieve a list of all favorite episodes.
97      */
98     static QString getFavEpisodesUrl( const QString& username );
99 
100     /**
101      * @param username User name (gpodder.net). You need to be logged in with username.
102      * @param deviceId The id of the device.
103      * @return Request URL to to update the subscription list for a given device.
104      */
105     static QString getAddRemoveSubUrl( const QString& username, const QString& deviceId );
106 
107     static QString getAccountSettingsUrl( const QString& username );
108 
109     static QString getDeviceSettingsUrl( const QString& username, const QString& deviceId );
110 
111     static QString getPodcastSettingsUrl( const QString& username, const QString& podcastUrl );
112 
113     static QString getEpisodeSettingsUrl( const QString& username, const QString& podcastUrl, const QString& episodeUrl );
114 
115     static QString getDeviceListUrl( const QString& username );
116 
117     static QString getRenameDeviceUrl( const QString& username, const QString& deviceId );
118 
119     static QString getDeviceUpdatesUrl( const QString& username, const QString& deviceId, qulonglong timestamp );
120 
121     static QString getEpisodeActionsUrl( const QString& username, bool aggregated );
122 
123     static QString getEpisodeActionsUrlByPodcast( const QString& username, const QString& podcastUrl, bool aggregated );
124 
125     static QString getEpisodeActionsUrlByDevice( const QString& username, const QString& deviceId, bool aggregated );
126 
127     static QString getEpisodeActionsUrlByTimestamp( const QString& username, qulonglong since );
128 
129     static QString getEpisodeActionsUrlByPodcastAndTimestamp( const QString& username, const QString& podcastUrl, qulonglong since );
130 
131     static QString getEpisodeActionsUrlByDeviceAndTimestamp( const QString& username, const QString& deviceId, qulonglong since );
132 
133     static QString getUploadEpisodeActionsUrl( const QString& username );
134 
135     static QString getDeviceSynchronizationStatusUrl( const QString& username );
136 
137 private:
UrlBuilder()138     UrlBuilder() {};
UrlBuilder(const UrlBuilder &)139     UrlBuilder( const UrlBuilder& ) {};
140     static const QString s_server;
141     static const QString s_api2;
142     static const QString s_api1;
143 };
144 }
145 
146 #endif // LIBMYGPO_QT_URLBUILDER_H
147