--- /dev/null
+Imports System.ComponentModel
+
+Public Class ApiInformationChangedEventArgs
+ Inherits EventArgs
+ Public ApiInfo As New ApiInfo
+End Class
+
+Public MustInherit Class ApiInfoBase
+ Protected Shared _MaxCount As Integer = -1
+ Protected Shared _RemainCount As Integer = -1
+ Protected Shared _ResetTime As New DateTime
+ Protected Shared _ResetTimeInSeconds As Integer = -1
+ Protected Shared _UsingCount As Integer = -1
+End Class
+
+Public Class ApiInfo
+ Inherits ApiInfoBase
+ Public MaxCount As Integer
+ Public RemainCount As Integer
+ Public ResetTime As DateTime
+ Public ResetTimeInSeconds As Integer
+ Public UsingCount As Integer
+
+ Public Sub New()
+ Me.MaxCount = _MaxCount
+ Me.RemainCount = _RemainCount
+ Me.ResetTime = _ResetTime
+ Me.ResetTimeInSeconds = _ResetTimeInSeconds
+ Me.UsingCount = _ResetTimeInSeconds
+ End Sub
+End Class
+
+Public Class ApiInformation
+ Inherits ApiInfoBase
+
+ 'Private ReadOnly _lockobj As New Object 更新時にロックが必要かどうかは様子見
+
+ Public HttpHeaders As New Dictionary(Of String, String)(StringComparer.CurrentCultureIgnoreCase)
+
+ Public Sub Initialize()
+ If HttpHeaders.ContainsKey("X-RateLimit-Remaining") Then
+ HttpHeaders.Item("X-RateLimit-Remaining") = "-1"
+ Else
+ HttpHeaders.Add("X-RateLimit-Remaining", "-1")
+ End If
+
+ If HttpHeaders.ContainsKey("X-RateLimit-Limit") Then
+ HttpHeaders.Item("X-RateLimit-Limit") = "-1"
+ Else
+ HttpHeaders.Add("X-RateLimit-Limit", "-1")
+ End If
+
+ If HttpHeaders.ContainsKey("X-RateLimit-Reset") Then
+ HttpHeaders.Item("X-RateLimit-Reset") = "-1"
+ Else
+ HttpHeaders.Add("X-RateLimit-Reset", "-1")
+ End If
+ _MaxCount = -1
+ _RemainCount = -1
+ _ResetTime = New DateTime
+ _ResetTimeInSeconds = -1
+ 'UsingCountは初期化対象外
+ RaiseEvent Changed(Me, New ApiInformationChangedEventArgs)
+ End Sub
+
+ Public Function ConvertResetTimeInSecondsToResetTime(ByVal seconds As Integer) As DateTime
+ If seconds >= 0 Then
+ Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(seconds))
+ Else
+ Return New DateTime
+ End If
+ End Function
+
+ Public Event Changed(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs)
+
+ Private Sub Raise_Changed()
+ Dim arg As New ApiInformationChangedEventArgs
+ RaiseEvent Changed(Me, arg)
+ _MaxCount = arg.ApiInfo.MaxCount
+ _RemainCount = arg.ApiInfo.RemainCount
+ _ResetTime = arg.ApiInfo.ResetTime
+ _ResetTimeInSeconds = arg.ApiInfo.ResetTimeInSeconds
+ _UsingCount = arg.ApiInfo.UsingCount
+ End Sub
+
+ Public Property MaxCount As Integer
+ Get
+ Return _MaxCount
+ End Get
+ Set(ByVal value As Integer)
+ If _MaxCount <> value Then
+ _MaxCount = value
+ Raise_Changed()
+ End If
+ End Set
+ End Property
+
+ Public Property RemainCount As Integer
+ Get
+ Return _RemainCount
+ End Get
+ Set(ByVal value As Integer)
+ If _RemainCount <> value Then
+ _RemainCount = value
+ Raise_Changed()
+ End If
+ End Set
+ End Property
+
+ Public Property ResetTime As DateTime
+ Get
+ Return _ResetTime
+ End Get
+ Set(ByVal value As DateTime)
+ If _ResetTime <> value Then
+ _ResetTime = value
+ Raise_Changed()
+ End If
+ End Set
+ End Property
+
+ Public Property ResetTimeInSeconds As Integer
+ Get
+ Return _ResetTimeInSeconds
+ End Get
+ Set(ByVal value As Integer)
+ If _ResetTimeInSeconds <> value Then
+ _ResetTimeInSeconds = value
+ Raise_Changed()
+ End If
+ End Set
+ End Property
+
+ Public Property UsingCount As Integer
+ Get
+ Return _UsingCount
+ End Get
+ Set(ByVal value As Integer)
+ If _UsingCount <> value Then
+ _UsingCount = value
+ Raise_Changed()
+ End If
+ End Set
+ End Property
+
+
+ Private ReadOnly Property RemainCountFromHttpHeader() As Integer
+ Get
+ Dim result As Integer = 0
+ If HttpHeaders("X-RateLimit-Remaining") = "" Then Return -1
+ If Integer.TryParse(HttpHeaders("X-RateLimit-Remaining"), result) Then
+ Return result
+ End If
+ Return -1
+ End Get
+ End Property
+
+ Private ReadOnly Property MaxCountFromHttpHeader() As Integer
+ Get
+ Dim result As Integer = 0
+ If HttpHeaders("X-RateLimit-Limit") = "" Then Return -1
+ If Integer.TryParse(HttpHeaders("X-RateLimit-Limit"), result) Then
+ Return result
+ End If
+ Return -1
+ End Get
+ End Property
+
+ Private ReadOnly Property ResetTimeFromHttpHeader() As DateTime
+ Get
+ Dim i As Integer
+ If Integer.TryParse(HttpHeaders("X-RateLimit-Reset"), i) Then
+ If i >= 0 Then
+ Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(i))
+ Else
+ Return New DateTime
+ End If
+ Else
+ Return New DateTime
+ End If
+ End Get
+ End Property
+
+ Public Sub ParseHttpHeaders(ByVal headers As Dictionary(Of String, String))
+ _MaxCount = MaxCountFromHttpHeader
+ _RemainCount = RemainCountFromHttpHeader
+ _ResetTime = ResetTimeFromHttpHeader
+ Raise_Changed()
+ End Sub
+End Class
+
+
'''<param name="param">GET時のクエリ、またはPOST時のエンティティボディ</param>
'''<param name="content">[OUT]HTTP応答のボディデータ</param>
'''<param name="headerInfo">[IN/OUT]HTTP応答のヘッダ情報。必要なヘッダ名を事前に設定しておくこと</param>
+ '''<param name="callback">処理終了直前に呼ばれるコールバック関数のデリゲート 不要な場合はNothingを渡すこと</param>
'''<returns>HTTP応答のステータスコード</returns>
Public Function GetContent(ByVal method As String, _
ByVal requestUri As Uri, _
ByVal param As Dictionary(Of String, String), _
ByRef content As String, _
- ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+ ByVal headerInfo As Dictionary(Of String, String), _
+ ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
'認証済かチェック
If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized
'BASIC認証用ヘッダを付加
AppendApiInfo(webReq)
+ Dim code As HttpStatusCode
If content Is Nothing Then
- Return GetResponse(webReq, headerInfo, False)
+ code = GetResponse(webReq, headerInfo, False)
Else
- Return GetResponse(webReq, content, headerInfo, False)
+ code = GetResponse(webReq, content, headerInfo, False)
End If
+ If callback IsNot Nothing Then
+ callback(Me)
+ End If
+ Return code
End Function
Public Function GetContent(ByVal method As String, _
ByVal param As Dictionary(Of String, String), _
ByVal binary As List(Of KeyValuePair(Of String, FileInfo)), _
ByRef content As String, _
- ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+ ByVal headerInfo As Dictionary(Of String, String), _
+ ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
'認証済かチェック
If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized
'BASIC認証用ヘッダを付加
AppendApiInfo(webReq)
+ Dim code As HttpStatusCode
If content Is Nothing Then
- Return GetResponse(webReq, headerInfo, False)
+ code = GetResponse(webReq, headerInfo, False)
Else
- Return GetResponse(webReq, content, headerInfo, False)
+ code = GetResponse(webReq, content, headerInfo, False)
+ End If
+ If callback IsNot Nothing Then
+ callback(Me)
End If
+ Return code
End Function
+
'''<summary>
'''BASIC認証とREST APIで必要なヘッダを付加
'''</summary>
Dim orgCre As String = Me.credential
Me.credential = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
Try
- Dim httpCode As HttpStatusCode = Me.GetContent("GET", url, Nothing, Nothing, Nothing)
+ Dim httpCode As HttpStatusCode = Me.GetContent("GET", url, Nothing, Nothing, Nothing, Nothing)
If httpCode = HttpStatusCode.OK Then
Me._userName = username
Me._password = password
'''<param name="param">GET時のクエリ、またはPOST時のエンティティボディ</param>
'''<param name="content">[OUT]HTTP応答のボディデータ</param>
'''<param name="headerInfo">[IN/OUT]HTTP応答のヘッダ情報。必要なヘッダ名を事前に設定しておくこと</param>
+ '''<param name="callback">処理終了直前に呼ばれるコールバック関数のデリゲート 不要な場合はNothingを渡すこと</param>
'''<returns>HTTP応答のステータスコード</returns>
Public Function GetContent(ByVal method As String, _
ByVal requestUri As Uri, _
ByVal param As Dictionary(Of String, String), _
ByRef content As String, _
- ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+ ByVal headerInfo As Dictionary(Of String, String), _
+ ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
'認証済かチェック
If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized
'OAuth認証ヘッダを付加
AppendOAuthInfo(webReq, param, token, tokenSecret)
+ Dim code As HttpStatusCode
If content Is Nothing Then
- Return GetResponse(webReq, headerInfo, False)
+ code = GetResponse(webReq, headerInfo, False)
Else
- Return GetResponse(webReq, content, headerInfo, False)
+ code = GetResponse(webReq, content, headerInfo, False)
End If
+ If callback IsNot Nothing Then
+ callback(Me)
+ End If
+ Return code
End Function
'''<summary>
ByVal param As Dictionary(Of String, String), _
ByVal binary As List(Of KeyValuePair(Of String, FileInfo)), _
ByRef content As String, _
- ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+ ByVal headerInfo As Dictionary(Of String, String), _
+ ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
'認証済かチェック
If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized
'OAuth認証ヘッダを付加
AppendOAuthInfo(webReq, Nothing, token, tokenSecret)
+ Dim code As HttpStatusCode
If content Is Nothing Then
- Return GetResponse(webReq, headerInfo, False)
+ code = GetResponse(webReq, headerInfo, False)
Else
- Return GetResponse(webReq, content, headerInfo, False)
+ code = GetResponse(webReq, content, headerInfo, False)
+ End If
+ If callback IsNot Nothing Then
+ callback(Me)
End If
+ Return code
End Function
#Region "認証処理"
Private Const AccessTokenUrlXAuth As String = "https://api.twitter.com/oauth/access_token"
Private Shared _protocol As String = "http://"
- Private _remainCountApi As New Dictionary(Of String, String)(StringComparer.CurrentCultureIgnoreCase)
Private Const PostMethod As String = "POST"
Private Const GetMethod As String = "GET"
Private connectionType As AuthMethod = AuthMethod.Basic
Public Sub New()
- InitializeCount()
- End Sub
-
- Private Sub InitializeCount()
- If _remainCountApi.ContainsKey("X-RateLimit-Remaining") Then
- _remainCountApi.Item("X-RateLimit-Remaining") = "-1"
- Else
- _remainCountApi.Add("X-RateLimit-Remaining", "-1")
- End If
-
- If _remainCountApi.ContainsKey("X-RateLimit-Limit") Then
- _remainCountApi.Item("X-RateLimit-Limit") = "-1"
- Else
- _remainCountApi.Add("X-RateLimit-Limit", "-1")
- End If
-
- If _remainCountApi.ContainsKey("X-RateLimit-Reset") Then
- _remainCountApi.Item("X-RateLimit-Reset") = "-1"
- Else
- _remainCountApi.Add("X-RateLimit-Reset", "-1")
- End If
+ TwitterApiInfo.Initialize()
End Sub
Public Sub Initialize(ByVal accessToken As String, _
tk = accessToken
tks = accessTokenSecret
un = username
- InitializeCount()
+ TwitterApiInfo.Initialize()
End If
con.Initialize(ConsumerKey, ConsumerSecret, accessToken, accessTokenSecret, username, "screen_name")
httpCon = con
' 以前の認証状態よりひとつでも変化があったらhttpヘッダより読み取ったカウントは初期化
un = username
pw = password
- InitializeCount()
+ TwitterApiInfo.Initialize()
End If
con.Initialize(username, password)
httpCon = con
End Set
End Property
- Public ReadOnly Property RemainCountApi() As Integer
- Get
- Dim result As Integer = 0
- If _remainCountApi("X-RateLimit-Remaining") = "" Then Return -1
- If Integer.TryParse(_remainCountApi("X-RateLimit-Remaining"), result) Then
- Return result
- End If
- Return -1
- End Get
- End Property
-
- Public ReadOnly Property UpperCountApi() As Integer
- Get
- Dim result As Integer = 0
- If _remainCountApi("X-RateLimit-Limit") = "" Then Return -1
- If Integer.TryParse(_remainCountApi("X-RateLimit-Limit"), result) Then
- Return result
- End If
- Return -1
- End Get
- End Property
-
- Public ReadOnly Property ResetTimeApi() As DateTime
- Get
- Dim i As Integer
- If Integer.TryParse(_remainCountApi("X-RateLimit-Reset"), i) Then
- If i >= 0 Then
- Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(i))
- Else
- Return New DateTime
- End If
- Else
- Return New DateTime
- End If
- End Get
- End Property
-
Public Function UpdateStatus(ByVal status As String, ByVal replyToId As Long, ByRef content As String) As HttpStatusCode
Dim param As New Dictionary(Of String, String)
param.Add("status", status)
CreateTwitterUri("/1/statuses/update.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/statuses/destroy/" + id.ToString + ".xml"), _
Nothing, _
Nothing, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/direct_messages/new.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/direct_messages/destroy/" + id.ToString + ".xml"), _
Nothing, _
Nothing, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/statuses/retweet/" + id.ToString() + ".xml"), _
Nothing, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/users/show.xml"), _
param, _
content, _
- Nothing)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function CreateFriendships(ByVal screenName As String, ByRef content As String) As HttpStatusCode
Dim param As New Dictionary(Of String, String)
CreateTwitterUri("/1/friendships/create.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/friendships/destroy.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/blocks/create.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/blocks/destroy.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/report_spam.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/friendships/show.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function ShowStatuses(ByVal id As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/statuses/show/" + id.ToString() + ".xml"), _
Nothing, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function CreateFavorites(ByVal id As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/favorites/create/" + id.ToString() + ".xml"), _
Nothing, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/favorites/destroy/" + id.ToString() + ".xml"), _
Nothing, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/statuses/home_timeline.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function Mentions(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/statuses/mentions.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function DirectMessages(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/direct_messages.xml"), _
Nothing, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function DirectMessagesSent(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/direct_messages/sent.xml"), _
Nothing, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function Favorites(ByVal count As Integer, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/favorites.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function Search(ByVal words As String, ByVal lang As String, ByVal rpp As Integer, ByVal page As Integer, ByVal sinceId As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/followers/ids.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function RateLimitStatus(ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/account/rate_limit_status.xml"), _
Nothing, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/" + user + "/lists.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function PostListID(ByVal user As String, ByVal list_id As String, ByVal name As String, ByVal mode As String, ByVal description As String, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/" + user + "/lists/" + list_id + ".xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/" + user + "/lists/" + list_id + ".xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/" + user + "/lists/subscriptions.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function GetListsStatuses(ByVal user As String, ByVal list_id As String, ByVal per_page As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/" + user + "/lists/" + list_id + "/statuses.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function PostLists(ByVal user As String, ByVal listname As String, ByVal isPrivate As Boolean, ByVal description As String, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/" + user + "/lists.xml"), _
param, _
content, _
+ Nothing,
Nothing)
End Function
CreateTwitterUri("/1/" + user + "/" + list_id + "/members.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function PostListMembers(ByVal user As String, ByVal list_id As String, ByVal id As String, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/" + user + "/" + list_id + "/members.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/" + user + "/" + list_id + "/members.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
CreateTwitterUri("/1/" + user + "/" + list_id + "/members/" + id + ".xml"), _
Nothing, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function Statusid_retweeted_by_ids(ByVal statusid As Long, ByVal count As Integer, ByVal page As Integer, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/statuses/" + statusid.ToString + "/retweeted_by/ids.xml"), _
param, _
content, _
- _remainCountApi)
+ TwitterApiInfo.HttpHeaders, _
+ AddressOf GetApiCallback)
End Function
Public Function UpdateProfile(ByVal name As String, ByVal url As String, ByVal location As String, ByVal description As String, ByRef content As String) As HttpStatusCode
CreateTwitterUri("/1/account/update_profile.xml"), _
param, _
content, _
+ Nothing, _
Nothing)
End Function
Nothing, _
binary, _
content, _
+ Nothing, _
Nothing)
End Function
End Property
#End Region
+ Private Sub GetApiCallback(ByVal sender As Object)
+ TwitterApiInfo.ParseHttpHeaders(TwitterApiInfo.HttpHeaders)
+ End Sub
End Class
ByVal requestUri As Uri, _
ByVal param As Dictionary(Of String, String), _
ByRef content As String, _
- ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode
+ ByVal headerInfo As Dictionary(Of String, String), _
+ ByVal callback As CallbackDelegate) As HttpStatusCode
Function GetContent(ByVal method As String, _
ByVal requestUri As Uri, _
ByVal param As Dictionary(Of String, String), _
ByVal binary As List(Of KeyValuePair(Of String, FileInfo)), _
ByRef content As String, _
- ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode
+ ByVal headerInfo As Dictionary(Of String, String), _
+ ByVal callback As CallbackDelegate) As HttpStatusCode
Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String) As HttpStatusCode
ReadOnly Property AuthUsername() As String
+ Delegate Sub CallbackDelegate(ByVal sender As Object)
End Interface
param, _
binary, _
content, _
+ Nothing, _
Nothing)
End Function
param, _
binary, _
content, _
+ Nothing, _
Nothing)
End Function
Public fileVersion As String
+ Public WithEvents TwitterApiInfo As New ApiInformation
End Module
CalcApiUsing()
End Sub
- Private Sub DisplayApiMaxCount(ByVal apiCount As Twitter.ApiInfo)
- If apiCount.MaxCount > -1 Then
- LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, apiCount.UsingCount, apiCount.MaxCount)
+ Private Sub DisplayApiMaxCount(ByVal info As ApiInfo)
+ If TwitterApiInfo.MaxCount > -1 Then
+ LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, TwitterApiInfo.UsingCount, TwitterApiInfo.MaxCount)
Else
- LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, apiCount.UsingCount, "???")
+ LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, TwitterApiInfo.UsingCount, "???")
End If
End Sub
End If
If tw IsNot Nothing Then
- If tw.UpperCountApi = -1 Then
+ If TwitterApiInfo.MaxCount = -1 Then
If Twitter.AccountState = ACCOUNT_STATE.Valid Then
- Dim info As New Twitter.ApiInfo
+ Dim info As New ApiInfo
info.UsingCount = UsingApi
- Dim proc As New Action(Of Twitter.ApiInfo)(Sub(infoCount)
- tw.GetInfoApi(infoCount) '取得エラー時はinfoCountは初期状態(値:-1)
- Me.Invoke(New Action(Of Twitter.ApiInfo)(AddressOf DisplayApiMaxCount), infoCount)
- End Sub)
+ Dim proc As New Action(Of ApiInfo)(Sub(infoCount)
+ tw.GetInfoApi(infoCount) '取得エラー時はinfoCountは初期状態(値:-1)
+ Me.Invoke(New Action(Of ApiInfo)(AddressOf DisplayApiMaxCount), infoCount)
+ End Sub)
proc.BeginInvoke(info, Nothing, Nothing)
Else
LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, UsingApi, "???")
End If
Else
- LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, UsingApi, tw.UpperCountApi)
+ LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, UsingApi, TwitterApiInfo.MaxCount)
End If
End If
Me.Visible = False
SecurityManager = New InternetSecurityManager(PostBrowser)
+ AddHandler TwitterApiInfo.Changed, AddressOf SetStatusLabelApiHandler
VerUpMenuItem.Image = shield.Icon
If Not My.Application.CommandLineArgs.Count = 0 AndAlso My.Application.CommandLineArgs.Contains("/d") Then TraceFlag = True
"Retweet",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question)
- Select rtResult
+ Select Case rtResult
Case Windows.Forms.DialogResult.Yes
doReTweetOriginal(False)
StatusText.Text = ""
result = SettingDialog.ShowDialog()
Catch ex As Exception
Exit Sub
- Finally
- SetStatusLabel()
End Try
If result = Windows.Forms.DialogResult.OK Then
Else
slbl.Append((SettingDialog.TimelinePeriodInt - _homeCounterAdjuster).ToString() + My.Resources.SetStatusLabelText3)
End If
- SetStatusLabelApi()
Return slbl.ToString()
End Function
+ Delegate Sub SetStatusLabelApiDelegate()
+
+ Private Sub SetStatusLabelApiHandler(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs)
+ If InvokeRequired Then
+ Invoke(New SetStatusLabelApiDelegate(AddressOf SetStatusLabelApi))
+ Else
+ SetStatusLabelApi()
+ End If
+ End Sub
+
Private Sub SetStatusLabelApi()
Dim slbl As New StringBuilder(256)
- If tw.RemainCountApi > -1 AndAlso tw.UpperCountApi > -1 Then
+ If TwitterApiInfo.RemainCount > -1 AndAlso TwitterApiInfo.MaxCount > -1 Then
' 正常
- slbl.Append("API " + tw.RemainCountApi.ToString + "/" + tw.UpperCountApi.ToString)
- ElseIf tw.RemainCountApi > -1 Then
+ slbl.Append("API " + TwitterApiInfo.RemainCount.ToString + "/" + TwitterApiInfo.MaxCount.ToString)
+ ElseIf TwitterApiInfo.RemainCount > -1 Then
' uppercount不正
- slbl.Append("API " + tw.RemainCountApi.ToString + "/???")
- ElseIf tw.UpperCountApi > -1 Then
+ slbl.Append("API " + TwitterApiInfo.RemainCount.ToString + "/???")
+ ElseIf TwitterApiInfo.MaxCount > -1 Then
' remaincount不正
- slbl.Append("API ???/" + tw.UpperCountApi.ToString)
+ slbl.Append("API ???/" + TwitterApiInfo.MaxCount.ToString)
Else
'両方とも不正
slbl.Append("API ???/???")
End If
StatusLabelApi.Text = slbl.ToString()
- If tw.ResetTimeApi >= DateTime.Now Then
- StatusLabelApi.ToolTipText = "ResetTime " + tw.ResetTimeApi.ToString
+ If TwitterApiInfo.ResetTime >= DateTime.Now Then
+ StatusLabelApi.ToolTipText = "ResetTime " + TwitterApiInfo.ResetTime.ToString
Else
StatusLabelApi.ToolTipText = "ResetTime ???"
End If
Private Function UrlConvert(ByVal Converter_Type As UrlConverter) As Boolean
'Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
Dim result As String = ""
- Const url As String = "(?<before>(?:[^\""':!=]|^|\:))" + _
- "(?<url>(?<protocol>https?://)" + _
- "(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" + _
- "(?<path>/[a-z0-9!*'();:&=+$/%#\[\]\-_.,~@^]*[a-z0-9)=#/]?)?" + _
- "(?<query>\?[a-z0-9!*'();:&=+$/%#\[\]\-_.,~]*[a-z0-9_&=#/])?)"
+ Const url As String = "(?<before>(?:[^\""':!=]|^|\:))" + _
+ "(?<url>(?<protocol>https?://)" + _
+ "(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" + _
+ "(?<path>/[a-z0-9!*'();:&=+$/%#\[\]\-_.,~@^]*[a-z0-9)=#/]?)?" + _
+ "(?<query>\?[a-z0-9!*'();:&=+$/%#\[\]\-_.,~]*[a-z0-9_&=#/])?)"
Const nico As String = "^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$"
Private Class GetApiInfoArgs
Public tw As Twitter
- Public info As Twitter.ApiInfo
+ Public info As ApiInfo
End Class
Private Sub GetApiInfo_Dowork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
End Sub
Private Sub ApiInfoMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApiInfoMenuItem.Click
- Dim info As New Twitter.ApiInfo
+ Dim info As New ApiInfo
Dim tmp As String
Dim args As New GetApiInfoArgs With {.tw = tw, .info = info}
End Sub
Private Sub FollowCommand(ByVal id As String)
- Try
- Using inputName As New InputTabName()
- inputName.FormTitle = "Follow"
- inputName.FormDescription = My.Resources.FRMessage1
- inputName.TabName = id
- If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
- Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
- Dim arg As New FollowRemoveCommandArgs
- arg.tw = tw
- arg.id = inputName.TabName.Trim()
- Using _info As New FormInfo(My.Resources.FollowCommandText1, _
- AddressOf FollowCommand_DoWork, _
- Nothing, _
- arg)
- _info.ShowDialog()
- Dim ret As String = DirectCast(_info.Result, String)
- If Not String.IsNullOrEmpty(ret) Then
- MessageBox.Show(My.Resources.FRMessage2 + ret)
- Else
- MessageBox.Show(My.Resources.FRMessage3)
- End If
- End Using
- End If
- End Using
- Finally
- SetStatusLabel()
- End Try
+ Using inputName As New InputTabName()
+ inputName.FormTitle = "Follow"
+ inputName.FormDescription = My.Resources.FRMessage1
+ inputName.TabName = id
+ If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+ Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
+ Dim arg As New FollowRemoveCommandArgs
+ arg.tw = tw
+ arg.id = inputName.TabName.Trim()
+ Using _info As New FormInfo(My.Resources.FollowCommandText1, _
+ AddressOf FollowCommand_DoWork, _
+ Nothing, _
+ arg)
+ _info.ShowDialog()
+ Dim ret As String = DirectCast(_info.Result, String)
+ If Not String.IsNullOrEmpty(ret) Then
+ MessageBox.Show(My.Resources.FRMessage2 + ret)
+ Else
+ MessageBox.Show(My.Resources.FRMessage3)
+ End If
+ End Using
+ End If
+ End Using
End Sub
Private Sub RemoveCommandMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveCommandMenuItem.Click
End Sub
Private Sub RemoveCommand(ByVal id As String, ByVal skipInput As Boolean)
- Try
- Dim arg As New FollowRemoveCommandArgs
- arg.tw = tw
- arg.id = id
- If Not skipInput Then
- Using inputName As New InputTabName()
- inputName.FormTitle = "Unfollow"
- inputName.FormDescription = My.Resources.FRMessage1
- inputName.TabName = id
- If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
- Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
- arg.tw = tw
- arg.id = inputName.TabName.Trim()
- Else
- Exit Sub
- End If
- End Using
- End If
-
- Using _info As New FormInfo(My.Resources.RemoveCommandText1, _
- AddressOf RemoveCommand_DoWork, _
- Nothing, _
- arg)
- _info.ShowDialog()
- Dim ret As String = DirectCast(_info.Result, String)
- If Not String.IsNullOrEmpty(ret) Then
- MessageBox.Show(My.Resources.FRMessage2 + ret)
+ Dim arg As New FollowRemoveCommandArgs
+ arg.tw = tw
+ arg.id = id
+ If Not skipInput Then
+ Using inputName As New InputTabName()
+ inputName.FormTitle = "Unfollow"
+ inputName.FormDescription = My.Resources.FRMessage1
+ inputName.TabName = id
+ If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+ Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
+ arg.tw = tw
+ arg.id = inputName.TabName.Trim()
Else
- MessageBox.Show(My.Resources.FRMessage3)
+ Exit Sub
End If
End Using
- Finally
- SetStatusLabel()
- End Try
+ End If
+
+ Using _info As New FormInfo(My.Resources.RemoveCommandText1, _
+ AddressOf RemoveCommand_DoWork, _
+ Nothing, _
+ arg)
+ _info.ShowDialog()
+ Dim ret As String = DirectCast(_info.Result, String)
+ If Not String.IsNullOrEmpty(ret) Then
+ MessageBox.Show(My.Resources.FRMessage2 + ret)
+ Else
+ MessageBox.Show(My.Resources.FRMessage3)
+ End If
+ End Using
End Sub
Private Sub FriendshipMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FriendshipMenuItem.Click
End Sub
Private Sub ShowFriendship(ByVal id As String)
- Try
- Dim args As New ShowFriendshipArgs
- args.tw = tw
- Using inputName As New InputTabName()
- inputName.FormTitle = "Show Friendships"
- inputName.FormDescription = My.Resources.FRMessage1
- inputName.TabName = id
- If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
- Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
- Dim ret As String = ""
- args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim))
- Using _info As New FormInfo(My.Resources.ShowFriendshipText1, _
- AddressOf ShowFriendship_DoWork, _
- Nothing, _
- args)
- _info.ShowDialog()
- ret = DirectCast(_info.Result, String)
- End Using
- Dim result As String = ""
- If String.IsNullOrEmpty(ret) Then
- If args.ids(0).isFollowing Then
- result = My.Resources.GetFriendshipInfo1 + System.Environment.NewLine
- Else
- result = My.Resources.GetFriendshipInfo2 + System.Environment.NewLine
- End If
- If args.ids(0).isFollowed Then
- result += My.Resources.GetFriendshipInfo3
- Else
- result += My.Resources.GetFriendshipInfo4
- End If
- result = args.ids(0).id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result
- Else
- result = ret
- End If
- MessageBox.Show(result)
- End If
- End Using
- Finally
- SetStatusLabel()
- End Try
- End Sub
-
- Private Sub ShowFriendship(ByVal ids() As String)
- Try
- For Each id As String In ids
+ Dim args As New ShowFriendshipArgs
+ args.tw = tw
+ Using inputName As New InputTabName()
+ inputName.FormTitle = "Show Friendships"
+ inputName.FormDescription = My.Resources.FRMessage1
+ inputName.TabName = id
+ If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+ Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
Dim ret As String = ""
- Dim args As New ShowFriendshipArgs
- args.tw = tw
- args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(id.Trim))
+ args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim))
Using _info As New FormInfo(My.Resources.ShowFriendshipText1, _
AddressOf ShowFriendship_DoWork, _
Nothing, _
ret = DirectCast(_info.Result, String)
End Using
Dim result As String = ""
- Dim fInfo As ShowFriendshipArgs.FriendshipInfo = args.ids(0)
- Dim ff As String = ""
If String.IsNullOrEmpty(ret) Then
- ff = " "
- If fInfo.isFollowing Then
- ff += My.Resources.GetFriendshipInfo1
+ If args.ids(0).isFollowing Then
+ result = My.Resources.GetFriendshipInfo1 + System.Environment.NewLine
Else
- ff += My.Resources.GetFriendshipInfo2
+ result = My.Resources.GetFriendshipInfo2 + System.Environment.NewLine
End If
- ff += System.Environment.NewLine + " "
- If fInfo.isFollowed Then
- ff += My.Resources.GetFriendshipInfo3
+ If args.ids(0).isFollowed Then
+ result += My.Resources.GetFriendshipInfo3
Else
- ff += My.Resources.GetFriendshipInfo4
+ result += My.Resources.GetFriendshipInfo4
End If
- result += fInfo.id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff
- If fInfo.isFollowing Then
- If MessageBox.Show( _
- "フォロー解除しますか?" + System.Environment.NewLine + result, "フォロー解除確認", _
- MessageBoxButtons.YesNo, _
- MessageBoxIcon.Question, _
- MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
- RemoveCommand(fInfo.id, True)
- End If
- Else
- MessageBox.Show(result)
+ result = args.ids(0).id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result
+ Else
+ result = ret
+ End If
+ MessageBox.Show(result)
+ End If
+ End Using
+ End Sub
+
+ Private Sub ShowFriendship(ByVal ids() As String)
+ For Each id As String In ids
+ Dim ret As String = ""
+ Dim args As New ShowFriendshipArgs
+ args.tw = tw
+ args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(id.Trim))
+ Using _info As New FormInfo(My.Resources.ShowFriendshipText1, _
+ AddressOf ShowFriendship_DoWork, _
+ Nothing, _
+ args)
+ _info.ShowDialog()
+ ret = DirectCast(_info.Result, String)
+ End Using
+ Dim result As String = ""
+ Dim fInfo As ShowFriendshipArgs.FriendshipInfo = args.ids(0)
+ Dim ff As String = ""
+ If String.IsNullOrEmpty(ret) Then
+ ff = " "
+ If fInfo.isFollowing Then
+ ff += My.Resources.GetFriendshipInfo1
+ Else
+ ff += My.Resources.GetFriendshipInfo2
+ End If
+ ff += System.Environment.NewLine + " "
+ If fInfo.isFollowed Then
+ ff += My.Resources.GetFriendshipInfo3
+ Else
+ ff += My.Resources.GetFriendshipInfo4
+ End If
+ result += fInfo.id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff
+ If fInfo.isFollowing Then
+ If MessageBox.Show( _
+ "フォロー解除しますか?" + System.Environment.NewLine + result, "フォロー解除確認", _
+ MessageBoxButtons.YesNo, _
+ MessageBoxIcon.Question, _
+ MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
+ RemoveCommand(fInfo.id, True)
End If
Else
- MessageBox.Show(ret)
+ MessageBox.Show(result)
End If
- Next
- Finally
- SetStatusLabel()
- End Try
+ Else
+ MessageBox.Show(ret)
+ End If
+ Next
End Sub
Private Sub OwnStatusMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OwnStatusMenuItem.Click
Dim result As String = ""
Dim xmlbuf As String = ""
Dim args As New GetUserInfoArgs
- Try
- If ShowInputDialog Then
- Using inputName As New InputTabName()
- inputName.FormTitle = "Show UserStatus"
- inputName.FormDescription = My.Resources.FRMessage1
- inputName.TabName = id
- If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
- Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
- id = inputName.TabName.Trim
- args.tw = tw
- args.id = id
- args.xmlbuf = xmlbuf
- Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
- AddressOf GetUserInfo_DoWork, _
- Nothing, _
- args)
- _info.ShowDialog()
- Dim ret As String = DirectCast(_info.Result, String)
- If String.IsNullOrEmpty(ret) Then
- doShowUserStatus(args.xmlbuf)
- Else
- MessageBox.Show(ret)
- End If
- End Using
- End If
- End Using
- Else
- args.tw = tw
- args.id = id
- args.xmlbuf = xmlbuf
- Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
- AddressOf GetUserInfo_DoWork, _
- Nothing, _
- args)
- _info.ShowDialog()
- Dim ret As String = DirectCast(_info.Result, String)
- If String.IsNullOrEmpty(ret) Then
- doShowUserStatus(args.xmlbuf)
- Else
- MessageBox.Show(ret)
- End If
- End Using
- End If
- Finally
- SetStatusLabel()
- End Try
+ If ShowInputDialog Then
+ Using inputName As New InputTabName()
+ inputName.FormTitle = "Show UserStatus"
+ inputName.FormDescription = My.Resources.FRMessage1
+ inputName.TabName = id
+ If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+ Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
+ id = inputName.TabName.Trim
+ args.tw = tw
+ args.id = id
+ args.xmlbuf = xmlbuf
+ Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
+ AddressOf GetUserInfo_DoWork, _
+ Nothing, _
+ args)
+ _info.ShowDialog()
+ Dim ret As String = DirectCast(_info.Result, String)
+ If String.IsNullOrEmpty(ret) Then
+ doShowUserStatus(args.xmlbuf)
+ Else
+ MessageBox.Show(ret)
+ End If
+ End Using
+ End If
+ End Using
+ Else
+ args.tw = tw
+ args.id = id
+ args.xmlbuf = xmlbuf
+ Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
+ AddressOf GetUserInfo_DoWork, _
+ Nothing, _
+ args)
+ _info.ShowDialog()
+ Dim ret As String = DirectCast(_info.Result, String)
+ If String.IsNullOrEmpty(ret) Then
+ doShowUserStatus(args.xmlbuf)
+ Else
+ MessageBox.Show(ret)
+ End If
+ End Using
+ End If
End Sub
Private Overloads Sub doShowUserStatus(ByVal xmldata As String)
- Try
- Using userinfo As New ShowUserInfo()
- userinfo.XmlData = xmldata
- userinfo.ShowDialog(Me)
- End Using
- Finally
- SetStatusLabel()
- End Try
+ Using userinfo As New ShowUserInfo()
+ userinfo.XmlData = xmldata
+ userinfo.ShowDialog(Me)
+ End Using
End Sub
Private Overloads Sub ShowUserStatus(ByVal id As String, ByVal ShowInputDialog As Boolean)
Private Sub RtCountMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RtCountMenuItem.Click
If _curPost IsNot Nothing Then
- Try
- Using _info As New FormInfo(My.Resources.RtCountMenuItem_ClickText1, _
+ Using _info As New FormInfo(My.Resources.RtCountMenuItem_ClickText1, _
AddressOf GetRetweet_DoWork)
- Dim retweet_count As Integer = 0
+ Dim retweet_count As Integer = 0
- ' ダイアログ表示
- _info.ShowDialog()
- retweet_count = CType(_info.Result, Integer)
- If retweet_count < 0 Then
- MessageBox.Show(My.Resources.RtCountText2)
- Else
- MessageBox.Show(retweet_count.ToString + My.Resources.RtCountText1)
- End If
- End Using
- Finally
- SetStatusLabel()
- End Try
+ ' ダイアログ表示
+ _info.ShowDialog()
+ retweet_count = CType(_info.Result, Integer)
+ If retweet_count < 0 Then
+ MessageBox.Show(My.Resources.RtCountText2)
+ Else
+ MessageBox.Show(retweet_count.ToString + My.Resources.RtCountText1)
+ End If
+ End Using
End If
End Sub
<Import Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="ApiInformation.vb" />
<Compile Include="ApplicationEvents.vb" />
<Compile Include="AtIdSupplement.Designer.vb">
<DependentUpon>AtIdSupplement.vb</DependentUpon>
Dim res As HttpStatusCode
Dim content As String = ""
- _infoapi.Initialize()
+ TwitterApiInfo.Initialize()
Try
res = twCon.AuthUserAndPass(username, password)
Catch ex As Exception
If String.IsNullOrEmpty(token) OrElse String.IsNullOrEmpty(tokenSecret) OrElse String.IsNullOrEmpty(username) Then
Twitter.AccountState = ACCOUNT_STATE.Invalid
End If
- _infoapi.Initialize()
+ TwitterApiInfo.Initialize()
twCon.Initialize(token, tokenSecret, username)
_uid = username.ToLower
_UserIdNo = ""
If String.IsNullOrEmpty(username) OrElse String.IsNullOrEmpty(password) Then
Twitter.AccountState = ACCOUNT_STATE.Invalid
End If
- _infoapi.Initialize()
+ TwitterApiInfo.Initialize()
twCon.Initialize(username, password)
_uid = username.ToLower
_UserIdNo = ""
Return sb.ToString
End Function
- Public ReadOnly Property RemainCountApi() As Integer
- Get
- If twCon.RemainCountApi <> -1 Then
- _infoapi.Initialize()
- Return twCon.RemainCountApi
- Else
- If _infoapi.RemainCount <> -1 Then
- Return _infoapi.RemainCount
- Else
- Return -1
- End If
- End If
- End Get
- End Property
-
- Public ReadOnly Property UpperCountApi() As Integer
- Get
- If twCon.UpperCountApi <> -1 Then
- _infoapi.Initialize()
- Return twCon.UpperCountApi
- Else
- If _infoapi.MaxCount <> -1 Then
- Return _infoapi.MaxCount
- Else
- Return -1
- End If
- End If
- End Get
- End Property
-
- Public ReadOnly Property ResetTimeApi() As DateTime
- Get
- If twCon.ResetTimeApi.ToBinary <> 0 Then
- _infoapi.Initialize()
- Return twCon.ResetTimeApi
- Else
- If _infoapi.ResetTime.ToBinary <> 0 Then
- Return _infoapi.ResetTime
- Else
- Return New DateTime
- End If
- End If
- End Get
- End Property
-
- Public Class ApiInfo
- Public MaxCount As Integer = -1
- Public RemainCount As Integer = -1
- Public ResetTime As New DateTime
- Public ResetTimeInSeconds As Integer = -1
- Public UsingCount As Integer = -1
-
- Public Sub Initialize()
- Me.MaxCount = -1
- Me.RemainCount = -1
- Me.ResetTime = New DateTime
- Me.ResetTimeInSeconds = -1
- 'UsingCountは初期化対象外
- End Sub
-
- Public Function ConvertResetTimeInSecondsToResetTime(ByVal seconds As Integer) As DateTime
- If seconds >= 0 Then
- Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(seconds))
- Else
- Return New DateTime
- End If
- End Function
- End Class
-
- Private _infoapi As New ApiInfo
-
Public Function GetInfoApi(ByVal info As ApiInfo) As Boolean
If Twitter.AccountState <> ACCOUNT_STATE.Valid Then Return True
Try
res = twCon.RateLimitStatus(content)
Catch ex As Exception
- _infoapi.Initialize()
- info.Initialize()
+ TwitterApiInfo.Initialize()
Return False
End Try
Dim xdoc As New XmlDocument
Try
xdoc.LoadXml(content)
- info.MaxCount = Integer.Parse(xdoc.SelectSingleNode("/hash/hourly-limit").InnerText)
- info.RemainCount = Integer.Parse(xdoc.SelectSingleNode("/hash/remaining-hits").InnerText)
- info.ResetTime = DateTime.Parse(xdoc.SelectSingleNode("/hash/reset-time").InnerText)
- info.ResetTimeInSeconds = Integer.Parse(xdoc.SelectSingleNode("/hash/reset-time-in-seconds").InnerText)
-
- _infoapi.MaxCount = info.MaxCount
- _infoapi.RemainCount = info.RemainCount
- _infoapi.ResetTime = info.ResetTime
- _infoapi.ResetTimeInSeconds = info.ResetTimeInSeconds
+ Dim arg As New ApiInformationChangedEventArgs
+
+ arg.ApiInfo.MaxCount = Integer.Parse(xdoc.SelectSingleNode("/hash/hourly-limit").InnerText)
+ arg.ApiInfo.RemainCount = Integer.Parse(xdoc.SelectSingleNode("/hash/remaining-hits").InnerText)
+ arg.ApiInfo.ResetTime = DateTime.Parse(xdoc.SelectSingleNode("/hash/reset-time").InnerText)
+ arg.ApiInfo.ResetTimeInSeconds = Integer.Parse(xdoc.SelectSingleNode("/hash/reset-time-in-seconds").InnerText)
+
+ info.MaxCount = arg.ApiInfo.MaxCount
+ info.RemainCount = arg.ApiInfo.RemainCount
+ info.ResetTime = arg.ApiInfo.ResetTime
+ info.ResetTimeInSeconds = arg.ApiInfo.ResetTimeInSeconds
+
+ RaiseEvent ApiInformationChanged(Me, arg)
Return True
Catch ex As Exception
- _infoapi.Initialize()
- info.Initialize()
+ TwitterApiInfo.Initialize()
Return False
End Try
End Function
Public Property UserIdNo As String
+ Public Event ApiInformationChanged(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs)
+
+ Private Sub Twitter_ApiInformationChanged(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs) Handles Me.ApiInformationChanged
+ End Sub
End Class