Jump to content
zippoxer

PasteBin API

Recommended Posts

var
 PasteBinHttpClient: Integer;
 PasteBinDevKey, PasteBinUserKey: String;


procedure PasteBinSetup(DevKey: String);
begin
 PasteBinDevKey := DevKey;
 PasteBinHttpClient := InitializeHTTPClient(False, False);
end;


function PasteBinSuccessful(Response: String): Boolean;
begin
 Result := (Length(Response) > 0) and not StartsWith('Bad', Response);
end;


function PasteBinLogin(Name, Password: String): Boolean;
var Response: String;
begin
 ClearPostData(PasteBinHttpClient);
 AddPostVariable(PasteBinHttpClient, 'api_dev_key', PasteBinDevKey);
 AddPostVariable(PasteBinHttpClient, 'api_user_name', Name);
 AddPostVariable(PasteBinHttpClient, 'api_user_password', Password);


 Response := PostHTTPPageEx(PasteBinHttpClient, 'http://pastebin.com/api/api_login.php');
 if PasteBinSuccessful(Response) then
 begin
   PasteBinUserKey := Response;
   Result := True;
 end;
end;


procedure PasteBinLogout;
begin
 PasteBinUserKey := '';
end;


function PasteBinPostEx(Code, Name, ExpireDate, Format: String; IsPrivate: Boolean; out Url: String): Boolean;
var IsPrivateStr, Response: String;
begin
 IsPrivateStr := '0';
 if IsPrivate then
   IsPrivateStr := '1';


 ClearPostData(PasteBinHttpClient);
 AddPostVariable(PasteBinHttpClient, 'api_dev_key', PasteBinDevKey);
 AddPostVariable(PasteBinHttpClient, 'api_user_key', PasteBinUserKey);
 AddPostVariable(PasteBinHttpClient, 'api_option', 'paste');
 AddPostVariable(PasteBinHttpClient, 'api_paste_code', Code);
 AddPostVariable(PasteBinHttpClient, 'api_paste_name', Name);
 AddPostVariable(PasteBinHttpClient, 'api_paste_expire_date', ExpireDate);
 AddPostVariable(PasteBinHttpClient, 'api_paste_format', Format);
 AddPostVariable(PasteBinHttpClient, 'api_paste_private', IsPrivateStr);


 Response := PostHTTPPageEx(PasteBinHttpClient, 'http://pastebin.com/api/api_post.php');
 if PasteBinSuccessful(Response) then
 begin
   Url := Response;
   Result := True;
 end;
end;


// Posts a paste that never expires, has no format and is not private.
function PasteBinPost(Code: String; out Url: String): Boolean;
begin
 Result := PasteBinPostEx(Code, '', 'N', 'text', False, Url);
end;


procedure PasteBinTest;
var Url: String;
begin
 PasteBinSetup('89fd7c77653a7e05ab04010a0aba000a');
 if PasteBinLogin('ScarStatistics', 'service') then
 begin
   WriteLn('Logged in to pastebin.');
   if PasteBinPostEx('"omfg"', 'I have 10 minutes left to live!', '10M', 'php', True, Url) then
     WriteLn('Successfully posted that: ' + Url)
   else
     WriteLn('Failed to post.');
 end
 else
   WriteLn('Are you kidding me?');
end;

 

Usage sample is in the PasteBinTest procedure.

You can use it to submit statistics ;)

Edited by zippoxer
documentation
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...