Changeset 33664

Show
Ignore:
Timestamp:
05/29/09 18:12:10 (4 years ago)
Author:
kiri_feather
Message:
 
Location:
lang/vb2005/FuwaKumo/trunk/FuwaKumo
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • lang/vb2005/FuwaKumo/trunk/FuwaKumo/FuwaKumo.vbproj

    r33647 r33664  
    7474    <Compile Include="SettingNet.vb" /> 
    7575    <Compile Include="SettingTwitter.vb" /> 
     76    <Compile Include="StatusElement.vb" /> 
    7677    <Compile Include="WebAccessBase.vb" /> 
    7778    <Compile Include="WebOAuth.vb" /> 
     79    <Compile Include="WebTwitter.vb" /> 
    7880  </ItemGroup> 
    7981  <ItemGroup> 
  • lang/vb2005/FuwaKumo/trunk/FuwaKumo/WebAccessBase.vb

    r33647 r33664  
    128128                            Return CType(sr.ReadToEnd(), Object) 
    129129                        End Using 
     130                    Case Else 
     131                        Throw New System.ArgumentException("Type must String or Bitmap") 
    130132                End Select 
    131133            End Using 
  • lang/vb2005/FuwaKumo/trunk/FuwaKumo/WebOAuth.vb

    r33647 r33664  
    1313    End Sub 
    1414 
    15     Private Shared Function OpenAuthorizePage() As Boolean 
     15    Public Shared Function GetAuthorizePageUrl() As String 
    1616        _requestToken = "" 
    1717 
    1818        Dim query As System.Collections.Specialized.NameValueCollection = GetOAuthToken(_oauthSetting.RequestTokenUrl) 
    19         If query Is Nothing Then Return False 
     19        If query Is Nothing OrElse query.Count = 0 Then Return Nothing 
    2020 
    2121        _requestToken = query.Item("oauth_token") 
    2222 
    23         Try 
    24             System.Diagnostics.Process.Start(String.Format("{0}?oauth_token={1}", _oauthSetting.AuthorizeUrl, _requestToken)) 
    25         Catch ex As Exception 
    26         End Try 
    27  
    28         Return True 
     23        Return String.Format("{0}?oauth_token={1}", _oauthSetting.AuthorizeUrl, _requestToken) 
    2924    End Function 
    3025 
    31     Private Shared Function GetAccessToken() As Boolean 
     26    Public Shared Function GetAccessToken() As Boolean 
    3227        If String.IsNullOrEmpty(_requestToken) Then Return False 
    3328 
    3429        Dim query As System.Collections.Specialized.NameValueCollection = GetOAuthToken(_oauthSetting.AccessTokenUrl) 
    3530 
    36         If query Is Nothing Then Return False 
     31        If query Is Nothing OrElse query.Count = 0 Then Return False 
    3732 
    3833        _oauthSetting.Token = query.Item("oauth_token") 
     
    4843        Dim statusCode As HttpStatusCode 
    4944        Try 
    50             Dim response As String = GetText(request, statusCode) 
     45            Dim response As String = WebAccessBase.GetText(request, statusCode) 
    5146            If statusCode <> HttpStatusCode.OK OrElse String.IsNullOrEmpty(response) Then Return Nothing 
    5247            Return ParseQueryString(response) 
     
    10297        Return _random.Next(123400, 9999999).ToString 
    10398    End Function 
     99 
     100    Protected Shared Function GetPage(ByVal url As String, _ 
     101                                        ByRef query As System.Collections.Generic.SortedList(Of String, String), _ 
     102                                        ByVal encode As System.Text.Encoding, _ 
     103                                        ByVal headerInfo As System.Collections.Specialized.NameValueCollection _ 
     104                                    ) As String 
     105        Dim request As HttpWebRequest = CreateRequestObject(WEBACCESS_REQ_TYPE.ReqGET, _ 
     106                                                            New Uri(url), _ 
     107                                                            query) 
     108        Return GetText(request, query, encode, headerInfo) 
     109    End Function 
     110 
     111    Protected Shared Function PostData(ByVal url As String, _ 
     112                                        ByRef query As System.Collections.Generic.SortedList(Of String, String), _ 
     113                                        ByVal encode As System.Text.Encoding, _ 
     114                                        ByVal headerInfo As System.Collections.Specialized.NameValueCollection _ 
     115                                    ) As String 
     116        Dim request As HttpWebRequest = CreateRequestObject(WEBACCESS_REQ_TYPE.ReqPOST, _ 
     117                                                            New Uri(url), _ 
     118                                                            query) 
     119        Return GetText(request, query, encode, headerInfo) 
     120    End Function 
     121 
     122    Private Overloads Shared Function GetText(ByVal webRequest As HttpWebRequest, _ 
     123                                        ByVal query As System.Collections.Generic.SortedList(Of String, String), _ 
     124                                        ByVal encode As System.Text.Encoding, _ 
     125                                        ByVal headerInfo As System.Collections.Specialized.NameValueCollection _ 
     126                                    ) As String 
     127 
     128        If _oauthSetting.Token = "" Then Throw New System.UnauthorizedAccessException("Unauthorized OAuth") 
     129 
     130        AppendOAuthInfo(webRequest, query, _oauthSetting.Token, _oauthSetting.TokenSecret) 
     131 
     132        Dim statusCode As HttpStatusCode 
     133        Dim response As String = WebAccessBase.GetText(webRequest, statusCode, encode, headerInfo) 
     134 
     135        If statusCode = HttpStatusCode.Unauthorized Then 
     136            _oauthSetting.ClearToken() 
     137            Throw New System.UnauthorizedAccessException("Unauthorized OAuth") 
     138        End If 
     139 
     140        If statusCode <> HttpStatusCode.OK OrElse String.IsNullOrEmpty(response) Then Return Nothing 
     141        Return response 
     142    End Function 
    104143End Class