Lasso Soft Inc. > Home

[feedburner_mgmtapi]

Linkfeedburner_mgmtapi
AuthorJason Huck
CategoryUtility
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted21 Jul 2006
Updated21 Jul 2006
More by this author...

Description

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.

Sample Usage

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

	// AddFeed
	'
Adding A Feed:
\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 '
Finding All Feeds:
\n'; $myFeeds->find; sleep($delay); // GetFeed '
Getting Feed Details:
\n'; '
';
	encode_xml($myFeeds->get( -uri='uniquefeedname'));
	'
'; sleep($delay); // ModifyFeed '
Modifying A Feed:
\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 '
Re-Syncing A Feed:
\n'; $myFeeds->resync( -uri='uniquefeedname'); sleep($delay); // DeleteFeed '
Deleting A Feed:
\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.

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('');
		
		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('');
				#s->addattribute('class' = #i->first);
				
				iterate(#i->second->keys, local('j'));
					local('p') = xml('');
					#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

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft