OSDN Git Service

Stream関連のAPI仕様書に合わせた修正(UserAgent,420エラー)
authorkiri_feather <kiri_feather@users.sourceforge.jp>
Thu, 16 Dec 2010 10:15:55 +0000 (10:15 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:17:13 +0000 (23:17 +0900)
Streamイベントでuser_updateを実装
カラム自動調整をコメントアウト(要検討)

git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@1213 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/Connection/HttpConnectionBasic.vb
Tween/Connection/HttpConnectionOAuth.vb
Tween/Connection/HttpTwitter.vb
Tween/Connection/IHttpConnection.vb
Tween/Tween.vb
Tween/Twitter.vb

index dd0a0c8..0d973b6 100644 (file)
@@ -116,11 +116,14 @@ Public Class HttpConnectionBasic
     Public Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
-            ByRef content As Stream) As HttpStatusCode Implements IHttpConnection.GetContent
+            ByRef content As Stream,
+            ByVal userAgent As String) As HttpStatusCode Implements IHttpConnection.GetContent
         '認証済かチェック
         If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized
 
         streamReq = CreateRequest(method, requestUri, param, False)
+        'User-Agent指定がある場合は付加
+        If Not String.IsNullOrEmpty(userAgent) Then streamReq.UserAgent = userAgent
 
         'BASIC認証用ヘッダを付加
         AppendApiInfo(streamReq)
index eaa082f..c8c0678 100644 (file)
@@ -145,11 +145,15 @@ Public Class HttpConnectionOAuth
     Public Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
-            ByRef content As Stream) As HttpStatusCode Implements IHttpConnection.GetContent
+            ByRef content As Stream,
+            ByVal userAgent As String) As HttpStatusCode Implements IHttpConnection.GetContent
         '認証済かチェック
         If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized
 
         streamReq = CreateRequest(method, requestUri, param, False)
+        'User-Agent指定がある場合は付加
+        If Not String.IsNullOrEmpty(userAgent) Then streamReq.UserAgent = userAgent
+
         'OAuth認証ヘッダを付加
         AppendOAuthInfo(streamReq, param, token, tokenSecret)
 
index d8f16d8..aa9a37c 100644 (file)
@@ -722,7 +722,10 @@ Public Class HttpTwitter
         End If
     End Sub
 
-    Public Function UserStream(ByRef content As Stream, ByVal allAtReplies As Boolean, ByVal trackwords As String) As HttpStatusCode
+    Public Function UserStream(ByRef content As Stream,
+                               ByVal allAtReplies As Boolean,
+                               ByVal trackwords As String,
+                               ByVal userAgent As String) As HttpStatusCode
         Dim param As New Dictionary(Of String, String)
 
         If allAtReplies Then
@@ -736,7 +739,8 @@ Public Class HttpTwitter
         Return httpCon.GetContent(GetMethod, _
                             CreateTwitterStreamUri("/2/user.json"), _
                             param, _
-                            content)
+                            content,
+                            userAgent)
     End Function
 
     Public Sub RequestAbort()
index 19bc971..c11625f 100644 (file)
@@ -6,7 +6,8 @@ Public Interface IHttpConnection
     Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
-            ByRef content As Stream) As HttpStatusCode
+            ByRef content As Stream,
+            ByVal userAgent As String) As HttpStatusCode
 
     Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
index cd2b9ed..4be5dc9 100644 (file)
@@ -2559,13 +2559,13 @@ Public Class TweenMain
             Me.Visible AndAlso _
             Me.WindowState = FormWindowState.Normal Then
 
-            Dim colNo As Integer = 2
-            If _iconCol Then colNo = 1
-            Dim widthDiff As Integer = Me.ClientSize.Width - Me._mySize.Width
-            Dim listView As DetailsListView = CType(Me._curTab.Tag, DetailsListView)
-            Dim column As ColumnHeader = listView.Columns(colNo)
-            column.Width += widthDiff
-            Me.MyList_ColumnWidthChanged(listView, New ColumnWidthChangedEventArgs(colNo))
+            'Dim colNo As Integer = 2
+            'If _iconCol Then colNo = 1
+            'Dim widthDiff As Integer = Me.ClientSize.Width - Me._mySize.Width
+            'Dim listView As DetailsListView = CType(Me._curTab.Tag, DetailsListView)
+            'Dim column As ColumnHeader = listView.Columns(colNo)
+            'column.Width += widthDiff
+            'Me.MyList_ColumnWidthChanged(listView, New ColumnWidthChangedEventArgs(colNo))
 
             _mySize = Me.ClientSize
             _mySpDis = Me.SplitContainer1.SplitterDistance
index 97cda1c..fefe1a2 100644 (file)
@@ -2930,6 +2930,8 @@ Public Class Twitter
                 evt.Target = eventData.TargetObject.Name
             Case "block"
                 evt.Target = ""
+            Case "user_update"
+                evt.Target = ""
             Case Else
                 TraceOut("Unknown Event:" + evt.Event + Environment.NewLine + content)
         End Select
@@ -3047,7 +3049,7 @@ Public Class Twitter
 
                     RaiseEvent Started()
 
-                    twCon.UserStream(st, _allAtreplies, _trackwords)
+                    twCon.UserStream(st, _allAtreplies, _trackwords, My.Application.Info.ProductName + " v" + fileVersion)
                     sr = New StreamReader(st)
 
                     Do While _streamActive AndAlso Not sr.EndOfStream
@@ -3069,6 +3071,9 @@ Public Class Twitter
                         RaiseEvent Stopped()
                         TraceOut("Stop:Timeout")
                         Thread.Sleep(10 * 1000)
+                    ElseIf CType(ex.Response, HttpWebResponse).StatusCode = 420 Then
+                        TraceOut("Stop:Connection Limit")
+                        Exit Do
                     Else
                         RaiseEvent Stopped()
                         TraceOut("Stop:WebException " & ex.Status.ToString)