-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommon_FF.pas
More file actions
131 lines (112 loc) · 3.53 KB
/
common_FF.pas
File metadata and controls
131 lines (112 loc) · 3.53 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
122
123
124
125
126
127
128
129
130
131
unit common_FF;
interface
uses Classes, SysUtils, Forms, Dialogs,SHDocVw, NativeXML,uLkJSON,
httpsend,synacode,TypInfo;
const
ff_ConsumerKey = '07c551b86f1944c89123bac5c2544c94';
ff_ConsumerSecret = 'de8ff7da283649a294f252b9ae3569591f82110bfd584c94822e4c10ddea8952';
ProgName = 'LinkCompressor';
CallbackURL = 'http://www.webdelphi.ru';
FFURL = 'http://%s:%s@friendfeed-api.com/v%d/%s';
ffAPIVer=2;
GroupName='linkcompressor';
ffRemoteKeyURL='http://friendfeed.com/remotekey';
ffGroupURL='http://friendfeed.com/linkcompressor';
type
TffOperations = (ff_subscribe,ff_entry);
type
TFriendFeed = class
private
FAuthorized: boolean;
FRemoteKey: string;
FLogin: string;
FAppID: string;
FAPIVersion: integer;
procedure SetAuthorized(const Value: boolean);
procedure SetLogin(const Value: string);
procedure SetRemoteKey(const Value: string);
procedure SetAppID(const Value: string);
procedure SetAPIVersion(const Value: integer);
function POSTCommand(const Operation:TffOperations;Params:TStrings):string;
published
public
constructor Create();
function Subscribe(const ListID: string):boolean;
function Entry(const aMsg:string; aTo: string):boolean;
property APIVersion:integer read FAPIVersion write SetAPIVersion;
property AppID: string read FAppID write SetAppID;
property Authorized: boolean read FAuthorized write SetAuthorized;
property Login: string read FLogin write SetLogin;
property RemoteKey : string read FRemoteKey write SetRemoteKey;
end;
var FriendFeed: TFriendFeed;
implementation
{ TFriendFeed }
constructor TFriendFeed.Create;
begin
inherited Create;
FAppID:=ff_ConsumerKey;
FAPIVersion:=ffAPIVer;
end;
function TFriendFeed.Entry(const aMsg: string; aTo: string): boolean;
var Params: TStringList;
Res:string;
begin
Params:=TStringList.Create;
Params.Add('body='+aMsg+'&to='+aTo);
Res:=POSTCommand(ff_entry,Params);
Result:=(pos('errorCode',Res)<=0)and(Length(Res)>0);
end;
function TFriendFeed.POSTCommand(const Operation:TffOperations; Params: TStrings): string;
var URL: string;
Oper: string;
i:integer;
begin
Result:='';
if Params<>nil then
if Params.Count>0 then
begin
Oper:=GetEnumName(TypeInfo(TffOperations),ord(Operation));
Delete(Oper,1,3);
URL:=Format(FFURL,[FLogin,FRemoteKey,FAPIVersion,Oper])+'?';
for I := 0 to Params.Count-1 do
URL:=URL+Params[i]+'&';
Delete(URL,length(URL),1);
url := EncodeURL(AnsiToUtf8(URL));
with THTTPSend.Create do
begin
Params.SaveToStream(Document);
HTTPMethod('POST', url);
Params.LoadFromStream(Document);
Result:=Params.Text;
end;
end;
end;
procedure TFriendFeed.SetAPIVersion(const Value: integer);
begin
FAPIVersion := Value;
end;
procedure TFriendFeed.SetAppID(const Value: string);
begin
FAppID := Value;
end;
procedure TFriendFeed.SetAuthorized(const Value: boolean);
begin
FAuthorized := Value;
end;
procedure TFriendFeed.SetLogin(const Value: string);
begin
FLogin := Value;
end;
procedure TFriendFeed.SetRemoteKey(const Value: string);
begin
FRemoteKey := Value;
end;
function TFriendFeed.Subscribe(const ListID: string): boolean;
var Params: TStringList;
begin
Params:=TStringList.Create;
Params.Add('feed='+ListID+'&appid='+AppID);
Result:=pos('subscribed',POSTCommand(ff_subscribe,Params))>0
end;
end.