This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathIPocketClient.cs
More file actions
512 lines (463 loc) · 22.5 KB
/
IPocketClient.cs
File metadata and controls
512 lines (463 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
using PocketSharp.Models;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace PocketSharp
{
public interface IPocketClient
{
#region properties
/// <summary>
/// callback URLi for API calls
/// </summary>
/// <value>
/// The callback URI.
/// </value>
string CallbackUri { get; set; }
/// <summary>
/// Accessor for the Pocket API key
/// see: http://getpocket.com/developer
/// </summary>
/// <value>
/// The consumer key.
/// </value>
string ConsumerKey { get; set; }
/// <summary>
/// Code retrieved on authentification
/// </summary>
/// <value>
/// The request code.
/// </value>
string RequestCode { get; set; }
/// <summary>
/// Code retrieved on authentification-success
/// </summary>
/// <value>
/// The access code.
/// </value>
string AccessCode { get; set; }
/// <summary>
/// Action which is executed before every request
/// </summary>
/// <value>
/// The pre request callback.
/// </value>
Action<string> PreRequest { get; set; }
#endregion
#region account methods
/// <summary>
/// Retrieves the requestCode from Pocket, which is used to generate the Authentication URI to authenticate the user
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="System.NullReferenceException">Authentication methods need a callbackUri on initialization of the PocketClient class</exception>
/// <exception cref="PocketException"></exception>
Task<string> GetRequestCode(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Generate Authentication URI from requestCode
/// </summary>
/// <param name="requestCode">The requestCode. If no requestCode is supplied, the property from the PocketClient intialization is used.</param>
/// <returns>
/// A valid URI to redirect the user to.
/// </returns>
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
Uri GenerateAuthenticationUri(string requestCode = null);
/// <summary>
/// Requests the access code and username after authentication
/// The access code has to permanently be stored within the users session, and should be passed in the constructor for all future PocketClient initializations.
/// </summary>
/// <param name="requestCode">The request code.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The authenticated user
/// </returns>
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
Task<PocketUser> GetUser(string requestCode = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Generate registration URI from requestCode
/// </summary>
/// <param name="requestCode">The requestCode. If no requestCode is supplied, the property from the PocketClient intialization is used.</param>
/// <returns>A valid URI to redirect the user to.</returns>
/// <exception cref="System.NullReferenceException">Call GetRequestCode() first to receive a request_code</exception>
Uri GenerateRegistrationUri(string requestCode = null);
/// <summary>
/// Get a new GUID from the Pocket API.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// The GUID
/// </returns>
Task<string> GetGuid(CancellationToken cancellationToken = default(CancellationToken));
#endregion
#region add methods
/// <summary>
/// Adds a new item to pocket
/// </summary>
/// <param name="uri">The URL of the item you want to save</param>
/// <param name="tags">A comma-separated list of tags to apply to the item</param>
/// <param name="title">This can be included for cases where an item does not have a title, which is typical for image or PDF URLs. If Pocket detects a title from the content of the page, this parameter will be ignored.</param>
/// <param name="tweetID">If you are adding Pocket support to a Twitter client, please send along a reference to the tweet status id. This allows Pocket to show the original tweet alongside the article.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method)
/// </returns>
/// <exception cref="System.FormatException">(1) Uri should be absolute.</exception>
/// <exception cref="PocketException"></exception>
Task<PocketItem> Add(Uri uri, string[] tags = null, string title = null, string tweetID = null, CancellationToken cancellationToken = default(CancellationToken));
#endregion
#region get methods
/// <summary>
/// Retrieves items from pocket
/// with the given filters
/// </summary>
/// <param name="state">The state.</param>
/// <param name="favorite">The favorite.</param>
/// <param name="tag">The tag.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="sort">The sort.</param>
/// <param name="search">The search.</param>
/// <param name="domain">The domain.</param>
/// <param name="since">The since.</param>
/// <param name="count">The count.</param>
/// <param name="offset">The offset.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> Get(
State? state = null,
bool? favorite = null,
string tag = null,
ContentType? contentType = null,
Sort? sort = null,
string search = null,
string domain = null,
DateTime? since = null,
int? count = null,
int? offset = null,
CancellationToken cancellationToken = default(CancellationToken)
);
/// <summary>
/// Retrieves an item by a given ID
/// Note: The Pocket API contains no method, which allows to retrieve a single item, so all items are retrieved and filtered locally by the ID.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<PocketItem> Get(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieves all items by a given filter
/// </summary>
/// <param name="filter">The filter.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Converts a raw JSON response to a PocketItem list
/// </summary>
/// <param name="itemsJSON">The raw JSON response.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
IEnumerable<PocketItem> ConvertJsonToList(string itemsJSON);
/// <summary>
/// Retrieves all available tags.
/// Note: The Pocket API contains no method, which allows to retrieve all tags, so all items are retrieved and the associated tags extracted.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketTag>> GetTags(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieves items by tag
/// </summary>
/// <param name="tag">The tag.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieves items which match the specified search string in title and URI
/// </summary>
/// <param name="searchString">The search string.</param>
/// <param name="tag">Filter by tag.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> Search(string searchString, string tag = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Retrieves the article content from an URI
/// WARNING:
/// You have to pass the parseUri in the PocketClient ctor for this method to work.
/// This is a private API and can only be used by authenticated users.
/// </summary>
/// <param name="tag">The article URI.</param>
/// <param name="includeImages">Include images into content or use placeholder.</param>
/// <param name="includeVideos">Include videos into content or use placeholder.</param>
/// <param name="forceRefresh">Force refresh of the content (don't use cache).</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<PocketArticle> GetArticle(Uri uri, bool includeImages = true, bool includeVideos = true, bool forceRefresh = false, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get article suggestions for an existing Pocket item.
/// </summary>
/// <param name="itemId">Get suggestions based on this item.</param>
/// <param name="count">Requested item count.</param>
/// <param name="languageCode">Two-letter language code for language-specific results.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> GetSuggestions(string itemId, int count = 3, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken));
#endregion
#region modify methods
/// <summary>
/// Sends multiple actions in one request.
/// See: http://getpocket.com/developer/docs/v3/modify
/// </summary>
/// <param name="actions">The actions.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> SendActions(IEnumerable<PocketAction> actions, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Archives the specified item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Archive(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Archives the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Archive(PocketItem item, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Un-archives the specified item (alias for Readd).
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Unarchive(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Unarchives the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Unarchive(PocketItem item, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Favorites the specified item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Favorite(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Favorites the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Favorite(PocketItem item, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Un-favorites the specified item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Unfavorite(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Un-favorites the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Unfavorite(PocketItem item, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes the specified item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> Delete(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<bool> Delete(PocketItem item, CancellationToken cancellationToken = default(CancellationToken));
#endregion
#region modify tags methods
/// <summary>
/// Adds the specified tags to an item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="tags">The tags.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> AddTags(string itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Adds the specified tags to an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="tags">The tags.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> AddTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Removes the specified tags from an item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="tags">The tags.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RemoveTags(string itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Removes the specified tags from an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="tags">The tag.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RemoveTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Removes a tag from an item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="tag">The tag.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RemoveTag(string itemID, string tag, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Removes a tag from an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="tag">The tag.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RemoveTag(PocketItem item, string tag, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Clears all tags from an item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RemoveTags(string itemID, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Clears all tags from an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RemoveTags(PocketItem item, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes a tag. This will remove it from all affected items too.
/// </summary>
/// <param name="tag">The tag.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> DeleteTag(string tag, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Replaces all existing tags with the given tags in an item.
/// </summary>
/// <param name="itemID">The item ID.</param>
/// <param name="tags">The tags.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> ReplaceTags(string itemID, string[] tags, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Replaces all existing tags with the given new ones in an item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="tags">The tags.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> ReplaceTags(PocketItem item, string[] tags, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Renames a tag. This affects all items with this tag.
/// </summary>
/// <param name="oldTag">The old tag.</param>
/// <param name="newTag">The new tag name.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<bool> RenameTag(string oldTag, string newTag, CancellationToken cancellationToken = default(CancellationToken));
#endregion
#region statistics methods
/// <summary>
/// Statistics from the user account.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<PocketStatistics> GetUserStatistics(CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns API usage statistics.
/// If a request was made before, the data is returned synchronously from the cache.
/// Note: This method only works for authenticated users with a given AccessCode.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<PocketLimits> GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken));
#endregion
#region explore/trending methods
/// <summary>
/// Get trending articles on Pocket.
/// Requires an active GUID from GetGuid() and will therefore make two HTTP requests.
/// </summary>
/// <param name="count">Article count.</param>
/// <param name="languageCode">Two-letter language code for language-specific results.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get trending topics on Pocket.
/// Requires an active GUID from GetGuid() and will therefore make two HTTP requests.
/// </summary>
/// <param name="languageCode">Two-letter language code for language-specific results.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketTopic>> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Explore Pocket and find interesting articles by a certain topic
/// </summary>
/// <param name="topic">Term or topic to get articles for</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
// Task<IEnumerable<PocketExploreItem>> Explore(string topic, CancellationToken cancellationToken = default(CancellationToken));
#endregion
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
void Dispose();
}
}