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 pathPocketItem.cs
More file actions
493 lines (441 loc) · 12.5 KB
/
PocketItem.cs
File metadata and controls
493 lines (441 loc) · 12.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace PocketSharp.Models
{
/// <summary>
/// Item containing all available data
/// see: http://getpocket.com/developer/docs/v3/retrieve
/// </summary>
[JsonObject]
[DebuggerDisplay("Uri = {Uri}, Title = {Title}")]
public class PocketItem : IComparable
{
/// <summary>
/// Gets or sets the ID.
/// </summary>
/// <value>
/// The ID.
/// </value>
[JsonProperty("item_id")]
public string ID { get; set; }
/// <summary>
/// Gets or sets the resolved identifier.
/// </summary>
/// <value>
/// The resolved identifier.
/// </value>
[JsonProperty("resolved_id")]
public string ResolvedId { get; set; }
/// <summary>
/// Gets or sets the normal URI.
/// </summary>
/// <value>
/// The normal URI.
/// </value>
[JsonProperty("normal_url")]
private Uri _NormalUri { get; set; }
/// <summary>
/// Gets or sets the given URI.
/// </summary>
/// <value>
/// The given URI.
/// </value>
[JsonProperty("given_url")]
private Uri _GivenUri { get; set; }
/// <summary>
/// Gets or sets the resolved URI.
/// </summary>
/// <value>
/// The resolved URI.
/// </value>
[JsonProperty("resolved_url")]
private Uri _ResolvedUri { get; set; }
/// <summary>
/// Gets or sets the URI.
/// </summary>
/// <value>
/// The URI.
/// </value>
[JsonIgnore]
public Uri Uri
{
get { return _ResolvedUri ?? _GivenUri ?? _NormalUri; }
set { _NormalUri = value; _ResolvedUri = value; _GivenUri = value; }
}
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
[JsonProperty("resolved_title")]
private string _ResolvedTitle { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
[JsonProperty("title")]
private string _InternalTitle { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
[JsonIgnore]
public string Title
{
get { return _InternalTitle ?? _ResolvedTitle ?? FullTitle; }
set { _InternalTitle = value; _ResolvedTitle = value; }
}
/// <summary>
/// Gets or sets the full title.
/// </summary>
/// <value>
/// The full title.
/// </value>
[JsonProperty("given_title")]
public string FullTitle { get; set; }
/// <summary>
/// Gets or sets the excerpt.
/// </summary>
/// <value>
/// The excerpt.
/// </value>
[JsonProperty]
public string Excerpt { get; set; }
/// <summary>
/// Gets or sets the status.
/// </summary>
/// <value>
/// The status.
/// </value>
[JsonProperty]
public int Status { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is favorite.
/// </summary>
/// <value>
/// <c>true</c> if this instance is favorite; otherwise, <c>false</c>.
/// </value>
[JsonProperty("favorite")]
public bool IsFavorite { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is archive.
/// </summary>
/// <value>
/// <c>true</c> if this instance is archive; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool IsArchive { get { return Status == 1; } }
/// <summary>
/// Gets a value indicating whether this instance is deleted.
/// </summary>
/// <value>
/// <c>true</c> if this instance is deleted; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool IsDeleted { get { return Status == 2; } }
/// <summary>
/// Gets or sets a value indicating whether this instance is article.
/// </summary>
/// <value>
/// <c>true</c> if this instance is article; otherwise, <c>false</c>.
/// </value>
[JsonProperty("is_article")]
public bool IsArticle { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance has image.
/// </summary>
/// <value>
/// <c>true</c> if this instance has image; otherwise, <c>false</c>.
/// </value>
[JsonProperty("has_image")]
private PocketBoolean? _HasImage { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance has video.
/// </summary>
/// <value>
/// <c>true</c> if this instance has video; otherwise, <c>false</c>.
/// </value>
[JsonProperty("has_video")]
private PocketBoolean? _HasVideo { get; set; }
/// <summary>
/// Gets a value indicating whether [has image].
/// </summary>
/// <value>
/// <c>true</c> if [has image]; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool HasImage
{
get
{
return _HasImage == PocketBoolean.Yes || _HasImage == PocketBoolean.IsType;
}
}
/// <summary>
/// Gets a value indicating whether [has video].
/// </summary>
/// <value>
/// <c>true</c> if [has video]; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool HasVideo
{
get
{
return _HasVideo == PocketBoolean.Yes || _HasVideo == PocketBoolean.IsType;
}
}
/// <summary>
/// Gets a value indicating whether [is video].
/// </summary>
/// <value>
/// <c>true</c> if [is video]; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool IsVideo
{
get
{
return _HasVideo == PocketBoolean.IsType;
}
}
/// <summary>
/// Gets a value indicating whether [is image].
/// </summary>
/// <value>
/// <c>true</c> if [is image]; otherwise, <c>false</c>.
/// </value>
[JsonIgnore]
public bool IsImage
{
get
{
return _HasImage == PocketBoolean.IsType;
}
}
/// <summary>
/// Gets or sets the word count.
/// </summary>
/// <value>
/// The word count.
/// </value>
[JsonProperty("word_count")]
public int WordCount { get; set; }
/// <summary>
/// Gets or sets the sort.
/// </summary>
/// <value>
/// The sort.
/// </value>
[JsonProperty("sort_id")]
public int Sort { get; set; }
/// <summary>
/// Gets or sets the add time.
/// </summary>
/// <value>
/// The add time.
/// </value>
[JsonProperty("time_added")]
public DateTime? AddTime { get; set; }
/// <summary>
/// Gets or sets the update time.
/// </summary>
/// <value>
/// The update time.
/// </value>
[JsonProperty("time_updated")]
public DateTime? UpdateTime { get; set; }
/// <summary>
/// Gets or sets the read time.
/// </summary>
/// <value>
/// The read time.
/// </value>
[JsonProperty("time_read")]
public DateTime? ReadTime { get; set; }
/// <summary>
/// Gets or sets the favorite time.
/// </summary>
/// <value>
/// The favorite time.
/// </value>
[JsonProperty("time_favorited")]
public DateTime? FavoriteTime { get; set; }
/// <summary>
/// Gets or sets the published time.
/// </summary>
/// <value>
/// The time when the article was published.
/// </value>
[JsonProperty("date_published")]
public DateTime? PublishedTime { get; set; }
/// <summary>
/// Gets or sets the tags as comma-separated strings.
/// </summary>
/// <value>
/// The tags.
/// </value>
[JsonIgnore]
public string TagsString
{
get { return Tags != null ? String.Join(",", Tags.Select(tag => tag.Name)) : ""; }
}
/// <summary>
/// Gets or sets the tags.
/// </summary>
/// <value>
/// The tags.
/// </value>
[JsonProperty("tags")]
[JsonConverter(typeof(ObjectToArrayConverter<PocketTag>))]
public IEnumerable<PocketTag> Tags { get; set; }
/// <summary>
/// Gets or sets the images.
/// </summary>
/// <value>
/// The images.
/// </value>
[JsonProperty("images")]
[JsonConverter(typeof(ObjectToArrayConverter<PocketImage>))]
public IEnumerable<PocketImage> Images { get; set; }
/// <summary>
/// Gets or sets the videos.
/// </summary>
/// <value>
/// The videos.
/// </value>
[JsonProperty("videos")]
[JsonConverter(typeof(ObjectToArrayConverter<PocketVideo>))]
public IEnumerable<PocketVideo> Videos { get; set; }
/// <summary>
/// Gets or sets the authors.
/// </summary>
/// <value>
/// The authors.
/// </value>
[JsonProperty("authors")]
[JsonConverter(typeof(ObjectToArrayConverter<PocketAuthor>))]
public IEnumerable<PocketAuthor> Authors { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is trending.
/// </summary>
/// <value>
/// <c>true</c> if this instance is trending; otherwise, <c>false</c>.
/// </value>
[JsonProperty("trending")]
public bool IsTrending { get; set; }
/// <summary>
/// Gets the lead image.
/// </summary>
/// <value>
/// The lead image.
/// </value>
[JsonIgnore]
public PocketImage LeadImage
{
get { return Images != null && Images.Count() > 0 ? Images.First() : null; }
}
/// <summary>
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
/// </summary>
/// <param name="obj">An object to compare with this instance.</param>
/// <returns>
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes <paramref name="obj" /> in the sort order. Zero This instance occurs in the same position in the sort order as <paramref name="obj" />. Greater than zero This instance follows <paramref name="obj" /> in the sort order.
/// </returns>
int IComparable.CompareTo(object obj)
{
PocketItem item = (PocketItem)obj;
if (!AddTime.HasValue)
{
return 1;
}
if (!item.AddTime.HasValue)
{
return -1;
}
return DateTime.Compare(AddTime.Value, item.AddTime.Value);
}
/// <summary>
/// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
PocketItem item = obj as PocketItem;
if (item == null)
{
return false;
}
return ID == item.ID;
}
/// <summary>
/// Implements the operator ==.
/// </summary>
/// <param name="a">A.</param>
/// <param name="b">The b.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator ==(PocketItem a, PocketItem b)
{
if (Object.ReferenceEquals(a, b))
{
return true;
}
PocketItem itemA = (PocketItem)a;
PocketItem itemB = (PocketItem)b;
if ((Object)itemA == null || (Object)itemB == null)
{
return false;
}
return itemA.ID == itemB.ID;
}
/// <summary>
/// Implements the operator !=.
/// </summary>
/// <param name="a">A.</param>
/// <param name="b">The b.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator !=(PocketItem a, PocketItem b)
{
return !(a == b);
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return ID.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
return ID;
}
}
}