Lasso Soft Inc. > Home

[delicious]

Linkdelicious
AuthorJason Huck
CategoryUtility
Version8.5.x
LicensePublic Domain
Posted02 Aug 2007
Updated18 Sep 2007
More by this author...

Description

This custom type allows you to interact with del.icio.us, the social bookmarking site, programmatically. Search, add, edit, and delete posts, tags, and bundles. See the API documentation and the sample usage below for implementation specifics. Requires [xml_tree].

Sample Usage

// Create a new delicious object.
var('d') = delicious(
	-username='xxxxxxxxx',
	-password='xxxxxxxxx'
);

// Retrieve the date/time the given account
// was last updated.
$d->lastupdate;

// Retrieve a list of all tags associated
// with the account. This will return an 
// array of pairs where the key is the tag
// name and the value is the number of times
// the tag has been used. The results are 
// also stored within the object and are
// accessible via ->'tags'.
$d->gettags;

// Rename a tag.
$d->renametag('LDML','Lasso');

// Retrieve all the posts for the given tag
// or tags (space separated) on the given date.
// Returns an array of maps. Each map contains 
// the URL, title, description, unique ID, tags,
// date/time added, and how many other users have
// posted the same item. The results are also
// stored in within the object and are accessible
// via ->'posts'.
$d->getposts( -tag='api', -date=date('2007-06-20'));

// Get the most recent posts (up to 100, user-
// configurable) for the give tag(s).
$d->recentposts( -tag='api');

// Get all posts for the given tag(s). If no
// tags are given, returns ALL posts for the
// given account.
$d->allposts('api');

// Returns a list of dates with the number of 
// posts at each date.
$d->getdates('api');

// Adds a new post to the account.
$d->addpost(
	-url='http://tagSwap.net/',
	-description='tagSwap.net',
	-extended='A public exchange for Lasso custom tags.',
	-tags='lasso webdev programming customtags'
);

// Deletes the post specified by the URL.
$d->deletepost('http://www.blueworld.com/');

// Gets a list of all bundles associated with the account.
// Returns an array of pairs where the key is the bundle
// name and the value is an array of tags included in the
// given bundle.
$d->getbundles;

// Creates or updates the given bundle with the given tags.
// Overwrites any previously existing bundle by the same name.
$d->setbundle( 
    -bundle='searchengineoptimization', 
    -tags='analytics google keywords pagerank SEO statistics stats urchin'
);

// Deletes the specified bundle.
$d->deletebundle('searchengineoptimization');

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(
	'delicious',
	-prototype,
	-description='Implements the del.icio.us API v1.'
);
	// http://del.icio.us/help/api/
	// dependencies: xml_tree

	local(
		'username' = string,
		'password' = string,
		'tags' = array,
		'posts' = array,
		'dates' = treemap,
		'bundles' = array
	);

	
	define_tag(
		'oncreate',
		-req='username',
		-req='password'
	);
		self->username = #username;
		self->password = #password;
	/define_tag;

	
	define_tag(
		'send',
		-req='object',
		-req='method',
		-opt='args'
	);
		!local_defined('args') ? local('args') = array;
		local('resp') = string;
		
		protect;
			#resp = xml_tree(
				string(
					include_url(
						('https://api.del.icio.us/v1/' + #object + '/' + #method),
						-username=self->username,
						-password=self->password,
						-getparams=#args,
						-timeout=10
					)
				)
			);
		/protect;
		
		return(@#resp);
	/define_tag;

	
	define_tag('lastupdate');			
		protect;
			local('resp') = @self->send('posts','update');
			local('out') = date_gmttolocal(date(#resp->time, -format='%QT%TZ', -gmt));
			return(#out);
		/protect;
	/define_tag;
	

	define_tag('gettags');
		protect;
			local('resp') = @self->send('tags','get');
			local('tags') = #resp->tag;
			!#tags->isa('array') ? #tags = array(#tags);
			
			// clear any previously populated tags
			self->tags = array;
			
			iterate(#tags, local('i'));
				self->tags->insert(#i->tag = integer(#i->count));
			/iterate;				
		/protect;

		return(@self->tags);
	/define_tag;	
	
	
	define_tag(
		'renametag',
		-req='old',
		-req='new'
	);
		protect;
			local('resp') = @self->send('tags','rename',array('old'=#old,'new'=#new));
			return(#resp->contents == 'done');
		/protect;
	/define_tag;
	
	
	define_tag(
		'getposts',
		-opt='tag',
		-opt='date', -type='date',
		-opt='url'
	);
		protect;
			local('args') = array;
			local_defined('tag') ? #args->insert('tag' = #tag);
			local_defined('date') ? #args->insert('dt' = date_localtogmt(#date)->format('%QT%TZ'));
			local_defined('url') ? #args->insert('url' = #url);

			local('resp') = @self->send('posts','get',#args);
			local('posts') = #resp->post;
			!#posts->isa('array') ? #posts = array(#posts);
			
			// empty any previously inserted posts
			self->posts = array;
			
			iterate(#posts, local('i'));
				self->posts->insert(#i->atts);
			/iterate;				
		/protect;

		return(@self->posts);
	/define_tag;
	
	
	define_tag(
		'recentposts',
		-opt='tag',
		-opt='count', -type='integer'
	);
		protect;
			local('args') = array;
			local_defined('tag') ? #args->insert('tag' = #tag);
			local_defined('count') ? #args->insert('count' = #count);

			local('resp') = @self->send('posts','recent',#args);
			local('posts') = #resp->post;
			!#posts->isa('array') ? #posts = array(#posts);

			// empty any previously inserted posts
			self->posts = array;
			
			iterate(#posts, local('i'));
				self->posts->insert(#i->atts);
			/iterate;				
		/protect;

		return(@self->posts);
	/define_tag;


	define_tag(
		'allposts',
		-opt='tag'
	);
		protect;
			local('args') = array;
			local_defined('tag') ? #args->insert('tag' = #tag);

			local('resp') = @self->send('posts','all',#args);
			local('posts') = #resp->post;
			!#posts->isa('array') ? #posts = array(#posts);

			// empty any previously inserted posts
			self->posts = array;
			
			iterate(#posts, local('i'));
				self->posts->insert(#i->atts);
			/iterate;
		/protect;

		return(@self->posts);
	/define_tag;
	
	
	define_tag(
		'getdates',
		-opt='tag'
	);
		protect;
			local('args') = array;
			local_defined('tag') ? #args->insert('tag' = #tag);

			local('resp') = @self->send('posts','dates',#args);
			local('dates') = #resp->date;
			!#dates->isa('array') ? #dates = array(#dates);
			
			// clear any previously populated dates
			self->dates = treemap;
			
			iterate(#dates, local('i'));
				self->dates->insert(date_gmttolocal(date(#i->date, -format='%Q', -gmt)) = integer(#i->count));
			/iterate;				
		/protect;

		return(@self->dates);
	/define_tag;
	
	
	define_tag(
		'addpost',
		-req='url',
		-req='description',
		-opt='extended',
		-opt='tags',
		-opt='date', -type='date',
		-opt='replace', -type='boolean',
		-opt='shared', -type='boolean'
	);
		!local_defined('replace') ? local('replace') = true;
		!local_defined('shared') ? local('shared') = true;
	
		local('args') = array(
			'url' = #url,
			'description' = #description
		);
		
		local_defined('extended') ? #args->insert('extended' = #extended);
		local_defined('tags') ? #args->insert('tags' = #tags);
		local_defined('date') ? #args->insert('dt' = date_localtogmt(#date)->format('%QT%TZ'));
		!#replace ? #args->insert('replace' = 'no');
		!#shared ? #args->insert('shared' = 'no');
		
		protect;
			local('resp') = @self->send('posts','add',#args);
			return(#resp->code == 'done');
		/protect;
	/define_tag;
	
	
	define_tag(
		'deletepost',
		-req='url'
	);
		protect;
			local('resp') = @self->send('posts','delete',array('url'=#url));
			return(#resp->code == 'done');
		/protect;
	/define_tag;
	
	
	define_tag('getbundles');
		protect;
			local('resp') = @self->send('tags/bundles','all');				
			local('bundles') = #resp->bundle;
			!#bundles->isa('array') ? #bundles = array(#bundles);
			
			// clear any previously populated bundles
			self->bundles = array;
			
			iterate(#bundles, local('i'));
				self->bundles->insert(string(#i->attribute('name')) = string(#i->tags)->split(' '));
			/iterate;				
		/protect;

		return(@self->bundles);
	/define_tag;
	
	
	define_tag(
		'setbundle',
		-req='bundle',
		-req='tags'
	);
		protect;
			local('resp') = @self->send('tags/bundles','set',array('bundle'=#bundle,'tags'=#tags));
			return(#resp->contents == 'ok');
		/protect;
	/define_tag;
	
	
	define_tag(
		'deletebundle',
		-req='bundle'
	);
		protect;
			local('resp') = @self->send('tags/bundles','delete',array('bundle'=#bundle));
			return(#resp->contents == 'ok');
		/protect;
	/define_tag;
/define_type;

Related Tags

Comments

18 Sep 2007, Jason Huck

Bug Fix

Fixed a double-encoding bug.

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