Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
MercadoLibre - Consultar mis datos personales
See more MercadoLibre Examples
Consultar mis datos personalesChilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.StringBuilder,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
jsonToken: TJsonObject;
sbResponseBody: TStringBuilder;
jResp: TJsonObject;
respStatusCode: Integer;
strVal: string;
id: Integer;
nickname: string;
registration_date: string;
country_id: string;
addressState: string;
addressCity: string;
user_type: string;
logo: string;
points: Integer;
site_id: string;
permalink: string;
seller_reputationLevel_id: string;
seller_reputationPower_seller_status: string;
seller_reputationTransactionsPeriod: string;
seller_reputationTransactionsTotal: Integer;
seller_reputationTransactionsCompleted: Integer;
seller_reputationTransactionsCanceled: Integer;
seller_reputationTransactionsRatingsPositive: Integer;
seller_reputationTransactionsRatingsNegative: Integer;
seller_reputationTransactionsRatingsNeutral: Integer;
statusSite_status: string;
i: Integer;
count_i: Integer;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
// First get our previously obtained OAuth2 access token.
jsonToken := TJsonObject.Create;
success := jsonToken.LoadFile('qa_data/tokens/mercadolibre.json');
// Implements the following CURL command:
// curl - X GET https://api.mercadolibre.com/users/me?access_token=$ACCESS_TOKEN
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
http.SetUrlVar('access_token',jsonToken.StringOf('access_token'));
sbResponseBody := TStringBuilder.Create;
success := http.QuickGetSb('https://api.mercadolibre.com/users/me?access_token={$access_token}',sbResponseBody);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
jResp := TJsonObject.Create;
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact := False;
WriteLn('Response Body:');
WriteLn(jResp.Emit());
respStatusCode := http.LastStatus;
WriteLn('Response Status Code = ' + respStatusCode);
if (respStatusCode >= 400) then
begin
WriteLn('Response Header:');
WriteLn(http.LastHeader);
WriteLn('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": 202593498,
// "nickname": "TETE2870021",
// "registration_date": "2016-01-06T11: 31: 42.000-04: 00",
// "country_id": "AR",
// "address": {
// "state": "AR-C",
// "city": "Palermo"
// },
// "user_type": "normal",
// "tags": [
// "normal",
// "test_user",
// "user_info_verified"
// ],
// "logo": null,
// "points": 100,
// "site_id": "MLA",
// "permalink": "http://perfil.mercadolibre.com.ar/TETE2870021",
// "seller_reputation": {
// "level_id": null,
// "power_seller_status": null,
// "transactions": {
// "period": "historic",
// "total": 0,
// "completed": 0,
// "canceled": 0,
// "ratings": {
// "positive": 0,
// "negative": 0,
// "neutral": 0
// }
// }
// },
// "buyer_reputation": {
// "tags": [
// ]
// },
// "status": {
// "site_status": "active"
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
id := jResp.IntOf('id');
nickname := jResp.StringOf('nickname');
registration_date := jResp.StringOf('registration_date');
country_id := jResp.StringOf('country_id');
addressState := jResp.StringOf('address.state');
addressCity := jResp.StringOf('address.city');
user_type := jResp.StringOf('user_type');
logo := jResp.StringOf('logo');
points := jResp.IntOf('points');
site_id := jResp.StringOf('site_id');
permalink := jResp.StringOf('permalink');
seller_reputationLevel_id := jResp.StringOf('seller_reputation.level_id');
seller_reputationPower_seller_status := jResp.StringOf('seller_reputation.power_seller_status');
seller_reputationTransactionsPeriod := jResp.StringOf('seller_reputation.transactions.period');
seller_reputationTransactionsTotal := jResp.IntOf('seller_reputation.transactions.total');
seller_reputationTransactionsCompleted := jResp.IntOf('seller_reputation.transactions.completed');
seller_reputationTransactionsCanceled := jResp.IntOf('seller_reputation.transactions.canceled');
seller_reputationTransactionsRatingsPositive := jResp.IntOf('seller_reputation.transactions.ratings.positive');
seller_reputationTransactionsRatingsNegative := jResp.IntOf('seller_reputation.transactions.ratings.negative');
seller_reputationTransactionsRatingsNeutral := jResp.IntOf('seller_reputation.transactions.ratings.neutral');
statusSite_status := jResp.StringOf('status.site_status');
i := 0;
count_i := jResp.SizeOfArray('tags');
while i < count_i do
begin
jResp.I := i;
strVal := jResp.StringOf('tags[i]');
i := i + 1;
end;
i := 0;
count_i := jResp.SizeOfArray('buyer_reputation.tags');
while i < count_i do
begin
jResp.I := i;
i := i + 1;
end;
http.Free;
jsonToken.Free;
sbResponseBody.Free;
jResp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.