-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFMX.TMS.myCloudDataRestClient.pas
More file actions
121 lines (105 loc) · 3.56 KB
/
FMX.TMS.myCloudDataRestClient.pas
File metadata and controls
121 lines (105 loc) · 3.56 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
{ *************************************************************************** }
{ TMS FMX myCloudData RESTClient }
{ for Delphi & C++Builder }
{ }
{ written by TMS Software }
{ copyright © 2016 }
{ Email : info@tmssoftware.com }
{ Web : http://www.tmssoftware.com }
{ }
{ The source code is given as is. The author is not responsible }
{ for any possible damage done due to the use of this code. }
{ The component can be freely used in any application. The complete }
{ source code remains property of the author and may not be distributed, }
{ published, given or sold in any form as such. No parts of the source }
{ code can be included in any other component or application without }
{ written authorization of the author. }
{ *************************************************************************** }
unit FMX.TMS.myCloudDataRestClient;
interface
uses
REST.TMS.myCloudDataRestClient, IndyPeerImpl,
REST.TMS.myCloudDataRestClient.Data,
REST.Authenticator.OAuth.WebForm.FMX, System.UITypes, FMX.Graphics;
type
TFMXmyCloudDataRESTClient = class(TmyCloudDataRESTClient)
private
procedure OnWebformClosed(Sender: TObject; var Action: TCloseAction);
public
procedure Authenticate; override;
end;
MyCloudDataBlobClassHelper = class helper for TmyCloudDataBlob
public
function TryGetAsBitmap(out ABitmap: TBitmap): Boolean;
end;
implementation
uses
REST.Utils, System.Classes, System.SysUtils;
{$IFDEF IOS}
{$DEFINE TMSRESTMOBILE}
{$ENDIF}
{$IFDEF ANDROID}
{$DEFINE TMSRESTMOBILE}
{$ENDIF}
{ TFMXmyCloudDataRESTClient }
procedure TFMXmyCloudDataRESTClient.Authenticate;
var
LWebForm: Tfrm_OAuthWebForm;
begin
if (ClientID.Trim = '') OR (ClientSecret.Trim = '') then
begin
raise Exception.Create('Please make sure to set your application KEY and SECRET that you can obtain by registering at http://myclouddata.net');
end;
LWebForm := Tfrm_OAuthWebForm.Create(Owner);
{$IFDEF TMSRESTMOBILE}
LWebForm.OnBeforeRedirect := OAuth2_AuthTokenRedirect;
{$ELSE}
LWebForm.OnAfterRedirect := OAuth2_AuthTokenRedirect;
{$ENDIF}
LWebForm.Caption := 'myCloudData login';
LWebForm.OnClose := OnWebformClosed;
LWebForm.ShowWithURL(GetLoginUrl);
end;
procedure TFMXmyCloudDataRESTClient.OnWebformClosed(Sender: TObject; var Action: TCloseAction);
var
LWebForm: Tfrm_OAuthWebForm;
begin
LWebForm := Sender AS Tfrm_OAuthWebForm;
if LWebForm <> nil then
begin
{$IFDEF TMSRESTMOBILE}
LWebForm.OnBeforeRedirect := nil;
{$ELSE}
LWebForm.OnAfterRedirect := nil;
{$ENDIF}
LWebForm.Release;
end;
end;
{ MyCloudDataBlobClassHelper }
function MyCloudDataBlobClassHelper.TryGetAsBitmap(out ABitmap: TBitmap): Boolean;
var
LStream: TStream;
LBitmap: TBitmap;
begin
LStream := GetStream;
try
LBitmap := TBitmap.Create;
try
Result := True;
LBitmap.LoadFromStream(LStream);
ABitmap := LBitmap;
Exit;
except
on E: Exception do
begin
LBitmap.Free;
Result := False;
Exit;
end;
end;
Result := False;
finally
LStream.Free;
end;
end;
end.