-
Notifications
You must be signed in to change notification settings - Fork 90
/
Grijjy.Social.pas
132 lines (110 loc) · 2.42 KB
/
Grijjy.Social.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
unit Grijjy.Social;
{ Cross social network types and classes }
{ Note: This unit should only used by clients as it will embed social libraries and SDKs }
{$I Grijjy.inc}
interface
uses
System.Messaging,
{$IFDEF TWTR}
Grijjy.TWTR,
{$ENDIF}
Grijjy.FBSDK;
type
TgoSocialNetwork = (None, Facebook, Twitter);
type
TgoSocialLogin = record
public
Result: Boolean;
Network: TgoSocialNetwork;
Id: String;
AccessToken: String;
public
procedure Initialize;
end;
TgoSocialLoginMessage = class(TMessage<TgoSocialLogin>)
public
constructor Create(const ASocialLogin: TgoSocialLogin);
end;
type
TgoSocial = class
class var FFacebook: TgoFacebook;
{$IFDEF TWTR}
class var FTwitter: TTwitter;
{$ENDIF}
public
class function Facebook: TgoFacebook; static;
{$IFDEF TWTR}
class function Twitter: TgoTwitter; static;
{$ENDIF}
public
procedure Login(const ANetwork: TgoSocialNetwork);
procedure GetSelf(const ANetwork: TgoSocialNetwork);
public
constructor Create;
destructor Destroy; override;
end;
implementation
{ TgoSocialLogin }
procedure TgoSocialLogin.Initialize;
begin
Result := False;
Network := TgoSocialNetwork.None;
Id := '';
AccessToken := '';
end;
{ TgoSocialLoginMessage }
constructor TgoSocialLoginMessage.Create(const ASocialLogin: TgoSocialLogin);
begin
inherited Create(ASocialLogin);
end;
{ TgoSocial }
constructor TgoSocial.Create;
begin
{$IFDEF TWTR}
FTwitter := nil;
{$ENDIF}
FFacebook := nil;
end;
destructor TgoSocial.Destroy;
begin
{$IFDEF TWTR}
if FTwitter <> nil then
FTwitter.Free;
{$ENDIF}
if FFacebook <> nil then
FFacebook.Free;
inherited;
end;
{$IFDEF TWTR}
class function TgoSocial.Twitter: TgoTwitter;
begin
if FTwitter = nil then
FTwitter := TgoTwitter.Create;
Result := FTwitter;
end;
{$ENDIF}
class function TgoSocial.Facebook: TgoFacebook;
begin
if FFacebook = nil then
FFacebook := TgoFacebook.Create;
Result := FFacebook;
end;
procedure TgoSocial.Login(const ANetwork: TgoSocialNetwork);
begin
case ANetwork of
TgoSocialNetwork.Facebook: Facebook.Login;
{$IFDEF TWTR}
TgoSocialNetwork.Twitter: Twitter.Login;
{$ENDIF}
end;
end;
procedure TgoSocial.GetSelf(const ANetwork: TgoSocialNetwork);
begin
case ANetwork of
TgoSocialNetwork.Facebook: Facebook.GetSelf;
{$IFDEF TWTR}
TgoSocialNetwork.Twitter: Twitter.GetSelf;
{$ENDIF}
end;
end;
end.