Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit PastebinAPI;
- interface
- uses
- Winapi.WinHTTP, System.SysUtils, System.Classes;
- type
- TPastebinAPI = class
- private
- FDevKey: string;
- FUserKey: string;
- function SendRequest(const URL, Method, Data: string): string;
- public
- constructor Create(const DevKey: string);
- function Login(const Username, Password: string): Boolean;
- function CreatePaste(const Code, Title, Format, Exposure: string): string;
- function DeletePaste(const PasteCode: string): Boolean;
- function GetUserInformationAndSettings: string;
- function ListPastes: string;
- end;
- implementation
- { TPastebinAPI }
- constructor TPastebinAPI.Create(const DevKey: string);
- begin
- FDevKey := DevKey;
- FUserKey := '';
- end;
- function TPastebinAPI.SendRequest(const URL, Method, Data: string): string;
- var
- Request: IWinHTTPRequest;
- begin
- Request := WinHTTP.WinHTTPRequest;
- Request.Open(Method, URL, False);
- Request.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- 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');
- if FUserKey <> '' then
- Request.SetRequestHeader('api_paste_user_key', FUserKey);
- Request.SetRequestHeader('api_dev_key', FDevKey);
- Request.Send(Data);
- Result := Request.ResponseText;
- end;
- function TPastebinAPI.Login(const Username, Password: string): Boolean;
- var
- URL, Data: string;
- begin
- URL := 'https://pastebin.com/api/api_login.php';
- Data := Format('api_user_name=%s&api_user_password=%s', [Username, Password]);
- FUserKey := SendRequest(URL, 'POST', Data);
- Result := FUserKey <> '';
- end;
- function TPastebinAPI.CreatePaste(const Code, Title, Format, Exposure: string): string;
- var
- URL, Data: string;
- begin
- URL := 'https://pastebin.com/api/api_post.php';
- Data := Format('api_paste_code=%s&api_paste_name=%s&api_paste_format=%s&api_paste_private=%s',
- [Code, Title, Format, Exposure]);
- Result := SendRequest(URL, 'POST', Data);
- end;
- function TPastebinAPI.DeletePaste(const PasteCode: string): Boolean;
- var
- URL, Data: string;
- begin
- URL := 'https://pastebin.com/api/api_post.php';
- Data := Format('api_paste_code=%s&api_paste_private=%s&api_paste_delete_key=%s',
- [PasteCode, '2', FUserKey]);
- Result := SendRequest(URL, 'POST', Data).Contains('paste removed');
- end;
- function TPastebinAPI.GetUserInformationAndSettings: string;
- var
- URL: string;
- begin
- URL := 'https://pastebin.com/api/api_post.php';
- Result := SendRequest(URL, 'POST', 'api_paste_user_details');
- end;
- function TPastebinAPI.ListPastes: string;
- var
- URL: string;
- begin
- URL := 'https://pastebin.com/api/api_post.php';
- Result := SendRequest(URL, 'POST', 'api_paste_user_pastes');
- end;
- end.
- // This class uses the WinHTTP library to send HTTP requests to Pastebin's API. Make sure to replace the FDevKey variable with your
- // actual Pastebin Developer API key.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement