OSDN Git Service

・Plixiへの画像投稿に対応
authorsyo68k <syo68k@users.sourceforge.jp>
Mon, 31 Jan 2011 04:05:36 +0000 (04:05 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:18:55 +0000 (23:18 +0900)
・revertの影響でChangeLogまで巻き戻っていたのを修正

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

Tween/Connection/Plixi.vb [new file with mode: 0644]
Tween/PictureService.vb
Tween/Resources/ChangeLog.txt
Tween/Tween.vb
Tween/Tween.vbproj

diff --git a/Tween/Connection/Plixi.vb b/Tween/Connection/Plixi.vb
new file mode 100644 (file)
index 0000000..9a1f929
--- /dev/null
@@ -0,0 +1,117 @@
+' Tween - Client of Twitter
+' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
+'           (c) 2008-2011 Moz (@syo68k)
+'           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
+'           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
+'           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
+' All rights reserved.
+' 
+' This file is part of Tween.
+' 
+' This program is free software; you can redistribute it and/or modify it
+' under the terms of the GNU General Public License as published by the Free
+' Software Foundation; either version 3 of the License, or (at your option)
+' any later version.
+' 
+' This program is distributed in the hope that it will be useful, but
+' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+' for more details. 
+' 
+' You should have received a copy of the GNU General Public License along
+' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+' Boston, MA 02110-1301, USA.
+
+Imports System.IO
+Imports System.Net
+
+Public Class Plixi
+    Inherits HttpConnectionOAuthEcho
+
+    'OAuth関連
+    '''<summary>
+    '''OAuthのコンシューマー鍵
+    '''</summary>
+    Private Const ConsumerKey As String = "tLbG3uS0BIIE8jm1mKzKOfZ6EgUOmWVM"
+
+    '''<summary>
+    '''OAuthの署名作成用秘密コンシューマーデータ
+    '''</summary>
+    Private Const ConsumerSecretKey As String = "M0IMsbl2722iWa+CGPVcNeQmE+TFpJk8B/KW9UUTk3eLOl9Ij005r52JNxVukTzM"
+
+    Private Const PostMethod As String = "POST"
+    Private Const GetMethod As String = "GET"
+    Private Const ApiKey As String = "c0263958-f32c-4704-9dac-cdc806b1249c"
+    Private pictureExt() As String = {".jpg", _
+                                    ".jpeg", _
+                                    ".gif", _
+                                    ".png"}
+
+    Private Const MaxFileSize As Long = 5 * 1024 * 1024
+
+    Public Function Upload(ByVal mediaFile As FileInfo, _
+                       ByVal message As String, _
+                       ByRef content As String) As HttpStatusCode
+        'Message必須
+        If String.IsNullOrEmpty(message) Then message = ""
+        'Check filetype and size(Max 5MB)
+        If Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then
+            If mediaFile.Length > MaxFileSize Then Throw New ArgumentException("File is too large.")
+        Else
+            Throw New ArgumentException("Service don't support this filetype.")
+        End If
+
+        Dim param As New Dictionary(Of String, String)
+        param.Add("api_key", ApiKey)
+        param.Add("message", message)
+        param.Add("isoauth", "true")
+        Dim binary As New List(Of KeyValuePair(Of String, FileInfo))
+        binary.Add(New KeyValuePair(Of String, FileInfo)("media", mediaFile))
+        Me.InstanceTimeout = 60000 'タイムアウト60秒
+
+        Return GetContent(PostMethod, _
+                          New Uri("http://api.plixi.com/api/upload.aspx"), _
+                          param, _
+                          binary, _
+                          content, _
+                          Nothing, _
+                          Nothing)
+    End Function
+
+    Public Function CheckValidExtension(ByVal ext As String) As Boolean
+        If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
+            Return True
+        End If
+        Return False
+    End Function
+
+    Public Function GetFileOpenDialogFilter() As String
+        Return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png"
+    End Function
+
+    Public Function GetFileType(ByVal ext As String) As UploadFileType
+        If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
+            Return UploadFileType.Picture
+        End If
+        Return UploadFileType.Invalid
+    End Function
+
+    Public Function IsSupportedFileType(ByVal type As UploadFileType) As Boolean
+        Return type.Equals(UploadFileType.Picture)
+    End Function
+
+    Public Function GetMaxFileSize(ByVal ext As String) As Long
+        If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
+            Return MaxFileSize
+        End If
+        Return -1
+    End Function
+
+    Public Sub New(ByVal accessToken As String, ByVal accessTokenSecret As String)
+        MyBase.New(New Uri("http://api.twitter.com/"), _
+                   New Uri("https://api.twitter.com/1/account/verify_credentials.json"))
+        Initialize(DecryptString(ConsumerKey), DecryptString(ConsumerSecretKey), accessToken, accessTokenSecret, "")
+    End Sub
+End Class
+
index c5ece76..74369c8 100644 (file)
@@ -50,6 +50,8 @@ Public Class PictureService
                 '    ret = UpToTwitVideo(file, message, upResult)
             Case "yfrog"
                 ret = UpToyfrog(file, message, upResult)
+            Case "Plixi"
+                ret = UpToPlixi(file, message, upResult)
         End Select
         If upResult Then filePath = ""
         Return ret
@@ -66,6 +68,8 @@ Public Class PictureService
                 '    ret = (New TwitVideo).CheckValidExtension(ext)
             Case "yfrog"
                 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).CheckValidExtension(ext)
+            Case "Plixi"
+                ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).CheckValidExtension(ext)
         End Select
         Return ret
     End Function
@@ -81,6 +85,8 @@ Public Class PictureService
                 '    ret = (New TwitVideo).GetFileOpenDialogFilter
             Case "yfrog"
                 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).GetFileOpenDialogFilter
+            Case "Plixi"
+                ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).GetFileOpenDialogFilter
         End Select
         Return ret
     End Function
@@ -96,6 +102,8 @@ Public Class PictureService
                 '    ret = (New TwitVideo).GetFileType(ext)
             Case "yfrog"
                 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).GetFileType(ext)
+            Case "Plixi"
+                ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).GetFileType(ext)
         End Select
         Return ret
     End Function
@@ -111,6 +119,8 @@ Public Class PictureService
                 '    ret = (New TwitVideo).IsSupportedFileType(type)
             Case "yfrog"
                 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).IsSupportedFileType(type)
+            Case "Plixi"
+                ret = (New Plixi(tw.AccessToken, tw.AccessTokenSecret)).IsSupportedFileType(type)
         End Select
         Return ret
     End Function
@@ -126,6 +136,8 @@ Public Class PictureService
                 '    ret = (New TwitVideo).GetMaxFileSize(ext)
             Case "yfrog"
                 ret = (New yfrog(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext)
+            Case "Plixi"
+                ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext)
         End Select
         Return ret
     End Function
@@ -235,6 +247,41 @@ Public Class PictureService
         Return tw.PostStatus(message, 0)
     End Function
 
+    Private Function UpToPlixi(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
+        Dim content As String = ""
+        Dim ret As HttpStatusCode
+        'Plixiへの投稿
+        Dim svc As New Plixi(tw.AccessToken, tw.AccessTokenSecret)
+        Try
+            ret = svc.Upload(file, message, content)
+        Catch ex As Exception
+            Return "Err:" + ex.Message
+        End Try
+        Dim url As String = ""
+        If ret = HttpStatusCode.Created Then
+            Dim xd As XmlDocument = New XmlDocument()
+            Try
+                xd.LoadXml(content)
+                'MediaUrlの取得
+                url = xd.ChildNodes().Item(0).ChildNodes(2).InnerText
+            Catch ex As XmlException
+                Return "Err:" + ex.Message
+            End Try
+        Else
+            Return "Err:" + ret.ToString
+        End If
+        'アップロードまでは成功
+        resultUpload = True
+        'Twitterへの投稿
+        '投稿メッセージの再構成
+        If message.Length + url.Length + 1 > 140 Then
+            message = message.Substring(0, 140 - url.Length - 1) + " " + url
+        Else
+            message += " " + url
+        End If
+        Return tw.PostStatus(message, 0)
+    End Function
+
     'Private Function UpToTwitVideo(ByVal file As FileInfo, ByRef message As String, ByRef resultUpload As Boolean) As String
     '    Dim content As String = ""
     '    Dim ret As HttpStatusCode
index dc9ba31..248a3ee 100644 (file)
  * 詳細表示の更新頻度見直し
  * プロフィール表示時に最新発言が返ってこないユーザーの表示ができなかったバグを修正
  * その他メニューに指定ユーザーのユーザータイムライン、ふぁぼられを開く機能を追加
+ * 画像投稿先を保持するようにした
+ * UserStreamが有効の場合はRecent/Mentions/DMの定期更新、投稿時取得を停止するようにした
+ * プロフィール画面でアカウント作成日時が正しく表示されない場合があるのを修正した
+ * API簡易計算でUserStream、UserTimelineを考慮するように
+ * API情報ダイアログにUserStream接続状態も表示するように
+ * Plixiへの画像投稿に対応
 ==== Ver 0.9.7.0(2010/11/14)
  * 描画周りの高速化と調整を行った
  * リスト表示が真っ白になる現象の対策を行った まだ発生する方はご連絡ください。
index c99699a..5bd8720 100644 (file)
@@ -9627,6 +9627,7 @@ RETRY:
             ImageServiceCombo.Items.Add("TwitPic")
             ImageServiceCombo.Items.Add("img.ly")
             ImageServiceCombo.Items.Add("yfrog")
+            ImageServiceCombo.Items.Add("Plixi")
         End If
         'ImageServiceCombo.Items.Add("TwitVideo")
         If svc = "" Then
index db1a599..68eea19 100644 (file)
     <Compile Include="Connection\HttpTwitter.vb" />
     <Compile Include="Connection\HttpVarious.vb" />
     <Compile Include="Connection\IHttpConnection.vb" />
+    <Compile Include="Connection\Plixi.vb" />
     <Compile Include="Connection\TwitPic.vb" />
     <Compile Include="Connection\imgly.vb" />
     <Compile Include="Connection\yfrog.vb" />