-
Notifications
You must be signed in to change notification settings - Fork 0
/
Webservice.pas
109 lines (95 loc) · 3.47 KB
/
Webservice.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
unit Webservice;
interface
uses
Webservice.Interfaces,
Webservice.Response,
Webservice.Request,
System.Net.HttpClient,
System.Net.URLClient,
System.Classes,
System.JSON,
System.SysUtils,
System.Generics.Collections;
type
TWebservice = class(TInterfacedObject, IWebservice)
private
FBaseURI: string;
FToken: string;
public
procedure SetBaseURI(const ABaseURI: string);
procedure SetToken(const AToken: string);
function Get(const AParams: array of string;
AQueryParams: TDictionary<string, string> = nil): IWebserviceResponse;
function Put(const AParams: array of string; AData: TJSONValue = nil;
AQueryParams: TDictionary<string, string> = nil;
ADataOwner: boolean = true): IWebserviceResponse;
function Post(const AParams: array of string; AData: TJSONValue = nil;
AQueryParams: TDictionary<string, string> = nil;
ADataOwner: boolean = true): IWebserviceResponse;
function Patch(const AParams: array of string; AData: TJSONValue = nil;
AQueryParams: TDictionary<string, string> = nil;
ADataOwner: boolean = true): IWebserviceResponse;
function Delete(const AParams: array of string;
AQueryParams: TDictionary<string, string> = nil): IWebserviceResponse;
property BaseURI: string read FBaseURI write SetBaseURI;
property Token: string read FToken write SetToken;
end;
implementation
{ TWebservice }
procedure TWebservice.SetBaseURI(const ABaseURI: string);
begin
FBaseURI := ABaseURI;
end;
procedure TWebservice.SetToken(const AToken: string);
begin
FToken := AToken;
end;
function TWebservice.Get(const AParams: array of string;
AQueryParams: TDictionary<string, string> = nil): IWebserviceResponse;
var
ARequest: IWebserviceRequest;
begin
ARequest := TWebserviceRequest.Create(BaseURI, Token);
Result := ARequest.SendData(AParams, TWebserviceCommand.fcGet, nil,
AQueryParams);
end;
function TWebservice.Post(const AParams: array of string;
AData: TJSONValue = nil; AQueryParams: TDictionary<string, string> = nil;
ADataOwner: boolean = true): IWebserviceResponse;
var
ARequest: IWebserviceRequest;
begin
ARequest := TWebserviceRequest.Create(BaseURI, Token);
Result := ARequest.SendData(AParams, TWebserviceCommand.fcPost, AData,
AQueryParams, ADataOwner);
end;
function TWebservice.Put(const AParams: array of string;
AData: TJSONValue = nil; AQueryParams: TDictionary<string, string> = nil;
ADataOwner: boolean = true): IWebserviceResponse;
var
ARequest: IWebserviceRequest;
begin
ARequest := TWebserviceRequest.Create(BaseURI, Token);
Result := ARequest.SendData(AParams, TWebserviceCommand.fcPut, AData,
AQueryParams, ADataOwner);
end;
function TWebservice.Patch(const AParams: array of string;
AData: TJSONValue = nil; AQueryParams: TDictionary<string, string> = nil;
ADataOwner: boolean = true): IWebserviceResponse;
var
ARequest: IWebserviceRequest;
begin
ARequest := TWebserviceRequest.Create(BaseURI, Token);
Result := ARequest.SendData(AParams, TWebserviceCommand.fcPatch, AData,
AQueryParams, ADataOwner);
end;
function TWebservice.Delete(const AParams: array of string;
AQueryParams: TDictionary<string, string> = nil): IWebserviceResponse;
var
ARequest: IWebserviceRequest;
begin
ARequest := TWebserviceRequest.Create(BaseURI, Token);
Result := ARequest.SendData(AParams, TWebserviceCommand.fcRemove, nil,
AQueryParams);
end;
end.