Advertisement
antonydanby

Untitled

Mar 8th, 2024
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.97 KB | None | 0 0
  1. unit PastebinAPI;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.WinHTTP, System.SysUtils, System.Classes;
  7.  
  8. type
  9.   TPastebinAPI = class
  10.   private
  11.     FDevKey: string;
  12.     FUserKey: string;
  13.     function SendRequest(const URL, Method, Data: string): string;
  14.   public
  15.     constructor Create(const DevKey: string);
  16.     function Login(const Username, Password: string): Boolean;
  17.     function CreatePaste(const Code, Title, Format, Exposure: string): string;
  18.     function DeletePaste(const PasteCode: string): Boolean;
  19.     function GetUserInformationAndSettings: string;
  20.     function ListPastes: string;
  21.   end;
  22.  
  23. implementation
  24.  
  25. { TPastebinAPI }
  26.  
  27. constructor TPastebinAPI.Create(const DevKey: string);
  28. begin
  29.   FDevKey := DevKey;
  30.   FUserKey := '';
  31. end;
  32.  
  33. function TPastebinAPI.SendRequest(const URL, Method, Data: string): string;
  34. var
  35.   Request: IWinHTTPRequest;
  36. begin
  37.   Request := WinHTTP.WinHTTPRequest;
  38.   Request.Open(Method, URL, False);
  39.   Request.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  40.   Request.SetRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
  41.  
  42.   if FUserKey <> '' then
  43.     Request.SetRequestHeader('api_paste_user_key', FUserKey);
  44.  
  45.   Request.SetRequestHeader('api_dev_key', FDevKey);
  46.   Request.Send(Data);
  47.   Result := Request.ResponseText;
  48. end;
  49.  
  50. function TPastebinAPI.Login(const Username, Password: string): Boolean;
  51. var
  52.   URL, Data: string;
  53. begin
  54.   URL := 'https://pastebin.com/api/api_login.php';
  55.   Data := Format('api_user_name=%s&api_user_password=%s', [Username, Password]);
  56.  
  57.   FUserKey := SendRequest(URL, 'POST', Data);
  58.  
  59.   Result := FUserKey <> '';
  60. end;
  61.  
  62. function TPastebinAPI.CreatePaste(const Code, Title, Format, Exposure: string): string;
  63. var
  64.   URL, Data: string;
  65. begin
  66.   URL := 'https://pastebin.com/api/api_post.php';
  67.   Data := Format('api_paste_code=%s&api_paste_name=%s&api_paste_format=%s&api_paste_private=%s',
  68.     [Code, Title, Format, Exposure]);
  69.  
  70.   Result := SendRequest(URL, 'POST', Data);
  71. end;
  72.  
  73. function TPastebinAPI.DeletePaste(const PasteCode: string): Boolean;
  74. var
  75.   URL, Data: string;
  76. begin
  77.   URL := 'https://pastebin.com/api/api_post.php';
  78.   Data := Format('api_paste_code=%s&api_paste_private=%s&api_paste_delete_key=%s',
  79.     [PasteCode, '2', FUserKey]);
  80.  
  81.   Result := SendRequest(URL, 'POST', Data).Contains('paste removed');
  82. end;
  83.  
  84. function TPastebinAPI.GetUserInformationAndSettings: string;
  85. var
  86.   URL: string;
  87. begin
  88.   URL := 'https://pastebin.com/api/api_post.php';
  89.  
  90.   Result := SendRequest(URL, 'POST', 'api_paste_user_details');
  91. end;
  92.  
  93. function TPastebinAPI.ListPastes: string;
  94. var
  95.   URL: string;
  96. begin
  97.   URL := 'https://pastebin.com/api/api_post.php';
  98.  
  99.   Result := SendRequest(URL, 'POST', 'api_paste_user_pastes');
  100. end;
  101.  
  102. end.
  103.  
  104. // This class uses the WinHTTP library to send HTTP requests to Pastebin's API. Make sure to replace the FDevKey variable with your
  105. // actual Pastebin Developer API key.
Tags: #pastebin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement