API Docs: clarify usage of Subscription API
[mygpo.git] / doc / api / reference / subscriptions.rst
blob9bcd0feaa73c189e0b44656694a0461f1dacb8fe
1 .. _subscriptions-api:
3 Subscriptions API
4 =================
6 The subscriptions API is used to manage the podcast subscriptions of a client
7 device.
10 Resources
11 ---------
13 The Subscriptions API defines the following resources ::
15  /user/{username}/subscriptions
16  /user/{username}/device/{deviceid}/subscriptions
18 The first resource represents the summary of subscriptions over all devices. It
19 can not be modified directly.
21 The second resource represents the subscriptions of a single
22 :ref:`device-integration`.
25 Subscription Upload
26 -------------------
28 Clients can upload the podcast subscriptions for a :ref:`device-integration` to
29 replace its existing subscriptions.
32 Request
33 ^^^^^^^
35 The client sends an object containing all current subscriptions for the
36 device. ::
38  PUT /user/{username}/device/{deviceid}/subscriptions
39  Content-Type: application/json
41  {
42     podcasts: [
43         { url: "http://example.com/podcast.rss" },
44         { url: "http://podcast.com/episodes.xml" }
45     ]
46  }
49 Response
50 ^^^^^^^^
52 The server can respond with the following status codes.
54 If a ``Link`` header with ``rel=changes`` is provided, this URL can be used to
55 retrieve changes to the subscriptions since the respective response (see
56 :ref:`subscription-change-download`)
58 If a new device has been created ::
60  201 Created
61  Link: <https://api.gpodder.net/user/{username}/device/{deviceid}/subscription?since=0>; rel=changes
63  no body
66 If the subscriptions have been processed immediatelly ::
68  204 No Content
69  Link: <https://api.gpodder.net/user/{username}/device/{deviceid}/subscription?since=1234>; rel=changes
71  no body
74 If the subscriptions have been accepted for later processing ::
76  202 Accepted
78  no body
80 No change download address is provided in this case, as is is not yet known at
81 the time of the response. If the client needs to know the current
82 subscriptions, it should follow up by a request to download the subscriptions.
84 If invalid podcast information is provided (eg an invalid feed URL), the whole
85 request will be rejected. ::
87  400 Bad Request
88  Content-Type: application/json
90  {
91    "message": "Invalid podcast URL",
92    "errors": [
93      {
94        "field": "/podcasts/1",
95        "code": "invalid_url"
96      }
97    ]
98  }
101 Subscription Download
102 ---------------------
104 Clients can download the current subscriptions either of a single
105 :ref:`device-integration` or over all of the user's devices.
108 Request
109 ^^^^^^^
111 Download subscriptions of a device ::
113  GET /user/{username}/device/{deviceid}/subscriptions
114  Content-Type: application/json
117 Download all of the user's subscriptions ::
119  GET /user/{username}/subscriptions
120  Content-Type: application/json
123 Response
124 ^^^^^^^^
126 The podcasts correspond to the :ref:`podcast-type` type. ::
128  200 OK
129  Link: <https://api.gpodder.net/user/{username}/device/{deviceid}/subscription?since=1234>; rel=changes
130  Content-Type: application/json
133     podcasts: [
134         { podcast1 },
135         { podcast2 }
136     ]
139 The changes link is not provided if all subscriptions of a user are requested.
142 Subscription Change Upload
143 --------------------------
145 Clients can update the current subscriptions of a :ref:`device-integration` by
146 reporting subscribed and unsubscribed podcasts.
149 Request
150 ^^^^^^^
152 A client can send which podcasts have been subscribed and unsubscribed. ::
154  POST /user/{username}/device/{deviceid}/subscriptions
155  Content-Tpe: application/json
158     subscribe: [
159         { url: "http://example.com/podcast.rss" }
160     ]
161     unsubscribe: [
162         { url: "http://podcast.com/episodes.xml" }
163     ]
166 A client MUST NOT upload a change set where both ``subscribe`` and
167 ``unsubscribe`` are empty, or where the same podcast is given in both
168 ``subscribe`` and ``unsubscribe``.
171 Response
172 ^^^^^^^^
174 The server responds with either of the following status codes.
176 The changes are processed immediatelly. ::
178  200 OK
179  Content-Tpe: application/json
181  body according to Subscription Download
184 The changes have been accepted for later processing. ::
186  204 Accepted
188  no body
190 No response body is provided in this case, as it is not yet known.
193 .. _subscription-change-download:
195 Subscription Change Download
196 ----------------------------
198 Download changes to the subscriptions of a :ref:`device-integration`.
201 Request
202 ^^^^^^^
204 The client makes the following request. ::
206  GET /user/{username}/device/{deviceid}/subscriptions{?since}
207  Content-Tpe: application/json
210 Response
211 ^^^^^^^^
213 The server can response with any of the following status codes.
215 The changes are returned immediatelly. ::
217  200 OK
218  Link: <https://api.gpodder.net/user/{username}/device/{deviceid}/subscription?since=1234>; rel=changes
219  Content-Type: application/json
222     subscribe: [
223         { url: "http://example.com/podcast.rss" }
224     ]
225     unsubscribe: [
226         { url: "http://podcast.com/episodes.xml" }
227     ]
230 The server can also return a prepared response (see
231 :ref:`prepared-response-api`).
234 Integration Recommendations
235 ---------------------------
237 This section describes how the API can be accessed for common use cases.
239 * On first startup a client CAN retrieve the list of all the user's
240   subscriptions to offer as suggestions.
242 * On first startup a client SHOULD generate a unique :ref:`device-integration`
243   Id for managing its own subscriptions in subsequent API calls.
245 * A client which has been somehow "reset" can re-use an existing device ID and
246   restore its subscriptions from there. It SHOULD NOT share the same device ID
247   with another installation which is still used.
249 * A client SHOULD either use the combination of Subscription Upload and
250   Download endpoints, or the Subscription Change endpoints to keep its
251   subscriptions up to date.
253 * When retrieving subscriptions or subscription changes, a client SHOULD use
254   the URL in the ``Link`` header with ``rel=changes`` (if present) to retrieve
255   subsequent changes to the resource.