Advertisement
Guest User

wARIS

a guest
Oct 31st, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.Net;
  4. using System.Text;
  5.  
  6. namespace PasteRight
  7. {
  8.     class PastebinSharp
  9.     {
  10.         private string ILoginURL = "http://pastebin.com/api/api_login.php";
  11.         private string IPostURL = "http://pastebin.com/api/api_post.php";
  12.         private string IDevKey = "";
  13.         private string IUserKey = null;
  14.  
  15.         public void Send(string IBody, string ISubj, string IFormat)
  16.         {
  17.             if (string.IsNullOrEmpty(IBody.Trim())) { return; }
  18.             if (string.IsNullOrEmpty(ISubj.Trim())) { return; }
  19.  
  20.             NameValueCollection IQuery = new NameValueCollection();
  21.  
  22.             IQuery.Add("api_dev_key", IDevKey);
  23.             IQuery.Add("api_option", "paste");
  24.             IQuery.Add("api_paste_code", IBody);
  25.             IQuery.Add("api_paste_private", "0");
  26.             IQuery.Add("api_paste_name", ISubj);
  27.             IQuery.Add("api_paste_expire_date", "N");
  28.             IQuery.Add("api_paste_format", IFormat);
  29.             IQuery.Add("api_user_key", IUserKey);
  30.  
  31.             using (WebClient IClient = new WebClient())
  32.             {
  33.                 string IResponse = Encoding.UTF8.GetString(IClient.UploadValues(IPostURL, IQuery));
  34.  
  35.                 Uri isValid = null;
  36.                 if (!Uri.TryCreate(IResponse, UriKind.Absolute, out isValid))
  37.                 {
  38.                     throw new WebException("Paste Error", WebExceptionStatus.SendFailure);
  39.                 }
  40.             }
  41.         }
  42.  
  43.         public PastebinSharp(string Username, string Password)
  44.         {
  45.             NameValueCollection IQuery = new NameValueCollection();
  46.  
  47.             IQuery.Add("api_dev_key", IDevKey);
  48.             IQuery.Add("api_user_name", Username);
  49.             IQuery.Add("api_user_password", Password);
  50.  
  51.             using (WebClient wc = new WebClient())
  52.             {
  53.                 byte[] respBytes = wc.UploadValues(ILoginURL, IQuery);
  54.                 string resp = Encoding.UTF8.GetString(respBytes);
  55.  
  56.                 if (resp.Contains("Bad API request"))
  57.                 {
  58.                     throw new WebException("Bad Request", WebExceptionStatus.SendFailure);
  59.                 }
  60.  
  61.                 IUserKey = resp;
  62.             }
  63.         }
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement