From ae1cfe37eebc8c8189f5e82a38c0dba00ec1910d Mon Sep 17 00:00:00 2001 From: syo68k Date: Mon, 31 Jan 2011 04:05:36 +0000 Subject: [PATCH] =?utf8?q?=E3=83=BBPlixi=E3=81=B8=E3=81=AE=E7=94=BB?= =?utf8?q?=E5=83=8F=E6=8A=95=E7=A8=BF=E3=81=AB=E5=AF=BE=E5=BF=9C=20?= =?utf8?q?=E3=83=BBrevert=E3=81=AE=E5=BD=B1=E9=9F=BF=E3=81=A7ChangeLog?= =?utf8?q?=E3=81=BE=E3=81=A7=E5=B7=BB=E3=81=8D=E6=88=BB=E3=81=A3=E3=81=A6?= =?utf8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@1433 e39ad16e-3079-482e-bb30-4b4d378143b6 --- Tween/Connection/Plixi.vb | 117 ++++++++++++++++++++++++++++++++++++++++++ Tween/PictureService.vb | 47 +++++++++++++++++ Tween/Resources/ChangeLog.txt | 6 +++ Tween/Tween.vb | 1 + Tween/Tween.vbproj | 1 + 5 files changed, 172 insertions(+) create mode 100644 Tween/Connection/Plixi.vb diff --git a/Tween/Connection/Plixi.vb b/Tween/Connection/Plixi.vb new file mode 100644 index 00000000..9a1f9295 --- /dev/null +++ b/Tween/Connection/Plixi.vb @@ -0,0 +1,117 @@ +' Tween - Client of Twitter +' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) +' (c) 2008-2011 Moz (@syo68k) +' (c) 2008-2011 takeshik (@takeshik) +' (c) 2010-2011 anis774 (@anis774) +' (c) 2010-2011 fantasticswallow (@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 , 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関連 + ''' + '''OAuthのコンシューマー鍵 + ''' + Private Const ConsumerKey As String = "tLbG3uS0BIIE8jm1mKzKOfZ6EgUOmWVM" + + ''' + '''OAuthの署名作成用秘密コンシューマーデータ + ''' + 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 + diff --git a/Tween/PictureService.vb b/Tween/PictureService.vb index c5ece76c..74369c8f 100644 --- a/Tween/PictureService.vb +++ b/Tween/PictureService.vb @@ -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 diff --git a/Tween/Resources/ChangeLog.txt b/Tween/Resources/ChangeLog.txt index dc9ba318..248a3ee4 100644 --- a/Tween/Resources/ChangeLog.txt +++ b/Tween/Resources/ChangeLog.txt @@ -68,6 +68,12 @@ * 詳細表示の更新頻度見直し * プロフィール表示時に最新発言が返ってこないユーザーの表示ができなかったバグを修正 * その他メニューに指定ユーザーのユーザータイムライン、ふぁぼられを開く機能を追加 + * 画像投稿先を保持するようにした + * UserStreamが有効の場合はRecent/Mentions/DMの定期更新、投稿時取得を停止するようにした + * プロフィール画面でアカウント作成日時が正しく表示されない場合があるのを修正した + * API簡易計算でUserStream、UserTimelineを考慮するように + * API情報ダイアログにUserStream接続状態も表示するように + * Plixiへの画像投稿に対応 ==== Ver 0.9.7.0(2010/11/14) * 描画周りの高速化と調整を行った * リスト表示が真っ白になる現象の対策を行った まだ発生する方はご連絡ください。 diff --git a/Tween/Tween.vb b/Tween/Tween.vb index c99699a4..5bd87208 100644 --- a/Tween/Tween.vb +++ b/Tween/Tween.vb @@ -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 diff --git a/Tween/Tween.vbproj b/Tween/Tween.vbproj index db1a599c..68eea199 100644 --- a/Tween/Tween.vbproj +++ b/Tween/Tween.vbproj @@ -135,6 +135,7 @@ + -- 2.11.0