Switch Gist upload to ShareX application

Add support for secret/public gist
This commit is contained in:
Gregoire Pailler 2013-12-03 22:49:15 +01:00
parent ee9af500dd
commit 7ab0568a66
9 changed files with 94 additions and 67 deletions

View file

@ -667,7 +667,7 @@ public UploadResult UploadText(Stream stream, string fileName)
textUploader = new Paste_ee(Program.UploadersConfig.Paste_eeUserAPIKey);
break;
case TextDestination.Gist:
textUploader = Program.UploadersConfig.GistAnonymousLogin ? new Gist() : new Gist(Program.UploadersConfig.GistOAuth2Info);
textUploader = new Gist(Program.UploadersConfig.GistPublishPublic, Program.UploadersConfig.GistOAuth2Info);
break;
case TextDestination.CustomTextUploader:
if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomTextUploaderSelected))

View file

@ -60,8 +60,8 @@ public static class ApiKeys
// Text Uploaders
public const string PastebinKey = "4b23be71ec78bbd4fb96735320aa09ef";
public const string PastebinCaKey = "KxTofLKQThSBZ63Gpa7hYLlMdyQlMD6u";
public const string GistId = "60cd5843cab0522f8501";
public const string GistSecret = "fa6eec2009b7fee1037548a96886992acc39fee8";
public const string GistId = "badfa7b5e0a67e31da88";
public const string GistSecret = "a538eff39300680f43d123a59ab9c1d9d4763640";
// URL Shorteners
public const string BitlyLogin = "jaex";

View file

@ -102,6 +102,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public bool GistAnonymousLogin = true;
public OAuth2Info GistOAuth2Info = null;
public bool GistPublishPublic = false;
#endregion Text uploaders

View file

@ -122,6 +122,7 @@ private void InitializeComponent()
this.lblPaste_eeUserAPIKey = new System.Windows.Forms.Label();
this.txtPaste_eeUserAPIKey = new System.Windows.Forms.TextBox();
this.tpGist = new System.Windows.Forms.TabPage();
this.chkGistPublishPublic = new System.Windows.Forms.CheckBox();
this.oAuth2Gist = new UploadersLib.GUI.OAuth2Control();
this.atcGistAccountType = new UploadersLib.GUI.AccountTypeControl();
this.tpFileUploaders = new System.Windows.Forms.TabPage();
@ -280,7 +281,9 @@ private void InitializeComponent()
this.lblCustomUploaderResponseType = new System.Windows.Forms.Label();
this.cbCustomUploaderURLShortener = new System.Windows.Forms.ComboBox();
this.gbCustomUploaders = new System.Windows.Forms.GroupBox();
this.btnCustomUploaderImport = new System.Windows.Forms.Button();
this.lbCustomUploaderList = new System.Windows.Forms.ListBox();
this.btnCustomUploaderExport = new System.Windows.Forms.Button();
this.btnCustomUploaderRemove = new System.Windows.Forms.Button();
this.btnCustomUploaderClear = new System.Windows.Forms.Button();
this.btnCustomUploaderUpdate = new System.Windows.Forms.Button();
@ -323,8 +326,6 @@ private void InitializeComponent()
this.txtRapidSharePremiumUserName = new System.Windows.Forms.TextBox();
this.ttHelpTip = new System.Windows.Forms.ToolTip(this.components);
this.actRapidShareAccountType = new UploadersLib.GUI.AccountTypeControl();
this.btnCustomUploaderExport = new System.Windows.Forms.Button();
this.btnCustomUploaderImport = new System.Windows.Forms.Button();
this.tcUploaders.SuspendLayout();
this.tpImageUploaders.SuspendLayout();
this.tcImageUploaders.SuspendLayout();
@ -1342,6 +1343,7 @@ private void InitializeComponent()
//
// tpGist
//
this.tpGist.Controls.Add(this.chkGistPublishPublic);
this.tpGist.Controls.Add(this.oAuth2Gist);
this.tpGist.Controls.Add(this.atcGistAccountType);
this.tpGist.Location = new System.Drawing.Point(4, 22);
@ -1351,10 +1353,21 @@ private void InitializeComponent()
this.tpGist.Text = "Gist";
this.tpGist.UseVisualStyleBackColor = true;
//
// chkGistPublishPublic
//
this.chkGistPublishPublic.AutoSize = true;
this.chkGistPublishPublic.Location = new System.Drawing.Point(235, 23);
this.chkGistPublishPublic.Name = "chkGistPublishPublic";
this.chkGistPublishPublic.Size = new System.Drawing.Size(109, 17);
this.chkGistPublishPublic.TabIndex = 17;
this.chkGistPublishPublic.Text = "Create public Gist";
this.chkGistPublishPublic.UseVisualStyleBackColor = true;
this.chkGistPublishPublic.CheckedChanged += new System.EventHandler(this.chkGistPublishPublic_CheckedChanged);
//
// oAuth2Gist
//
this.oAuth2Gist.Enabled = false;
this.oAuth2Gist.Location = new System.Drawing.Point(15, 51);
this.oAuth2Gist.Location = new System.Drawing.Point(16, 51);
this.oAuth2Gist.LoginStatus = false;
this.oAuth2Gist.Name = "oAuth2Gist";
this.oAuth2Gist.Size = new System.Drawing.Size(328, 207);
@ -3062,6 +3075,16 @@ private void InitializeComponent()
this.gbCustomUploaders.TabStop = false;
this.gbCustomUploaders.Text = "Uploaders";
//
// btnCustomUploaderImport
//
this.btnCustomUploaderImport.Location = new System.Drawing.Point(80, 328);
this.btnCustomUploaderImport.Name = "btnCustomUploaderImport";
this.btnCustomUploaderImport.Size = new System.Drawing.Size(64, 23);
this.btnCustomUploaderImport.TabIndex = 35;
this.btnCustomUploaderImport.Text = "Import";
this.btnCustomUploaderImport.UseVisualStyleBackColor = true;
this.btnCustomUploaderImport.Click += new System.EventHandler(this.btnCustomUploaderImport_Click);
//
// lbCustomUploaderList
//
this.lbCustomUploaderList.FormattingEnabled = true;
@ -3072,6 +3095,16 @@ private void InitializeComponent()
this.lbCustomUploaderList.TabIndex = 4;
this.lbCustomUploaderList.SelectedIndexChanged += new System.EventHandler(this.lbCustomUploaderList_SelectedIndexChanged);
//
// btnCustomUploaderExport
//
this.btnCustomUploaderExport.Location = new System.Drawing.Point(8, 328);
this.btnCustomUploaderExport.Name = "btnCustomUploaderExport";
this.btnCustomUploaderExport.Size = new System.Drawing.Size(64, 23);
this.btnCustomUploaderExport.TabIndex = 34;
this.btnCustomUploaderExport.Text = "Export";
this.btnCustomUploaderExport.UseVisualStyleBackColor = true;
this.btnCustomUploaderExport.Click += new System.EventHandler(this.btnCustomUploaderExport_Click);
//
// btnCustomUploaderRemove
//
this.btnCustomUploaderRemove.Location = new System.Drawing.Point(88, 40);
@ -3463,26 +3496,6 @@ private void InitializeComponent()
this.actRapidShareAccountType.Size = new System.Drawing.Size(214, 29);
this.actRapidShareAccountType.TabIndex = 16;
//
// btnCustomUploaderExport
//
this.btnCustomUploaderExport.Location = new System.Drawing.Point(8, 328);
this.btnCustomUploaderExport.Name = "btnCustomUploaderExport";
this.btnCustomUploaderExport.Size = new System.Drawing.Size(64, 23);
this.btnCustomUploaderExport.TabIndex = 34;
this.btnCustomUploaderExport.Text = "Export";
this.btnCustomUploaderExport.UseVisualStyleBackColor = true;
this.btnCustomUploaderExport.Click += new System.EventHandler(this.btnCustomUploaderExport_Click);
//
// btnCustomUploaderImport
//
this.btnCustomUploaderImport.Location = new System.Drawing.Point(80, 328);
this.btnCustomUploaderImport.Name = "btnCustomUploaderImport";
this.btnCustomUploaderImport.Size = new System.Drawing.Size(64, 23);
this.btnCustomUploaderImport.TabIndex = 35;
this.btnCustomUploaderImport.Text = "Import";
this.btnCustomUploaderImport.UseVisualStyleBackColor = true;
this.btnCustomUploaderImport.Click += new System.EventHandler(this.btnCustomUploaderImport_Click);
//
// UploadersConfigForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -3528,6 +3541,7 @@ private void InitializeComponent()
this.tpPaste_ee.ResumeLayout(false);
this.tpPaste_ee.PerformLayout();
this.tpGist.ResumeLayout(false);
this.tpGist.PerformLayout();
this.tpFileUploaders.ResumeLayout(false);
this.tcFileUploaders.ResumeLayout(false);
this.tpDropbox.ResumeLayout(false);
@ -3885,5 +3899,6 @@ private void InitializeComponent()
private GUI.OAuth2Control oAuth2Gist;
private System.Windows.Forms.Button btnCustomUploaderImport;
private System.Windows.Forms.Button btnCustomUploaderExport;
private System.Windows.Forms.CheckBox chkGistPublishPublic;
}
}

View file

@ -1181,8 +1181,13 @@ private void txtPaste_eeUserAPIKey_TextChanged(object sender, EventArgs e)
private void atcGistAccountType_AccountTypeChanged(AccountType accountType)
{
Config.GistAnonymousLogin = accountType == AccountType.Anonymous;
oAuth2Gist.Enabled = !Config.GistAnonymousLogin;
this.Config.GistAnonymousLogin = accountType == AccountType.Anonymous;
if (accountType == AccountType.Anonymous)
{
this.Config.GistOAuth2Info = null;
}
this.oAuth2Gist.Enabled = !this.Config.GistAnonymousLogin;
}
private void oAuth2Gist_CompleteButtonClicked(string code)
@ -1200,6 +1205,11 @@ private void oAuth2Gist_RefreshButtonClicked()
MessageBox.Show("Refresh authorization is not supported.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void chkGistPublishPublic_CheckedChanged(object sender, EventArgs e)
{
this.Config.GistPublishPublic = ((CheckBox)sender).Checked;
}
#endregion
#endregion Text Uploaders

View file

@ -117,33 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ttHelpTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="label1.ToolTip" xml:space="preserve">
<value>If URL textbox is empty then 'Response text' or 'Redirection URL' will be automatically used.
Regex usage for get regex result: $n$
'n' must be index number from 'Regex from response' list.
Example for get second regex result from list: $2$
Regex groups usage: $n,n$ or $n,name$
Second 'n' here must be group number or group name.
Example: $3,1$ or $2,thumbnail_result$</value>
</data>
<data name="lblCustomUploaderRequestTypeHelp.ToolTip" xml:space="preserve">
<value>For image uploader &amp; file uploader: The 'POST' request type is required along with the 'File form name'.
For text uploader or url shortener: 'POST' with no 'File Form Name' or 'GET' will replace an argument with
value '%input' or '$input$' with the text or URL.
For text uploader: Specifying 'POST' request type and a 'File Form Name' will upload the input as a file
(useful for very long inputs).
For example, if the argument name is 'pastebin_text' then a value of '%input' will be automatically
replaced with the text you're going to upload. Same thing applies for url shortener; '%input'
will be replaced with the url in the argument.</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pbDropboxLogo.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@ -264,4 +237,28 @@ will be replaced with the url in the argument.</value>
<metadata name="ttHelpTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="label1.ToolTip" xml:space="preserve">
<value>If URL textbox is empty then 'Response text' or 'Redirection URL' will be automatically used.
Regex usage for get regex result: $n$
'n' must be index number from 'Regex from response' list.
Example for get second regex result from list: $2$
Regex groups usage: $n,n$ or $n,name$
Second 'n' here must be group number or group name.
Example: $3,1$ or $2,thumbnail_result$</value>
</data>
<data name="lblCustomUploaderRequestTypeHelp.ToolTip" xml:space="preserve">
<value>For image uploader &amp; file uploader: The 'POST' request type is required along with the 'File form name'.
For text uploader or url shortener: 'POST' with no 'File Form Name' or 'GET' will replace an argument with
value '%input' or '$input$' with the text or URL.
For text uploader: Specifying 'POST' request type and a 'File Form Name' will upload the input as a file
(useful for very long inputs).
For example, if the argument name is 'pastebin_text' then a value of '%input' will be automatically
replaced with the text you're going to upload. Same thing applies for url shortener; '%input'
will be replaced with the url in the argument.</value>
</data>
</root>

View file

@ -219,6 +219,7 @@ public void LoadSettings(UploadersConfig uploadersConfig)
// Gist
atcGistAccountType.SelectedAccountType = Config.GistAnonymousLogin ? AccountType.Anonymous : AccountType.User;
chkGistPublishPublic.Checked = Config.GistPublishPublic;
#endregion Text uploaders

View file

@ -1474,6 +1474,7 @@ public void JiraAuthComplete(string code)
#endregion Jira
#region Gist
public void GistAuthOpen()
{
try

View file

@ -23,32 +23,35 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using Newtonsoft.Json;
using System.Collections.Generic;
using UploadersLib.HelperClasses;
namespace UploadersLib.TextUploaders
{
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using Newtonsoft.Json;
using UploadersLib.HelperClasses;
public sealed class Gist : TextUploader
{
private readonly Uri GistUri = new Uri("https://api.github.com/gists");
private readonly Uri GistAuthorizeUri = new Uri("https://github.com/login/oauth/authorize");
private readonly Uri GistCompleteUri = new Uri("https://github.com/login/oauth/access_token");
private readonly Uri GistRedirectUri = new Uri("http://ksr.pailler.fr/gist/gist.html");
private readonly Uri GistRedirectUri = new Uri("http://getsharex.com/github/");
private readonly OAuth2Info oAuthInfos;
private readonly bool publishPublic;
public Gist()
: this(null)
public Gist(OAuth2Info oAuthInfos)
: this(false, oAuthInfos)
{
}
public Gist(OAuth2Info oAuthInfos)
public Gist(bool publishPublic, OAuth2Info oAuthInfos)
{
this.publishPublic = publishPublic;
this.oAuthInfos = oAuthInfos;
}
@ -90,8 +93,7 @@ public bool GetAccessToken(string code)
return false;
}
public override UploadResult UploadText(string text, string fileName)
{
UploadResult ur = new UploadResult();
@ -100,7 +102,7 @@ public override UploadResult UploadText(string text, string fileName)
{
var gistUploadObject = new
{
@public = true,
@public = this.publishPublic,
files = new Dictionary<string, object>
{
{ fileName, new { content = text } }
@ -118,7 +120,7 @@ public override UploadResult UploadText(string text, string fileName)
string response = SendPostRequestJSON(Uri, argsJson);
if (response != null)
{
var gistReturnType = new { html_url = "" };
var gistReturnType = new { html_url = string.Empty };
var gistReturnObject = JsonConvert.DeserializeAnonymousType(response, gistReturnType);
ur.URL = gistReturnObject.html_url;
}