[delicious]

Description

Link: [delicious]
Author: Jason Huck
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Aug. 02, 2007
Updated: Sep. 18, 2007
More by this author...
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].

Parameters

none


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.
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
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

09/18/2007, Jason Huck
Bug Fix
Fixed a double-encoding bug.
Email:


Password:



Newest

Most Popular

Support tagSwap.net