1 ' Tween - Client of Twitter
2 ' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 ' (c) 2008-2011 Moz (@syo68k)
4 ' (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 ' (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 ' (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
9 ' This file is part of Tween.
11 ' This program is free software; you can redistribute it and/or modify it
12 ' under the terms of the GNU General Public License as published by the Free
13 ' Software Foundation; either version 3 of the License, or (at your option)
16 ' This program is distributed in the hope that it will be useful, but
17 ' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 ' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 ' You should have received a copy of the GNU General Public License along
22 ' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23 ' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24 ' Boston, MA 02110-1301, USA.
31 Inherits HttpConnectionOAuthEcho
37 Private Const ConsumerKey As String = "tLbG3uS0BIIE8jm1mKzKOfZ6EgUOmWVM"
40 '''OAuthの署名作成用秘密コンシューマーデータ
42 Private Const ConsumerSecretKey As String = "M0IMsbl2722iWa+CGPVcNeQmE+TFpJk8B/KW9UUTk3eLOl9Ij005r52JNxVukTzM"
44 Private Const PostMethod As String = "POST"
45 Private Const GetMethod As String = "GET"
46 Private pictureExt() As String = {".jpg", _
51 Private Const MaxFileSize As Long = 4 * 1024 * 1024
53 Public Function Upload(ByVal mediaFile As FileInfo, _
54 ByVal message As String, _
55 ByRef content As String) As HttpStatusCode
57 If String.IsNullOrEmpty(message) Then message = ""
58 'Check filetype and size(Max 4MB)
59 If Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then
60 If mediaFile.Length > MaxFileSize Then Throw New ArgumentException("File is too large.")
62 Throw New ArgumentException("Service don't support this filetype.")
65 Dim param As New Dictionary(Of String, String)
66 param.Add("message", message)
67 Dim binary As New List(Of KeyValuePair(Of String, FileInfo))
68 binary.Add(New KeyValuePair(Of String, FileInfo)("media", mediaFile))
69 Me.InstanceTimeout = 60000 'タイムアウト60秒
71 Return GetContent(PostMethod, _
72 New Uri("http://img.ly/api/2/upload.xml"), _
80 Public Function CheckValidExtension(ByVal ext As String) As Boolean
81 If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
87 Public Function GetFileOpenDialogFilter() As String
88 Return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png"
91 Public Function GetFileType(ByVal ext As String) As UploadFileType
92 If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
93 Return UploadFileType.Picture
95 Return UploadFileType.Invalid
98 Public Function IsSupportedFileType(ByVal type As UploadFileType) As Boolean
99 Return type.Equals(UploadFileType.Picture)
102 Public Function GetMaxFileSize(ByVal ext As String) As Long
103 If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
109 Public Sub New(ByVal accessToken As String, ByVal accessTokenSecret As String)
110 MyBase.New(New Uri("http://api.twitter.com/"), _
111 New Uri("https://api.twitter.com/1/account/verify_credentials.json"))
112 Initialize(DecryptString(ConsumerKey), DecryptString(ConsumerSecretKey), accessToken, accessTokenSecret, "")