[feedburner_mgmtapi]

Description

Link: [feedburner_mgmtapi]
Author: Jason Huck
Category: Utility
Version: 8.x
License:
Posted: Jul. 21, 2006
Updated: Jan. 01, 0001
More by this author...
This custom type allows you to use the FeedBurner Management API to add, modify, delete, and sync feeds in your FeedBurner account via Lasso. Requires [xml_tree] and a valid FeedBurner account. The following methods are included:

->authcheck - Used internally, produces an error if the FeedBurner account username and password haven't been specified.

->parseerrors - Used internally, common method for parsing error responses from FeedBurner.

->wrapfeed - Used internally, prepares feed data for submission.

->find - Returns a list of all feeds in your account as an array. Each element is a map containing the feed's title, id, and uri.

->get - Accepts the id or uri of a feed and returns complete details as an XML object.

->add - Adds a new feed to your account. Requires at least the source of the feed to add. Can also accept a title, uri, and an array of FeedBurner services. See sample usage and the API documentation for details.

->modify - Similar to add. Accepts the id or uri of a feed and modifies it's details according to the options specified. See sample usage and the API documentation for details.

->delete - Accepts the id or uri of a feed and removes it from your account.

->resync - Resyncs the specified feed based on id or uri.

Parameters

none


Sample Usage

[//lasso	
	var('delay' = 2000);
	
	var('myFeeds') = feedburner_mgmtapi(
		-username='xxxxxxxxx',
		-password='xxxxxxxxx'
	);

	// AddFeed
	'<hr>Adding A Feed:<br>\n';
	$myFeeds->add(
		-uri='uniquefeedname',
		-title='A Test Feed',
		-source='http://www.somedomain.com/feed.xml',
		-services=array('ContentType' = map('contentType' = 'application/rss+xml'))
	);
	
	sleep($delay);


	// FindFeeds
	'<hr>Finding All Feeds:<br>\n';
	$myFeeds->find;	
	
	sleep($delay);


	// GetFeed
	'<hr>Getting Feed Details:<br>\n';
	'<pre>';
	encode_xml($myFeeds->get( -uri='uniquefeedname'));
	'</pre>';	
	
	sleep($delay);

	
	// ModifyFeed
	'<hr>Modifying A Feed:<br>\n';
	$myFeeds->modify(
		-uri='uniquefeedname',
		-title='A Test Feed Modified',
		-source='http://www.somedomain.com/feed.xml',
		-services=array('ConvertFormat' = map('toFormat' = 'rss2.0'))
	);
	
	sleep($delay);


	// ResyncFeed
	'<hr>Re-Syncing A Feed:<br>\n';
	$myFeeds->resync( -uri='uniquefeedname');
	
	sleep($delay);


	// DeleteFeed
	'<hr>Deleting A Feed:<br>\n';
	$myFeeds->delete( -uri='uniquefeedname');
]
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
define_type(
	'mgmtapi',
	-namespace='feedburner_',
	-description='Implements the FeedBurner Management API in Lasso.'
);
	local(
		'username' = string,
		'password' = string,
		'url' = 'http://api.feedburner.com/management/1.0/'
	);



	define_tag(
		'onCreate',
		-opt='username',
		-opt='password'
	);
		local_defined('username') ? self->username = #username;
		local_defined('password') ? self->password = #password;
	/define_tag;


	
	define_tag('authcheck');
		fail_if(
			(: self->username, self->password) >> '',
			-1,
			'Username and/or password not set.'
		);
	/define_tag;



	define_tag('parseerrors', -req='response');
		local(
			'out' = array,
			'atts' = array('code', 'msg'),
			'errors' = #response->err
		);
		
		!#errors->isa('array') ? #errors = array(#errors);
		
		iterate(#errors, local('error'));
			local('tmp' = map);
			
			iterate(#atts, local('att'));
				#tmp->insert(#att = #error->getattribute(#att));
			/iterate;
			
			#out->insert(#tmp);
		/iterate;
		
		return(#out);	
	/define_tag;



	define_tag(
		'wrapfeed',
		-opt='id',
		-opt='uri',
		-opt='title',
		-req='source',
		-opt='services',
		-type='array'
	);
		local('out') = xml_tree('<feed />');
		
		iterate((: 'id', 'uri', 'title'), local('i'));
			local_defined(#i) && local(#i) != null ? 
				#out->addattribute(#i = local(#i));
		/iterate;
		
		#out->newchild('source');
		#out->source->addattribute('url' = #source);
		
		if(local_defined('services'));
			#out->newchild('services');
		
			iterate(#services, local('i'));
				local('s') = xml('<service />');
				#s->addattribute('class' = #i->first);
				
				iterate(#i->second->keys, local('j'));
					local('p') = xml('<param />');
					#p->addattribute('name' = #j);
					#p->addcontent(encode_xml(#i->second->find(#j)));
					
					#s->addchild(#p);
				/iterate;
				
				#out->services->addchild(#s);
			/iterate;
		/if;
		
		return(@xml(#out));
	/define_tag;
	
		
			
	define_tag('find');
		self->authcheck;
	
		local('response') = xml_tree(
			include_url(
				self->url + 'FindFeeds',
				-getparams=array(
					'user' = self->username, 
					'password' = self->password
				)
			)
		);
		
		if(#response->getattribute('stat') == 'ok');
			local(
				'out' = array,
				'atts' = array('id', 'uri', 'title'),
				'feeds' = #response->feeds->feed
			);
			
			!#feeds->isa('array') ? #feeds = array(#feeds);
			
			iterate(#feeds, local('feed'));
				local('tmp' = map);
				
				iterate(#atts, local('att'));
					#tmp->insert(#att = #feed->getattribute(#att));
				/iterate;
				
				#out->insert(#tmp);
			/iterate;
			
			return(#out);
			
		else(#response->getattribute('stat') == 'fail');
			return(self->parseerrors(#response));
		
		else;
			return('There was a problem completing the requested action: ' + err_msg);
		/if;
	/define_tag;


	
	define_tag(
		'get',
		-opt='id',
		-opt='uri'
	);
		self->authcheck;

		local('getparams') = array(
			'user' = self->username, 
			'password' = self->password
		);
		
		local_defined('id') ? #getparams->insert('id' = #id);
		local_defined('uri') ? #getparams->insert('uri' = #uri);

		local('response') = xml_tree(
			include_url(
				self->url + 'GetFeed',
				-getparams=#getparams
			)
		);
		
		if(#response->getattribute('stat') == 'ok');
			return(@#response->feed);
			
		else(#response->getattribute('stat') == 'fail');
			return(self->parseerrors(#response));
		
		else;
			return('There was a problem completing the requested action: ' + err_msg);
		/if;			
	/define_tag;


	
	define_tag(
		'add',
		-opt='uri',
		-opt='title',
		-req='source',
		-opt='services',
		-type='array'
	);
		self->authcheck;
		
		local('feed') = @self->wrapfeed(
			-uri=(local_defined('uri') ? #uri | null),
			-title=(local_defined('title') ? #title | null),
			-source=#source,
			-services=(local_defined('services') ? #services | array)
		);
		
		local('response') = xml_tree(
			include_url(
				self->url + 'AddFeed',
				-postparams=array(
					'user' = self->username, 
					'password' = self->password,
					'feed' = #feed
				)
			)
		);
		
		if(#response->getattribute('stat') == 'ok');
			local(
				'out' = map,
				'atts' = array('id', 'uri', 'title')
			);
								
			iterate(#atts, local('att'));
				#out->insert(#att = #feed->getattribute(#att));
			/iterate;
			
			return(#out);
			
		else(#response->getattribute('stat') == 'fail');
			return(self->parseerrors(#response));
		
		else;
			return('There was a problem completing the requested action: ' + err_msg);
		/if;			
	/define_tag;



	define_tag(
		'modify',
		-opt='id',
		-opt='uri',
		-opt='title',
		-req='source',
		-opt='services',
		-type='array'
	);
		self->authcheck;
		
		local('feed') = @self->wrapfeed(
			-id=(local_defined('id') ? #id | null),
			-uri=(local_defined('uri') ? #uri | null),
			-title=(local_defined('title') ? #title | null),
			-source=#source,
			-services=(local_defined('services') ? #services | array)
		);
		
		local('response') = xml_tree(
			include_url(
				self->url + 'ModifyFeed',
				-postparams=array(
					'user' = self->username, 
					'password' = self->password,
					'feed' = #feed
				)
			)
		);
		
		if(#response->getattribute('stat') == 'ok');
			local(
				'out' = map,
				'atts' = array('id', 'uri', 'title')
			);
								
			iterate(#atts, local('att'));
				#out->insert(#att = #feed->getattribute(#att));
			/iterate;
			
			return(#out);
			
		else(#response->getattribute('stat') == 'fail');
			return(self->parseerrors(#response));
		
		else;
			return('There was a problem completing the requested action: ' + err_msg);
		/if;				
	/define_tag;



	define_tag(
		'delete',
		-opt='id',
		-opt='uri'
	);
		self->authcheck;

		local('postparams') = array(
			'user' = self->username, 
			'password' = self->password
		);
		
		local_defined('id') ? #postparams->insert('id' = #id);
		local_defined('uri') ? #postparams->insert('uri' = #uri);

		local('response') = include_url(
			self->url + 'DeleteFeed',
			-postparams=#postparams
		);
		
		if(#response == '');
			return('The feed was deleted successfully.');
			
		else;
			#response = xml_tree(#response);
			
			if(#response->getattribute('stat') == 'fail');
				return(self->parseerrors(#response));
			else;
				return('There was a problem completing the requested action: ' + err_msg);
			/if;
		/if;		
	/define_tag;



	define_tag(
		'resync',
		-opt='id',
		-opt='uri'
	);
		self->authcheck;
		
		local('postparams') = array(
			'user' = self->username, 
			'password' = self->password
		);
		
		local_defined('id') ? #postparams->insert('id' = #id);
		local_defined('uri') ? #postparams->insert('uri' = #uri);

		local('response') = include_url(
			self->url + 'ResyncFeed',
			-postparams=#postparams
		);
						
		if(#response == '');
			return('Resync successful.');
			
		else;
			#response = xml_tree(#response);
			
			if(#response->getattribute('stat') == 'fail');
				return(self->parseerrors(#response));
			else;
				return('There was a problem completing the requested action: ' + err_msg);
			/if;
		/if;			
	/define_tag;
/define_type;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular