Delphi XERO – Redirect to GitHub and New Features

https://github.com/littleearth/delphiXERO

Components
TXEROAppDetails

Store XERO credentials

FXEROAppDetails.Privatekey.Text := 'MIICXgIBAAKBgQ....';
FXEROAppDetails.ConsumerKey := 'A12345';
FXEROAppDetails.ConsumerSecret := 'A54321';

TXEROApiJSON

Provide a simple interface for calling the XERO API
Get

var
LXEROAPI: TXEROApiJSON;
begin
LXEROAPI := TXEROApiJSON.Create(nil);
try
LXEROAPI.XEROAppDetails := FXEROAppDetails;
LJSON := LXEROAPI.Get('Contacts','page=1');
finally
FreeAndNil(LXEROAPI);
end;
end;

Post

var
LXEROAPI: TXEROApiJSON;
begin
LXEROAPI := TXEROApiJSON.Create(nil);
try
LXEROAPI.XEROAppDetails := FXEROAppDetails;
LJSON := LXEROAPI.Post('Contacts','[JSON data]');
finally
FreeAndNil(LXEROAPI);
end;
end;

TXERO{Module} ## (eg TXEROContacts)

A complete list is still in progress but helper objects for different XERO modules exists

var
LAPI: TXEROContacts;
LData: TXEROContactResponse;
begin
LAPI := TXEROContacts.Create(nil);
try
LAPI.XEROAppDetails := FXEROAppDetails;
// Search(Page, OrderBy, ContactID, ContactNumber, IncludeArchived
LData := LAPI.Search(1, '', '','', '',false);
if LData.Contacts.Count > 0 then
begin
ShowMessage(LData.Contacts.Item[0].Name);
end;
// AsJSON(Formatted)
LData.Contacts.AsJSON(true);
finally
FreeAndNil(LAPI);
end;
end;

TXEROModel

Models of the type TXM{Type} exist for population (eg TXMContact)
TXEROModelList

A list of TXEROModels (eg TXMContacts)
TXEROModelDataset

Allows the conversion of models to a dataset

var
LAPI: TXEROContacts;
LData: TXEROContactResponse;
LContactDataset : TXEROContactDataset;
begin
LAPI := TXEROContacts.Create(nil);
LContactDataset := TXEROContactDataset.Create;
try
LAPI.XEROAppDetails := FXEROAppDetails;
// Search(Page, OrderBy, ContactID, ContactNumber, IncludeArchived
LData := LAPI.Search(1, '', '','', '',false);
LContactDataset.StoreModelList(LData.Contacts);
While not LContactDataset.Dataset.Eof do
begin
ShowMessage(LContactDataset.Dataset.FieldByName('Name').AsString);
LContactDataset.Dataset.Next;
end;
finally
FreeAndNil(LAPI);
FreeAndNil(LContactDataset);
end;
end;

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.