function GetAuthenticator : THTTPBasicAuthenticator;
begin
Result := THTTPBasicAuthenticator.Create(TConfig.Username, TConfig.Password);
end;
function GetIssuesForUser(
const AUserName :
string) : TIssueList;
var
LIssue : TIssue;
RESTClient : TRESTClient;
RESTRequest : TRESTRequest;
JSONValue : TJsonValue;
JSONObject : TJSONObject;
JSONArr : TJSONArray;
i : Integer;
begin
Result := TIssueList.Create;
RESTClient := TRESTClient.Create(TConfig.BaseURL);
RESTClient.Authenticator := GetAuthenticator;
{$IFDEF FIDDLER}
// Zum Test mit Fiddler
RESTClient.ProxyPort := 8888;
RESTClient.ProxyServer := '
127.0.0.1';
{$ENDIF}
RESTRequest := TRESTRequest.Create(RESTClient);
RESTRequest.Method := TRESTRequestMethod.rmGET;
RESTRequest.Resource := '
search?jql=assignee={username}+'+
'
AND+status+in+("'+TConfig.Filter+'
")'+
'
&fields=key,summary,status';
try
RESTRequest.Params.AddItem('
username', AUserName, TRESTRequestParameterKind.pkURLSEGMENT);
RESTRequest.Execute;
if RESTRequest.Response.StatusCode = 200
then
begin
// JSON zerpflücken
JSONValue := RESTRequest.Response.JSONValue;
if JSONValue
is TJSONObject
then
begin
JSONArr := TJSONArray(TJSONObject(JSONValue).GetValue('
issues'));
for i := 0
to JSONArr.Size -1
do
begin
LIssue := TIssue.Create;
Result.Add(LIssue);
JSONObject := TJSONObject(JSONArr.Get(i));
GetIssueData(JSONObject, LIssue);
end;
end;
end;
except
On E:
Exception do
begin
LIssue := TIssue.Create;
LIssue.Key := E.
Message;
Result.Add(LIssue);
end;
end;
RESTRequest.Free;
RESTClient.Authenticator.Free;
RESTClient.Free;
end;