unit Unit1;
interface
uses
Windows, Classes, Forms,
xmldom, XMLIntf, msxmldom, XMLDoc, idHTTP;
type
TForm1 =
class(TForm)
XMLDocument: TXMLDocument;
procedure FormCreate(Sender: TObject);
private
Request: TidHTTP;
Parameters: TStringList;
ResponseStream: TStringStream;
procedure NewRequest;
function Get: Boolean;
function Post: Boolean;
function DeletePage(PageID:
string): Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
API:
string = '
http://lyrics.wikia.com/api.php';
procedure TForm1.FormCreate(Sender: TObject);
begin
Request := TIdHTTP.Create;
end;
function TForm1.DeletePage(PageID:
string): Boolean;
var
Token:
string;
begin
Result := False; Token := '
';
NewRequest;
Parameters.Add('
action=query');
Parameters.Add('
prop=info');
Parameters.Add('
pageids='+PageID);
Parameters.Add('
intoken=delete');
if Get
then
begin
Token := XMLDocument.DocumentElement.ChildNodes['
query'].ChildNodes['
pages'].ChildNodes[0].AttributeNodes['
deletetoken'].Text;
NewRequest;
Parameters.Add('
action=delete');
Parameters.Add('
pageid='+PageID);
Parameters.Add('
token='+Token);
if Post
then
Result := (XMLDocument.DocumentElement.ChildNodes[0].NodeName = '
delete');
end;
end;
{ Allgemeines Zurücksetzen }
procedure TForm1.NewRequest;
begin
ResponseStream.Free;
ResponseStream := TStringStream.Create('
');
Parameters.Free;
Parameters := TStringList.Create;
Parameters.Add('
format=xml');
Parameters.Delimiter := '
&';
end;
{ Allgemeine Funktion für GET Anfragen }
function TForm1.Get: Boolean;
begin
try
Request.Get(
API+'
?'+Parameters.DelimitedText, ResponseStream);
XMLDocument.Active := False;
XMLDocument.LoadFromStream(ResponseStream, xetUTF_8);
XMLDocument.Active := True;
Result := True;
except
Result := False;
end;
end;
{ Allgemeine Funktion für POST Anfragen }
function TForm1.Post: Boolean;
begin
try
Request.Post(
API, Parameters, ResponseStream);
XMLDocument.Active := False;
XMLDocument.LoadFromStream(ResponseStream, xetUTF_8);
XMLDocument.Active := True;
Result := True;
except
Result := False;
end;
end;