dev
リビジョン | 7b5749f36576a627552c579c91c26f252b33609a (tree) |
---|---|
日時 | 2013-07-05 04:36:52 |
作者 | Kimura Youichi <kim.upsilon@bucy...> |
コミッター | Kimura Youichi |
APIレートリミット表示がタイミングによって不整合を起こす問題を修正
複数のAPIへ同時にアクセスした場合などにエンドポイント毎のレートリミットの
記録がおかしくなる問題が存在していた
@@ -150,7 +150,7 @@ namespace OpenTween | ||
150 | 150 | if ( callback != null ) |
151 | 151 | { |
152 | 152 | StackFrame frame = new StackFrame( 1 ); |
153 | - callback( frame.GetMethod().Name, code, content ); | |
153 | + callback( frame.GetMethod().Name, code, headerInfo, content ); | |
154 | 154 | } |
155 | 155 | return code; |
156 | 156 | } |
@@ -183,7 +183,7 @@ namespace OpenTween | ||
183 | 183 | if ( callback != null ) |
184 | 184 | { |
185 | 185 | StackFrame frame = new StackFrame( 1 ); |
186 | - callback( frame.GetMethod().Name, code, content ); | |
186 | + callback( frame.GetMethod().Name, code, headerInfo, content ); | |
187 | 187 | } |
188 | 188 | return code; |
189 | 189 | } |
@@ -74,20 +74,6 @@ namespace OpenTween | ||
74 | 74 | private static string tks = ""; |
75 | 75 | private static string un = ""; |
76 | 76 | |
77 | - private Dictionary<string, string> apiStatusHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) | |
78 | - { | |
79 | - {"X-Access-Level", ""}, | |
80 | - {"X-RateLimit-Limit", ""}, | |
81 | - {"X-RateLimit-Remaining", ""}, | |
82 | - {"X-RateLimit-Reset", ""}, | |
83 | - {"X-Rate-Limit-Limit", ""}, | |
84 | - {"X-Rate-Limit-Remaining", ""}, | |
85 | - {"X-Rate-Limit-Reset", ""}, | |
86 | - {"X-MediaRateLimit-Limit", ""}, | |
87 | - {"X-MediaRateLimit-Remaining", ""}, | |
88 | - {"X-MediaRateLimit-Reset", ""}, | |
89 | - }; | |
90 | - | |
91 | 77 | static HttpTwitter() |
92 | 78 | { |
93 | 79 | HttpTwitter.API11Enabled = true; |
@@ -238,7 +224,7 @@ namespace OpenTween | ||
238 | 224 | param, |
239 | 225 | binary, |
240 | 226 | ref content, |
241 | - this.apiStatusHeaders, | |
227 | + this.CreateRetelimitHeadersDict(), | |
242 | 228 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/update_with_media") : GetApiCallback); |
243 | 229 | } |
244 | 230 |
@@ -307,7 +293,7 @@ namespace OpenTween | ||
307 | 293 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/users/show.json" : "/1/users/show.json"), |
308 | 294 | param, |
309 | 295 | ref content, |
310 | - this.apiStatusHeaders, | |
296 | + this.CreateRetelimitHeadersDict(), | |
311 | 297 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/users/show/:id") : GetApiCallback); |
312 | 298 | } |
313 | 299 |
@@ -386,7 +372,7 @@ namespace OpenTween | ||
386 | 372 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/show.json" : "/1/friendships/show.json"), |
387 | 373 | param, |
388 | 374 | ref content, |
389 | - this.apiStatusHeaders, | |
375 | + this.CreateRetelimitHeadersDict(), | |
390 | 376 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/friendships/show") : GetApiCallback); |
391 | 377 | } |
392 | 378 |
@@ -398,7 +384,7 @@ namespace OpenTween | ||
398 | 384 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/show/" + id + ".json" : "/1/statuses/show/" + id + ".json"), |
399 | 385 | param, |
400 | 386 | ref content, |
401 | - this.apiStatusHeaders, | |
387 | + this.CreateRetelimitHeadersDict(), | |
402 | 388 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/show/:id") : GetApiCallback); |
403 | 389 | } |
404 | 390 |
@@ -446,7 +432,7 @@ namespace OpenTween | ||
446 | 432 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/home_timeline.json" : "/1/statuses/home_timeline.json"), |
447 | 433 | param, |
448 | 434 | ref content, |
449 | - this.apiStatusHeaders, | |
435 | + this.CreateRetelimitHeadersDict(), | |
450 | 436 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/home_timeline") : GetApiCallback); |
451 | 437 | } |
452 | 438 |
@@ -475,7 +461,7 @@ namespace OpenTween | ||
475 | 461 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/user_timeline.json" : "/1/statuses/user_timeline.json"), |
476 | 462 | param, |
477 | 463 | ref content, |
478 | - this.apiStatusHeaders, | |
464 | + this.CreateRetelimitHeadersDict(), | |
479 | 465 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/user_timeline") : GetApiCallback); |
480 | 466 | } |
481 | 467 |
@@ -497,7 +483,7 @@ namespace OpenTween | ||
497 | 483 | CreateTwitterUri("/1/statuses/public_timeline.json"), |
498 | 484 | param, |
499 | 485 | ref content, |
500 | - this.apiStatusHeaders, | |
486 | + this.CreateRetelimitHeadersDict(), | |
501 | 487 | GetApiCallback); |
502 | 488 | } |
503 | 489 |
@@ -517,7 +503,7 @@ namespace OpenTween | ||
517 | 503 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/mentions_timeline.json" : "/1/statuses/mentions.json"), |
518 | 504 | param, |
519 | 505 | ref content, |
520 | - this.apiStatusHeaders, | |
506 | + this.CreateRetelimitHeadersDict(), | |
521 | 507 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/mentions_timeline") : GetApiCallback); |
522 | 508 | } |
523 | 509 |
@@ -536,7 +522,7 @@ namespace OpenTween | ||
536 | 522 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages.json" : "/1/direct_messages.json"), |
537 | 523 | param, |
538 | 524 | ref content, |
539 | - this.apiStatusHeaders, | |
525 | + this.CreateRetelimitHeadersDict(), | |
540 | 526 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/direct_messages") : GetApiCallback); |
541 | 527 | } |
542 | 528 |
@@ -555,7 +541,7 @@ namespace OpenTween | ||
555 | 541 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/sent.json" : "/1/direct_messages/sent.json"), |
556 | 542 | param, |
557 | 543 | ref content, |
558 | - this.apiStatusHeaders, | |
544 | + this.CreateRetelimitHeadersDict(), | |
559 | 545 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/direct_messages/sent") : GetApiCallback); |
560 | 546 | } |
561 | 547 |
@@ -575,7 +561,7 @@ namespace OpenTween | ||
575 | 561 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/list.json" : "/1/favorites.json"), |
576 | 562 | param, |
577 | 563 | ref content, |
578 | - this.apiStatusHeaders, | |
564 | + this.CreateRetelimitHeadersDict(), | |
579 | 565 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/favorites/list") : GetApiCallback); |
580 | 566 | } |
581 | 567 |
@@ -639,7 +625,7 @@ namespace OpenTween | ||
639 | 625 | HttpTwitter.API11Enabled ? this.CreateTwitterUri("/1.1/search/tweets.json") : this.CreateTwitterSearchUri("/search.json"), |
640 | 626 | param, |
641 | 627 | ref content, |
642 | - null, | |
628 | + this.CreateRetelimitHeadersDict(), | |
643 | 629 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/search/tweets") : GetApiCallback); |
644 | 630 | } |
645 | 631 |
@@ -649,7 +635,7 @@ namespace OpenTween | ||
649 | 635 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/saved_searches/list.json" : "/1/saved_searches.json"), |
650 | 636 | null, |
651 | 637 | ref content, |
652 | - null, | |
638 | + this.CreateRetelimitHeadersDict(), | |
653 | 639 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/saved_searches/list") : GetApiCallback); |
654 | 640 | } |
655 | 641 |
@@ -662,7 +648,7 @@ namespace OpenTween | ||
662 | 648 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/followers/ids.json" : "/1/followers/ids.json"), |
663 | 649 | param, |
664 | 650 | ref content, |
665 | - this.apiStatusHeaders, | |
651 | + this.CreateRetelimitHeadersDict(), | |
666 | 652 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/followers/ids") : GetApiCallback); |
667 | 653 | } |
668 | 654 |
@@ -675,7 +661,7 @@ namespace OpenTween | ||
675 | 661 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/no_retweets/ids.json" : "/1/friendships/no_retweet_ids.json"), |
676 | 662 | param, |
677 | 663 | ref content, |
678 | - this.apiStatusHeaders, | |
664 | + this.CreateRetelimitHeadersDict(), | |
679 | 665 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/friendships/no_retweets/ids") : GetApiCallback); |
680 | 666 | } |
681 | 667 |
@@ -685,7 +671,7 @@ namespace OpenTween | ||
685 | 671 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/application/rate_limit_status.json" : "/1/account/rate_limit_status.json"), |
686 | 672 | null, |
687 | 673 | ref content, |
688 | - this.apiStatusHeaders, | |
674 | + this.CreateRetelimitHeadersDict(), | |
689 | 675 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/application/rate_limit_status") : GetApiCallback); |
690 | 676 | } |
691 | 677 |
@@ -702,7 +688,7 @@ namespace OpenTween | ||
702 | 688 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/list.json" : "/1/lists.json"), |
703 | 689 | param, |
704 | 690 | ref content, |
705 | - this.apiStatusHeaders, | |
691 | + this.CreateRetelimitHeadersDict(), | |
706 | 692 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/list") : GetApiCallback); |
707 | 693 | } |
708 | 694 |
@@ -753,7 +739,7 @@ namespace OpenTween | ||
753 | 739 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/subscriptions.json" : "/1/lists/subscriptions.json"), |
754 | 740 | param, |
755 | 741 | ref content, |
756 | - this.apiStatusHeaders, | |
742 | + this.CreateRetelimitHeadersDict(), | |
757 | 743 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/subscriptions") : GetApiCallback); |
758 | 744 | } |
759 | 745 |
@@ -776,7 +762,7 @@ namespace OpenTween | ||
776 | 762 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/statuses.json" : "/1/lists/statuses.json"), |
777 | 763 | param, |
778 | 764 | ref content, |
779 | - this.apiStatusHeaders, | |
765 | + this.CreateRetelimitHeadersDict(), | |
780 | 766 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/statuses") : GetApiCallback); |
781 | 767 | } |
782 | 768 |
@@ -810,7 +796,7 @@ namespace OpenTween | ||
810 | 796 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members.json" : "/1/lists/members.json"), |
811 | 797 | param, |
812 | 798 | ref content, |
813 | - this.apiStatusHeaders, | |
799 | + this.CreateRetelimitHeadersDict(), | |
814 | 800 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/members") : GetApiCallback); |
815 | 801 | } |
816 | 802 |
@@ -897,7 +883,7 @@ namespace OpenTween | ||
897 | 883 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/show.json" : "/1/lists/members/show.json"), |
898 | 884 | param, |
899 | 885 | ref content, |
900 | - this.apiStatusHeaders, | |
886 | + this.CreateRetelimitHeadersDict(), | |
901 | 887 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/members/show") : GetApiCallback); |
902 | 888 | } |
903 | 889 | #endregion |
@@ -917,7 +903,7 @@ namespace OpenTween | ||
917 | 903 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/retweeters/ids.json" : "/1/statuses/" + statusid + "/retweeted_by/ids.json"), |
918 | 904 | param, |
919 | 905 | ref content, |
920 | - this.apiStatusHeaders, | |
906 | + this.CreateRetelimitHeadersDict(), | |
921 | 907 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/retweeters/ids") : GetApiCallback); |
922 | 908 | } |
923 | 909 |
@@ -967,7 +953,7 @@ namespace OpenTween | ||
967 | 953 | CreateTwitterUri("/1/related_results/show.json"), |
968 | 954 | param, |
969 | 955 | ref content, |
970 | - this.apiStatusHeaders, | |
956 | + this.CreateRetelimitHeadersDict(), | |
971 | 957 | GetApiCallback); |
972 | 958 | } |
973 | 959 |
@@ -977,7 +963,7 @@ namespace OpenTween | ||
977 | 963 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/ids.json" : "/1/blocks/blocking/ids.json"), |
978 | 964 | null, |
979 | 965 | ref content, |
980 | - this.apiStatusHeaders, | |
966 | + this.CreateRetelimitHeadersDict(), | |
981 | 967 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/blocks/ids") : GetApiCallback); |
982 | 968 | } |
983 | 969 |
@@ -987,7 +973,7 @@ namespace OpenTween | ||
987 | 973 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/help/configuration.json" : "/1/help/configuration.json"), |
988 | 974 | null, |
989 | 975 | ref content, |
990 | - this.apiStatusHeaders, | |
976 | + this.CreateRetelimitHeadersDict(), | |
991 | 977 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/help/configuration") : GetApiCallback); |
992 | 978 | } |
993 | 979 |
@@ -997,7 +983,7 @@ namespace OpenTween | ||
997 | 983 | CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/verify_credentials.json" : "/1/account/verify_credentials.json"), |
998 | 984 | null, |
999 | 985 | ref content, |
1000 | - this.apiStatusHeaders, | |
986 | + this.CreateRetelimitHeadersDict(), | |
1001 | 987 | HttpTwitter.API11Enabled ? CreateApi11Calllback("/account/verify_credentials") : GetApiCallback); |
1002 | 988 | } |
1003 | 989 |
@@ -1045,18 +1031,35 @@ namespace OpenTween | ||
1045 | 1031 | } |
1046 | 1032 | #endregion |
1047 | 1033 | |
1048 | - private void GetApiCallback(Object sender, HttpStatusCode code, string content) | |
1034 | + private Dictionary<string, string> CreateRetelimitHeadersDict() | |
1035 | + { | |
1036 | + return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) | |
1037 | + { | |
1038 | + {"X-Access-Level", ""}, | |
1039 | + {"X-RateLimit-Limit", ""}, | |
1040 | + {"X-RateLimit-Remaining", ""}, | |
1041 | + {"X-RateLimit-Reset", ""}, | |
1042 | + {"X-Rate-Limit-Limit", ""}, | |
1043 | + {"X-Rate-Limit-Remaining", ""}, | |
1044 | + {"X-Rate-Limit-Reset", ""}, | |
1045 | + {"X-MediaRateLimit-Limit", ""}, | |
1046 | + {"X-MediaRateLimit-Remaining", ""}, | |
1047 | + {"X-MediaRateLimit-Reset", ""}, | |
1048 | + }; | |
1049 | + } | |
1050 | + | |
1051 | + private void GetApiCallback(Object sender, HttpStatusCode code, IDictionary<string, string> headerInfo, string content) | |
1049 | 1052 | { |
1050 | 1053 | if (code < HttpStatusCode.InternalServerError) |
1051 | - MyCommon.TwitterApiInfo.UpdateFromHeader(this.apiStatusHeaders); | |
1054 | + MyCommon.TwitterApiInfo.UpdateFromHeader(headerInfo); | |
1052 | 1055 | } |
1053 | 1056 | |
1054 | 1057 | private CallbackDelegate CreateApi11Calllback(string endpointName) |
1055 | 1058 | { |
1056 | - return (sender, code, content) => | |
1059 | + return (sender, code, headerInfo, content) => | |
1057 | 1060 | { |
1058 | 1061 | if (code < HttpStatusCode.InternalServerError) |
1059 | - MyCommon.TwitterApiInfo11.UpdateFromHeader(this.apiStatusHeaders, endpointName); | |
1062 | + MyCommon.TwitterApiInfo11.UpdateFromHeader(headerInfo, endpointName); | |
1060 | 1063 | }; |
1061 | 1064 | } |
1062 | 1065 |
@@ -67,7 +67,8 @@ namespace OpenTween | ||
67 | 67 | /// </summary> |
68 | 68 | /// <param name="sender">メソッド名</param> |
69 | 69 | /// <param name="code">APIメソッドの返したHTTPステータスコード</param> |
70 | + /// <param name="headerInfo">HTTPヘッダー情報</param> | |
70 | 71 | /// <param name="content">APIメソッドの処理結果</param> |
71 | 72 | /// <remarks>contentはNothingになることがあるのでチェックを必ず行うこと</remarks> |
72 | - public delegate void CallbackDelegate(object sender, HttpStatusCode code, string content); | |
73 | + public delegate void CallbackDelegate(object sender, HttpStatusCode code, IDictionary<string, string> headerInfo, string content); | |
73 | 74 | } |
@@ -7,6 +7,7 @@ | ||
7 | 7 | * FIX: Windows 8.1 Preview にて UserStreams が動作しない問題の対策 (thx @ch3cooh!) |
8 | 8 | * FIX: 検索タブ更新時に壊れたツイートを受信した場合の対策を追加 (thx @nyamph_pf!) |
9 | 9 | * FIX: 検索機能の API v1.1 対応が不完全であった箇所の修正 (thx @nyamph_pf!) |
10 | + * FIX: APIレートリミット表示がタイミングによって不整合を起こす問題の修正 | |
10 | 11 | |
11 | 12 | ==== Ver 1.1.1(2013/06/11) |
12 | 13 | * 当バージョンから Twitter API v1.1 に対応しています |