program TwitchPrimer;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, TwitchAPI;

const
  TWITCH_CLIENTID = 'nfr3jymo9yp2behz2n3p188pzmfxxm';
  TWITCH_TOKEN = 'ay9pph405baqsrdpovhozhyabq4ie6';

procedure GetChannelInfo;
begin
  var LTwitch := TTwitch.Create(TWITCH_CLIENTID, TWITCH_TOKEN);
  try
    var LResult := LTwitch.GetChannelInfo()
      .SetBroadcasterID('537542262')
      .Execute;
    Writeln(LResult.Infos[0].Title);
  finally
    LTwitch.Free;
  end;
end;

procedure GetUsers;
begin
  var LTwitch := TTwitch.Create(TWITCH_CLIENTID, TWITCH_TOKEN);
  try
    var LResult := LTwitch.GetUsers()
      .SetLogin('CompilaQuindiVa')
      .Execute;
    Write('ID: ');
    Writeln(LResult.Users[0].ID);
    Writeln;
    Writeln('Description:');
    Writeln(LResult.Users[0].Description);
  finally
    LTwitch.Free;
  end;
end;

procedure GetExtensionAnalytics;
begin
  var LTwitch := TTwitch.Create(TWITCH_CLIENTID, TWITCH_TOKEN);
  try
    var LResult := LTwitch.GetExtensionAnalytics()
      .Execute;
    Writeln(LResult.Count);
    if LResult.Count <= 0 then
      Exit;
    Writeln(Format('%s - %s', [
      LResult.Data[0].ExtensionID,
      LResult.Data[0].URL
    ]));
  finally
    LTwitch.Free;
  end;
end;

begin
  ReportMemoryLeaksOnShutdown := True;
  try
    GetChannelInfo();
    GetUsers();
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
