My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Security;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
using System.Text;
using Dimebrain.TweetSharp.Core;
using Dimebrain.TweetSharp.Fluent;
using Dimebrain.TweetSharp.Extensions;
using Dimebrain.TweetSharp.Model;
using System.Collections.Generic;

namespace TwitterLib
{
/// <summary>
/// .NET wrapper for interacting with the Twitter API
/// </summary>
public class TwitterNet : IServiceApi
{
#region Private Fields
private string username;
private SecureString password;
private string publicTimelineUrl;
private string friendsTimelineUrl;
private string userTimelineUrl;
private string repliesTimelineUrl;
private string directMessagesUrl;
private string updateUrl;
private string friendsUrl;
private string followersUrl;
private string userShowUrl;
private string sendMessageUrl;
private string destroyUrl;
private string destroyDirectMessageUrl;
private string createFriendshipUrl;
private string rateLimitStatusUrl;
private string verifyCredentialsUrl;
private string tweetUrl;
private string format;
private IWebProxy webProxy = HttpWebRequest.DefaultWebProxy; // Jason Follas: Added initialization
private string twitterServerUrl; // Jason Follas

private User currentLoggedInUser;

// REMARK: might need to fix this for globalization
private readonly string twitterCreatedAtDateFormat = "ddd MMM dd HH:mm:ss zzzz yyyy"; // Thu Apr 26 01:36:08 +0000 2007
private readonly string twitterSinceDateFormat = "ddd MMM dd yyyy HH:mm:ss zzzz";

private static int characterLimit;
private string clientName;

#endregion

#region Public Properties

public User CurrentlyLoggedInUser
{
get
{
if (null == currentLoggedInUser)
{
currentLoggedInUser = Login();
}
return currentLoggedInUser;
}
set
{
currentLoggedInUser = value;
}
}

/// <summary>
/// Twitter username
/// </summary>
public string UserName
{
get { return (null == currentLoggedInUser ? String.Empty : currentLoggedInUser.Name) ; }
}

/// <summary>
/// Twitter password
/// </summary>
public SecureString Password
{
get { return password; }
set { password = value; }
}

/// <summary>
/// Web proxy to use when communicating with the Twitter service
/// </summary>
public IWebProxy WebProxy
{
get { return webProxy; }
set { webProxy = value; }
}


/// <summary>
/// URL of the Twitter host. Defaults to http://twitter.com/. Why would
/// you need to override this? Think: Alternate endpoints, like other
/// services with identical API's, or maybe a Twitter Proxy.
/// </summary>
public string TwitterServerUrl
{
get
{
if (String.IsNullOrEmpty(twitterServerUrl))
return "http://twitter.com/";
else
return twitterServerUrl;
}
set
{
twitterServerUrl = value;

if (!twitterServerUrl.EndsWith("/"))
twitterServerUrl += "/";
}
}

/// <summary>
/// Url to the Twitter Public Timeline. Defaults to http://twitter.com/statuses/public_timeline
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string PublicTimelineUrl
{
get
{
if (string.IsNullOrEmpty(publicTimelineUrl))
return TwitterServerUrl + "statuses/public_timeline";
else
return publicTimelineUrl;
}
set { publicTimelineUrl = value; }
}

/// <summary>
/// Url to the Twitter Friends Timeline. Defaults to http://twitter.com/statuses/friends_timeline
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string FriendsTimelineUrl
{
get
{
if (string.IsNullOrEmpty(friendsTimelineUrl))
return TwitterServerUrl + "statuses/friends_timeline";
else
return friendsTimelineUrl;
}
set { friendsTimelineUrl = value; }
}

/// <summary>
/// Url to the user's timeline. Defaults to http://twitter.com/statuses/user_timeline
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string UserTimelineUrl
{
get
{
if (string.IsNullOrEmpty(userTimelineUrl))
return TwitterServerUrl + "statuses/user_timeline";
else
return userTimelineUrl;
}
set { userTimelineUrl = value; }
}

/// <summary>
/// Url to the 20 most recent replies (status updates prefixed with @username posted by users who are friends with the user being replied to) to the authenticating user.
/// Defaults to http://twitter.com/statuses/user_timeline
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string RepliesTimelineUrl
{
get
{
if (string.IsNullOrEmpty(repliesTimelineUrl))
return TwitterServerUrl + "statuses/replies";
else
return repliesTimelineUrl;
}
set { repliesTimelineUrl = value; }
}

/// <summary>
/// Url to the list of the 20 most recent direct messages sent to the authenticating user. Defaults to http://twitter.com/direct_messages
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string DirectMessagesUrl
{
get
{
if (string.IsNullOrEmpty(directMessagesUrl))
return TwitterServerUrl + "direct_messages";
else
return directMessagesUrl;
}
set { directMessagesUrl = value; }
}

/// <summary>
/// Url to the Twitter HTTP Post. Defaults to http://twitter.com/statuses/update
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string UpdateUrl
{
get
{
if (string.IsNullOrEmpty(updateUrl))
return TwitterServerUrl + "statuses/update";
else
return updateUrl;
}
set { updateUrl = value; }
}

/// <summary>
/// Url to the user's friends. Defaults to http://twitter.com/statuses/friends
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string FriendsUrl
{
get
{
if (string.IsNullOrEmpty(friendsUrl))
return TwitterServerUrl + "statuses/friends";
else
return friendsUrl;
}
set { friendsUrl = value; }
}

/// <summary>
/// Url to the user's followers. Defaults to http://twitter.com/statuses/followers
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string FollowersUrl
{
get
{
if (string.IsNullOrEmpty(followersUrl))
return TwitterServerUrl + "statuses/followers";
else
return followersUrl;
}
set { followersUrl = value; }
}

/// <summary>
/// Returns extended information of a given user, specified by ID or screen name as per the required id parameter below.
/// This information includes design settings, so third party developers can theme their widgets according to a given user's preferences.
/// Defaults to http://twitter.com/users/show/
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string UserShowUrl
{
get
{
if (string.IsNullOrEmpty(userShowUrl))
return TwitterServerUrl + "users/show/";
else
return userShowUrl;
}
set { userShowUrl = value; }
}

/// <summary>
/// Url to sends a new direct message to the specified user from the authenticating user. Defaults to http://twitter.com/direct_messages/new
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string SendMessageUrl
{
get
{
if (string.IsNullOrEmpty(sendMessageUrl))
return TwitterServerUrl + "direct_messages/new";
else
return sendMessageUrl;
}
set { sendMessageUrl = value; }
}

/// <summary>
/// Url to destroy a status from the authenticating user. Defaults to http://twitter.com/statuses/destroy
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string DestroyUrl
{
get
{
if (string.IsNullOrEmpty(destroyUrl))
return TwitterServerUrl + "statuses/destroy/";
else
return destroyUrl;
}
set { destroyUrl = value; }
}

/// <summary>
/// Url to destroy a direct message from the authenticating user. Defaults to http://twitter.com/direct_messages/destroy/
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string DestroyDirectMessageUrl
{
get
{
if (string.IsNullOrEmpty(destroyDirectMessageUrl))
return TwitterServerUrl + "direct_messages/destroy/";
else
return destroyDirectMessageUrl;
}
set { destroyDirectMessageUrl = value; }
}



public string CreateFriendshipUrl
{
get {
if (string.IsNullOrEmpty(createFriendshipUrl))
{
return TwitterServerUrl + "friendships/create/";
}
else
{
return createFriendshipUrl;
}
}
set { createFriendshipUrl = value; }
}


/// <summary>
/// Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour.
/// Calls to rate_limit_status do not count against the rate limit. If authentication credentials are provided, the rate limit status
/// for the authenticating user is returned. Otherwise, the rate limit status for the requester's IP address is returned. Defaults to
/// http://twitter.com/direct_messages/account/rate_limit_status
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string RateLimitStatusUrl
{
get
{
if (string.IsNullOrEmpty(rateLimitStatusUrl))
{
return TwitterServerUrl + "account/rate_limit_status";
}
else
{
return rateLimitStatusUrl;
}
}
set { rateLimitStatusUrl = value; }
}

/// <summary>
///This is the url to return an individual tweet.
/// </summary>
/// <remarks>
/// Origionally done for "Conversations" but I'm sure it will be re-used.
/// </remarks>
public string TweetUrl
{
get
{
if (string.IsNullOrEmpty(tweetUrl))
{
return TwitterServerUrl + "statuses/show/";
}
else
{
return tweetUrl;
}
}
set { tweetUrl = value; }
}
/// <summary>
/// Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status
/// code and an error message if not. Use this method to test if supplied user credentials are valid. Defaults to
/// http://twitter.com/account/verify_credentials
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string VerifyCredentialsUrl
{
get
{
if (string.IsNullOrEmpty(verifyCredentialsUrl))
{
return TwitterServerUrl + "account/verify_credentials";
}
else
{
return verifyCredentialsUrl;
}
}
set { verifyCredentialsUrl = value; }
}

/// <summary>
/// The format of the results from the twitter API. Ex: .xml, .json, .rss, .atom. Defaults to ".xml"
/// </summary>
/// <remarks>
/// This value should only be changed if Twitter API urls have been changed on http://groups.google.com/group/twitter-development-talk/web/api-documentation
/// </remarks>
public string Format
{
get
{
if (string.IsNullOrEmpty(format))
return ".xml";
else
return format;
}
set { format = value; }
}




/// <summary>
/// The number of characters available for the Tweet text. Defaults to 140.
/// </summary>
/// <remarks>
/// This value should only be changed if the character limit on Twitter.com has been changed.
/// </remarks>
public static int CharacterLimit
{
get
{
if (characterLimit == 0)
return 140;
else
return characterLimit;
}
set { characterLimit = value; }
}

/// <summary>
/// The name of the current client. Defaults to "Witty"
/// </summary>
/// <remarks>
/// This value can be changed if you're using this Library for your own twitter client
/// </remarks>
public string ClientName
{
get
{
if (string.IsNullOrEmpty(clientName))
return "witty";
else
return clientName;
}
set { clientName = value; }
}

#endregion

#region Constructors

/// <summary>
/// Unauthenticated constructor
/// </summary>
public TwitterNet()
{
}

/// <summary>
/// Authenticated constructor
/// </summary>
public TwitterNet(string username, SecureString password)
{
this.username = username;
this.password = password;
}

/// <summary>
/// Authenticated constructor with Proxy.
/// </summary>
/// <remarks>
/// JMF: Note that this constructor should not be necessary. The default proxy
/// (HttpWebRequest.DefaultWebProxy) needs to be set to the user-configured
/// proxy setting during app startup so that WPF controls that access the
/// internet directly (like Image controls) can do so.
/// </remarks>
public TwitterNet(string username, SecureString password, IWebProxy webProxy)
{
this.username = username;
this.password = password;
this.webProxy = webProxy;
}

#endregion

#region Public Methods

#region Timeline Methods

/// <summary>
/// Retrieves the public timeline
/// </summary>
public TweetCollection GetPublicTimeline()
{
return RetrieveTimeline(Timeline.Public);
}

/// <summary>
/// Retrieves the public timeline. Narrows the result to after the since date.
/// </summary>
public TweetCollection GetPublicTimeline(string since)
{
return RetrieveTimeline(Timeline.Public, since);
}

/// <summary>
/// Retrieves the friends timeline
/// </summary>
public TweetCollection GetFriendsTimeline()
{
if (!string.IsNullOrEmpty(username))
return RetrieveTimeline(Timeline.Friends);
else
return RetrieveTimeline(Timeline.Public);
}

/// <summary>
/// Retrieves the friends timeline. Narrows the result to after the since date.
/// </summary>
public TweetCollection GetFriendsTimeline(string since)
{
if (!string.IsNullOrEmpty(username))
return RetrieveTimeline(Timeline.Friends, since);
else
return RetrieveTimeline(Timeline.Public, since);
}

/// <summary>
/// Retrieves the friends timeline. Narrows the result to after the since date.
/// </summary>
public TweetCollection GetFriendsTimeline(string since, string userId)
{
return RetrieveTimeline(Timeline.Friends, since, userId);
}

public TweetCollection GetUserTimeline(string userId)
{
return RetrieveTimeline(Timeline.User, string.Empty, userId);
}

public TweetCollection GetReplies()
{
return RetrieveTimeline(Timeline.Replies);
}

public TweetCollection GetReplies(string since)
{
return RetrieveTimeline(Timeline.Replies, since);
}

public TweetCollection GetConversation(double id)
{
TweetCollection tweets = new TweetCollection();
Tweet tweet = RetrieveTweet(id);
while (tweet.InReplyTo != null)
{
tweets.Add(tweet);
id = (double)tweet.InReplyTo;
tweet = RetrieveTweet(id);
}

tweets.Add(tweet);
return tweets;
}

#endregion

/// <summary>
/// Returns the authenticated user's friends who have most recently updated, each with current status inline.
/// </summary>
public UserCollection GetFriends()
{
return GetFriends(CurrentlyLoggedInUser.Id);
}

/// <summary>
/// Returns the user's friends who have most recently updated, each with current status inline.
/// </summary>
public UserCollection GetFriends(int userId)
{
try
{
UserCollection users = new UserCollection();

//This is ugly - we're mapping from TweetSharp users to our internal Twitter class
//This will all go away when we move wholesale to TweetSharp
foreach (TwitterUser user in GetFriendsInternal())
users.Add(CreateUser(user));

return users;
}
catch
{
return null;
}
}

public IEnumerable<TwitterUser> GetFriendsInternal()
{
IEnumerable<TwitterUser> _friends;

var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(username, ToInsecureString(password))
.Configuration.UseGzipCompression() //now using compression for performance
.Users().GetFriends().For(username)
.CreateCursor()
.AsJson();
_friends = GetAllCursorValues(twitter, s => s.AsUsers());

return _friends; //return either the newly fetched list, or the cached copy
}

private static IEnumerable<T> GetAllCursorValues<T>(ITwitterLeafNode twitter, Func<TwitterResult, IEnumerable<T>> conversionMethod)
{
long? nextCursor = -1 ;
var ret = new List<T>();
do
{
twitter.Root.Parameters.Cursor = nextCursor;
var response = twitter.Request();
IEnumerable<T> values = conversionMethod(response);
if (values != null)
{
ret.AddRange(values);
}
nextCursor = response.AsNextCursor();
} while (nextCursor.HasValue && nextCursor.Value != 0);
return ret;
}

public User GetUser(int userId)
{
User user = new User();

// Twitter expects http://twitter.com/users/show/12345.xml
string requestURL = UserShowUrl + userId + Format;

HttpWebRequest request = CreateTwitterRequest(requestURL);

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Load the response data into a XmlDocument
XmlDocument doc = new XmlDocument();
doc.Load(reader);

// Get statuses with XPath
XmlNode userNode = doc.SelectSingleNode("user");

if (userNode != null)
{
user = CreateUser(userNode);
}
}

return user;
}

public void PostPhoto(System.IO.FileInfo file, string text)
{

//var twitter = FluentTwitter.CreateRequest()
//.AuthenticateAs(username, ToInsecureString(password))
//.Statuses().Update("test")
//.AsJson();

//var response = twitter.Request();
System.Net.ServicePointManager.Expect100Continue = false;

var request = FluentTwitter.CreateRequest(new Dimebrain.TweetSharp.TwitterClientInfo() { ClientName = "Witty" })
.AuthenticateAs(username, ToInsecureString(password))
.Photos().PostPhoto(file.FullName, Dimebrain.TweetSharp.Fluent.Services.SendPhotoServiceProvider.TwitGoo)
.Statuses().Update(text)
.AsJson();
var response = request.Request();
string monkey = response.AsStatus().Text;
}

/// <summary>
/// Delete a tweet from a users timeline
/// </summary>
/// <param name="id">id of the Tweet to delete</param>
public void DestroyTweet(double id)
{
string urlToCall = string.Format("{0}{1:g}{2}", DestroyUrl, id, Format);
MakeDestroyRequestCall(urlToCall);
}

/// <summary>
/// Destroy a direct message sent by a user
/// </summary>
/// <param name="id">id of the direct message to delete</param>
public void DestroyDirectMessage(double id)
{
string urlToCall = string.Format("{0}{1:g}{2}", DestroyDirectMessageUrl, id, Format);
MakeDestroyRequestCall(urlToCall);
}

/// <summary>
/// Post new tweet to Twitter
/// </summary>
/// <returns>newly added tweet</returns>
public Tweet AddTweet(string text)
{
return AddTweet(text, 0);
}

public Tweet AddTweet(string text, double replyid)
{
Tweet tweet = new Tweet();
tweet.IsDirectMessage = (text.StartsWith("d ", StringComparison.CurrentCultureIgnoreCase));

if (string.IsNullOrEmpty(text))
return null;

text = HttpUtility.UrlEncode(text);

// Create the web request
HttpWebRequest request = CreateTwitterRequest(UpdateUrl + Format);

request.ServicePoint.Expect100Continue = false;

request.Method = "POST";

// Set values for the request back
request.ContentType = "application/x-www-form-urlencoded";
string param = "status=" + text;
string replyParam = "&in_reply_to_status_id=" + replyid.ToString();
string sourceParam = "&source=" + ClientName;
request.ContentLength = param.Length + sourceParam.Length;
if (replyid > 0)
{
request.ContentLength += replyParam.Length;
}

// Write the request paramater
StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(param);
stOut.Write(sourceParam);
if (replyid > 0)
{
stOut.Write(replyParam);
}
stOut.Close();

// Do the request to get the response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Load the response data into a XmlDocument
XmlDocument doc = new XmlDocument();
doc.Load(reader);

XmlNode node = doc.SelectSingleNode("status");

tweet.Id = double.Parse(node.SelectSingleNode("id").InnerText);

//Defect 43 - Twitter incorrectly returns last tweet sent when you direct message someone.
tweet.Text = tweet.IsDirectMessage
? HttpUtility.UrlDecode(text)
: HttpUtility.HtmlDecode(node.SelectSingleNode("text").InnerText);

string source = HttpUtility.HtmlDecode(node.SelectSingleNode("source").InnerText);
// Remove html from the source string
if (!string.IsNullOrEmpty(source))
tweet.Source = Regex.Replace(source, @"<(.|\n)*?>", string.Empty);

string dateString = node.SelectSingleNode("created_at").InnerText;
if (!string.IsNullOrEmpty(dateString))
{
tweet.DateCreated = DateTime.ParseExact(
dateString,
twitterCreatedAtDateFormat,
CultureInfo.GetCultureInfoByIetfLanguageTag("en-us"), DateTimeStyles.AllowWhiteSpaces);
}
string replyTo = HttpUtility.HtmlDecode(node.SelectSingleNode("in_reply_to_status_id").InnerText);
if (!string.IsNullOrEmpty(replyTo))
{
tweet.InReplyTo = double.Parse(HttpUtility.HtmlDecode(node.SelectSingleNode("in_reply_to_status_id").InnerText));

}
tweet.IsNew = true;


XmlNode userNode = node.SelectSingleNode("user");
User user = CreateUser(userNode);
tweet.User = user;
}

return tweet;
}

protected string GetPropertyFromXml(XmlNode twitterNode, string propertyName)
{
if (twitterNode != null)
{
XmlNode propertyNode = twitterNode.SelectSingleNode(propertyName);
if (propertyNode != null)
{
return propertyNode.InnerText;
}
}
return String.Empty;
}

private User CreateUser(XmlNode userNode)
{
User user = new User();

if (userNode != null)
{
int temp = -1;
int.TryParse(GetPropertyFromXml(userNode, "id"), out temp);
user.Id = temp;

user.Name = GetPropertyFromXml(userNode, "name");
user.ScreenName = GetPropertyFromXml(userNode, "screen_name");
user.ImageUrl = GetPropertyFromXml(userNode, "profile_image_url");
user.SiteUrl = GetPropertyFromXml(userNode, "url");
user.Location = GetPropertyFromXml(userNode, "location");
user.Description = GetPropertyFromXml(userNode, "description");
user.BackgroundColor = GetPropertyFromXml(userNode, "profile_background_color");
user.TextColor = GetPropertyFromXml(userNode, "profile_text_color");
user.LinkColor = GetPropertyFromXml(userNode, "profile_link_color");
user.SidebarBorderColor = GetPropertyFromXml(userNode, "profile_sidebar_border_color");
user.SidebarFillColor = GetPropertyFromXml(userNode, "profile_sidebar_fill_color");

temp = 0;
int.TryParse(GetPropertyFromXml(userNode, "friends_count"), out temp);
user.FollowingCount = temp;

temp = 0;
int.TryParse(GetPropertyFromXml(userNode, "favourites_count"), out temp);
user.FavoritesCount = temp;

temp = 0;
int.TryParse(GetPropertyFromXml(userNode, "statuses_count"), out temp);
user.StatusesCount = temp;

temp = 0;
int.TryParse(GetPropertyFromXml(userNode, "followers_count"), out temp);
user.FollowersCount = temp;
}

return user;
}

private User CreateUser(TwitterUser twitterUser)
{
User user = new User();

if (twitterUser != null)
{
user.Id = twitterUser.Id;

user.Name = twitterUser.Name;
user.ScreenName = twitterUser.ScreenName;
user.ImageUrl = twitterUser.ProfileImageUrl;
user.SiteUrl = twitterUser.Url;
user.Location = twitterUser.Location;
user.Description = twitterUser.Description;
user.BackgroundColor = twitterUser.ProfileBackgroundColor;
user.TextColor = twitterUser.ProfileTextColor;
user.LinkColor = twitterUser.ProfileLinkColor;
user.SidebarBorderColor = twitterUser.ProfileSidebarBorderColor;
user.SidebarFillColor = twitterUser.ProfileSidebarFillColor;
user.FollowingCount = twitterUser.FriendsCount;
user.FavoritesCount = twitterUser.FavouritesCount;
user.StatusesCount = twitterUser.StatusesCount;
user.FollowersCount = twitterUser.FollowersCount;
}

return user;
}

/// <summary>
/// Authenticating with the provided credentials and retrieve the user's settings
/// </summary>
/// <returns></returns>
public User Login()
{
User user = new User();

// Create the web request
HttpWebRequest request = CreateTwitterRequest(VerifyCredentialsUrl + Format);

try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Load the response data into a XmlDocument
XmlDocument doc = new XmlDocument();
doc.Load(reader);

// Get statuses with XPath
XmlNode userNode = doc.SelectSingleNode("user");

if (userNode != null)
{
user = CreateUser(userNode);
}
}
}
catch (WebException webExcp)
{
ParseWebException(webExcp);
}
currentLoggedInUser = user;
return user;
}

#region Secure String Members
static byte[] entropy = System.Text.Encoding.Unicode.GetBytes("WittyPasswordSalt");

/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string EncryptString(System.Security.SecureString input)
{
byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect(
System.Text.Encoding.Unicode.GetBytes(ToInsecureString(input)),
entropy,
System.Security.Cryptography.DataProtectionScope.CurrentUser);
return Convert.ToBase64String(encryptedData);
}

public static SecureString ToSecureString(string input)
{
SecureString secure = new SecureString();
foreach (char c in input)
{
secure.AppendChar(c);
}
secure.MakeReadOnly();
return secure;
}

public static string ToInsecureString(SecureString input)
{
string returnValue = string.Empty;
IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(input);
try
{
returnValue = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(ptr);
}
finally
{
System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(ptr);
}
return returnValue;
}

/// <summary>
///
/// </summary>
/// <param name="encryptedData"></param>
/// <returns></returns>
public static SecureString DecryptString(string encryptedData)
{
try
{
byte[] decryptedData = System.Security.Cryptography.ProtectedData.Unprotect(
Convert.FromBase64String(encryptedData),
entropy,
System.Security.Cryptography.DataProtectionScope.CurrentUser);
return ToSecureString(System.Text.Encoding.Unicode.GetString(decryptedData));
}
catch
{
return new SecureString();
}
}
#endregion

/// <summary>
/// Get rate limit status for the user
/// </summary>
/// <returns>String with the number of usages left out over the total, e.g. "93/100"</returns>
public string RetrieveRateLimitStatus()
{
HttpWebRequest request = CreateTwitterRequest(RateLimitStatusUrl + Format);
string result = String.Empty;

try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());

XmlDocument doc = new XmlDocument();
doc.Load(reader);

XmlNode limit = doc.SelectSingleNode("/hash/hourly-limit");
XmlNode remaining = doc.SelectSingleNode("/hash/remaining-hits");
result = remaining.InnerText + "/" + limit.InnerText;
}
}
catch (WebException webExcp)
{
ParseWebException(webExcp);
}
return result;
}

public DirectMessageCollection RetrieveMessages()
{
return RetrieveMessages(string.Empty);
}

/// <summary>
/// Gets direct messages for the user
/// </summary>
/// <returns>Collection of direct messages</returns>
public DirectMessageCollection RetrieveMessages(string since)
{
DirectMessageCollection messages = new DirectMessageCollection();

string url = DirectMessagesUrl + Format;

if (!string.IsNullOrEmpty(since))
{
DateTime sinceDate;
DateTime.TryParse(since, out sinceDate);

// Go back a minute to compensate for latency.
sinceDate = sinceDate.AddMinutes(-1);
string sinceDateString = sinceDate.ToString(twitterSinceDateFormat);
url += "?since=" + sinceDateString;
}

HttpWebRequest request = CreateTwitterRequest(url);

try
{
// Get the Response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Load the response data into a XmlDocument
XmlDocument doc = new XmlDocument();
doc.Load(reader);

// Get statuses with XPath
XmlNodeList nodes = doc.SelectNodes("/direct-messages/direct_message");

foreach (XmlNode node in nodes)
{
DirectMessage message = new DirectMessage();
message.Id = double.Parse(node.SelectSingleNode("id").InnerText);
message.Text = HttpUtility.HtmlDecode(node.SelectSingleNode("text").InnerText);

string dateString = node.SelectSingleNode("created_at").InnerText;
if (!string.IsNullOrEmpty(dateString))
{
message.DateCreated = DateTime.ParseExact(
dateString,
twitterCreatedAtDateFormat,
CultureInfo.GetCultureInfoByIetfLanguageTag("en-us"), DateTimeStyles.AllowWhiteSpaces);
}

XmlNode senderNode = node.SelectSingleNode("sender");
User sender = CreateUser(senderNode);
message.Sender = sender;

XmlNode recipientNode = node.SelectSingleNode("recipient");
User recipient = CreateUser(recipientNode);
message.Recipient = recipient;

messages.Add(message);
}
}
}
catch (WebException webExcp)
{
ParseWebException(webExcp);
}
return messages;
}

public Tweet RetrieveTweet(double id)
{
Tweet tweet = new Tweet();

string url = string.Format("{0}{1}{2}", TweetUrl, id, Format);




HttpWebRequest request = CreateTwitterRequest(url);
try
{
// Get the Response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Load the response data into a XmlDocument
XmlDocument doc = new XmlDocument();
doc.Load(reader);

// Get statuses with XPath
XmlNode node = doc.SelectSingleNode("/status");

tweet.Id = double.Parse(node.SelectSingleNode("id").InnerText);
tweet.Text = HttpUtility.HtmlDecode(node.SelectSingleNode("text").InnerText);
string source = HttpUtility.HtmlDecode(node.SelectSingleNode("source").InnerText);
if (!string.IsNullOrEmpty(source))
tweet.Source = Regex.Replace(source, @"<(.|\n)*?>", string.Empty);

string dateString = node.SelectSingleNode("created_at").InnerText;
if (!string.IsNullOrEmpty(dateString))
{
tweet.DateCreated = DateTime.ParseExact(
dateString,
twitterCreatedAtDateFormat,
CultureInfo.GetCultureInfoByIetfLanguageTag("en-us"), DateTimeStyles.AllowWhiteSpaces);
}
string replyTo = HttpUtility.HtmlDecode(node.SelectSingleNode("in_reply_to_status_id").InnerText);
if (!string.IsNullOrEmpty(replyTo))
{
tweet.InReplyTo = double.Parse(HttpUtility.HtmlDecode(node.SelectSingleNode("in_reply_to_status_id").InnerText));

}
XmlNode userNode = node.SelectSingleNode("user");
User user = CreateUser(userNode);
tweet.User = user;
tweet.IsReply = IsReplyTweet(this.CurrentlyLoggedInUser.ScreenName, tweet);


}
}
catch (WebException webExcp)
{
ParseWebException(webExcp);
}

return tweet;
}

public void SendMessage(string user, string text)
{
// Jason Follas: Make sure that the user isn't trying to DM themselves.
if (String.Compare(user, CurrentlyLoggedInUser.ScreenName, true) == 0)
return;

if (string.IsNullOrEmpty(text))
return;

text = HttpUtility.UrlEncode(text);

// Create the web request
HttpWebRequest request = CreateTwitterRequest(SendMessageUrl + Format);
request.ServicePoint.Expect100Continue = false;

request.Method = "POST";

// Set values for the request back
request.ContentType = "application/x-www-form-urlencoded";
string param = "text=" + text;
string userParam = "&user=" + user;
request.ContentLength = param.Length + userParam.Length;

// Write the request paramater
StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(param);
stOut.Write(userParam);
stOut.Close();

try
{
// Perform the web request
request.GetResponse();
}
catch (WebException webExcp)
{
ParseWebException(webExcp);
}

}

/// <summary>
/// Follow the user specified by userId
/// </summary>
/// <param name="userId"></param>
public void FollowUser(string userName)
{
// Jason Follas: Make sure that the user isn't trying to follow themselves.
if (String.Compare(userName, CurrentlyLoggedInUser.ScreenName, true) == 0)
return;

string followUrl = CreateFriendshipUrl + userName + Format;
MakeTwitterApiCall(followUrl, "POST");
}

#endregion

#region Private Methods

/// <summary>
/// Retrieves the specified timeline from Twitter
/// </summary>
/// <returns>Collection of Tweets</returns>
private TweetCollection RetrieveTimeline(Timeline timeline)
{
return RetrieveTimeline(timeline, string.Empty);
}

/// <summary>
/// Retrieves the specified timeline from Twitter
/// </summary>
/// <returns>Collection of Tweets</returns>
private TweetCollection RetrieveTimeline(Timeline timeline, string since)
{
return RetrieveTimeline(timeline, since, string.Empty);
}

/// <summary>
/// The Main function for interfacing with the Twitter API
/// </summary>
/// <returns>Collection of Tweets. Twitter limits the max to 20.</returns>
private TweetCollection RetrieveTimeline(Timeline timeline, string since, string userId)
{
TweetCollection tweets = new TweetCollection();

string timelineUrl;

switch (timeline)
{
case Timeline.Public:
timelineUrl = PublicTimelineUrl;
break;
case Timeline.Friends:
timelineUrl = FriendsTimelineUrl;
break;
case Timeline.User:
timelineUrl = UserTimelineUrl;
break;
case Timeline.Replies:
timelineUrl = RepliesTimelineUrl;
break;
default:
timelineUrl = PublicTimelineUrl;
break;
}

if (!string.IsNullOrEmpty(userId))
timelineUrl += "/" + userId + Format;
else
timelineUrl += Format;

if (!string.IsNullOrEmpty(since))
{
DateTime sinceDate;
DateTime.TryParse(since, out sinceDate);

// Go back a minute to compensate for latency.
sinceDate = sinceDate.AddMinutes(-1);
string sinceDateString = sinceDate.ToString(twitterSinceDateFormat);
timelineUrl = timelineUrl + "?since=" + sinceDateString;
}

// Create the web request
HttpWebRequest request = CreateTwitterRequest(timelineUrl);

// moved this out of the try catch to use it later on in the XMLException
// trying to fix a bug someone report
XmlDocument doc = new XmlDocument();
try
{
// Get the Web Response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Load the response data into a XmlDocument
doc.Load(reader);
// Get statuses with XPath
XmlNodeList nodes = doc.SelectNodes("/statuses/status");

foreach (XmlNode node in nodes)
{
Tweet tweet = new Tweet();
tweet.Id = double.Parse(node.SelectSingleNode("id").InnerText);
tweet.Text = HttpUtility.HtmlDecode(node.SelectSingleNode("text").InnerText);
string source = HttpUtility.HtmlDecode(node.SelectSingleNode("source").InnerText);
if (!string.IsNullOrEmpty(source))
tweet.Source = Regex.Replace(source, @"<(.|\n)*?>", string.Empty);

string dateString = node.SelectSingleNode("created_at").InnerText;
if (!string.IsNullOrEmpty(dateString))
{
tweet.DateCreated = DateTime.ParseExact(
dateString,
twitterCreatedAtDateFormat,
CultureInfo.GetCultureInfoByIetfLanguageTag("en-us"), DateTimeStyles.AllowWhiteSpaces);
}
string replyTo = HttpUtility.HtmlDecode(node.SelectSingleNode("in_reply_to_status_id").InnerText);
if (!string.IsNullOrEmpty(replyTo))
{
tweet.InReplyTo = double.Parse(HttpUtility.HtmlDecode(node.SelectSingleNode("in_reply_to_status_id").InnerText));

}
XmlNode userNode = node.SelectSingleNode("user");
User user = CreateUser(userNode);
tweet.User = user;
tweet.Timeline = timeline;
tweet.IsReply = IsReplyTweet(this.CurrentlyLoggedInUser.ScreenName, tweet);

tweets.Add(tweet);
}

tweets.SaveToDisk();
}
}
catch (XmlException exXML)
{
// adding the XML document data to the exception so it will get logged
// so we can debug the issue
exXML.Data.Add("XMLDoc", doc);
throw;
}
catch (WebException webExcp)
{
ParseWebException(webExcp, timeline, userId);
}
return tweets;
}

private bool IsReplyTweet(string userId, Tweet tweet)
{
if (tweet.Timeline == Timeline.Replies)
return true;

if (tweet.Timeline == Timeline.Friends)
{
if (tweet.Text.Contains("@" + userId))
return true;
}

return false;
}

/// <summary>
/// Generic call to destroy a status ** still in progress **
/// </summary>
/// <param name="urlToCall"></param>
private void MakeDestroyRequestCall(string urlToCall)
{
MakeTwitterApiCall(urlToCall, "POST");
}

/// <summary>
/// Default Twitter API call uses GET
/// </summary>
/// <param name="urlToCall"></param>
private void MakeTwitterApiCall(string urlToCall)
{
MakeTwitterApiCall(urlToCall, "GET");
}

/// <summary>
/// Generic Twitter API call. Use this when you don't need/want to parse the return message
/// and just want to make a succeed/fail call to the API.
/// </summary>
/// <param name="urlToCall"></param>
private void MakeTwitterApiCall(string urlToCall, string method)
{
//REMARK: We may want to refactor this to return the message returned by the API.
// Create the web request
HttpWebRequest request = CreateTwitterRequest(urlToCall);
request.ServicePoint.Expect100Continue = false;

request.Method = method;

try
{
// perform the destroy web request
request.GetResponse();
}
catch (WebException webExcp)
{
ParseWebException(webExcp);
}
}


private HttpWebRequest CreateTwitterRequest(string Uri)
{
// Create the web request
HttpWebRequest request = WebRequest.Create(Uri) as HttpWebRequest;

// Add credentials to request
byte[] authBytes = Encoding.UTF8.GetBytes(String.Format("{0}:{1}",username,TwitterNet.ToInsecureString(password)).ToCharArray());
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);

// Add configured web proxy
request.Proxy = webProxy;
return request;
}

private void ParseWebException(WebException webExcp)
{
ParseWebException(webExcp, null, null);
}

private void ParseWebException(WebException webExcp, Timeline? timeline, string userId)
{
// Get the WebException status code.
WebExceptionStatus status = webExcp.Status;
// If status is WebExceptionStatus.ProtocolError,
// there has been a protocol error and a WebResponse
// should exist. Display the protocol error.
if (status == WebExceptionStatus.ProtocolError)
{
// Get HttpWebResponse so that you can check the HTTP status code.
HttpWebResponse httpResponse = (HttpWebResponse)webExcp.Response;

switch (httpResponse.StatusCode)
{
case HttpStatusCode.NotModified: // no new tweets so ignore error.
break;

case HttpStatusCode.BadRequest: // rate limit exceeded
string message = String.Format("Rate limit exceeded. You have {0} of your requests left. Please try again in a few minutes", RetrieveRateLimitStatus());
throw new RateLimitException(message);

case HttpStatusCode.Unauthorized:
throw new SecurityException("Not Authorized.");

case HttpStatusCode.NotFound: // specified user does not exist
if (timeline == Timeline.User)
throw new UserNotFoundException(userId, "@" + userId + " does not exist (probably mispelled)");
else // what if a 404 happens to occur in another scenario?
throw webExcp;

case HttpStatusCode.ProxyAuthenticationRequired:
throw new ProxyAuthenticationRequiredException("Proxy authentication required.");

case HttpStatusCode.RequestTimeout:
throw new RequestTimeoutException("Request timed out. We'll try again in a few minutes");

case HttpStatusCode.BadGateway: //Twitter is freaking out.
throw new BadGatewayException("Fail Whale! There was a problem calling the Twitter API. Please try again in a few minutes.");

default:
throw webExcp;
}
}
else if (status == WebExceptionStatus.ProxyNameResolutionFailure)
{
throw new ProxyNotFoundException("The proxy server could not be found. Check that it was entered correctly in the Options dialog. You may need to disable your web proxy in the Options, if for instance you use a proxy server at work and are now at home.");
}
else throw webExcp;
}

#endregion
}

/// <summary>
/// Enumeration of available Twitter timelines
/// </summary>
public enum Timeline
{
Public,
Friends,
User,
Replies,
DirectMessages
}
}

Change log

r493 by jongalloway on Feb 6, 2010   Diff
Added K. Scott Allen's search patch.
Combined search and conversations. Fixed
autocomplete bug.
Go to: 
Sign in to write a code review

Older revisions

r482 by jongalloway on Jun 29, 2009   Diff
Added TwitGoo support and support for
u.nu URL shortening.
r478 by jongalloway on Jun 11, 2009   Diff
Upgraded tweet# to latest version.
Fixed a problem with friends list
fetch (was fetching followers, not
friends). Options dialog is now
windowless, too.
r471 by jongalloway on May 24, 2009   Diff
Applied patches:
110 - Don't show "D <name>" after
sending direct messages
187 - Add tr.im as a URL shortening
service
All revisions of this file

File info

Size: 58084 bytes, 1524 lines
Powered by Google Project Hosting