Link | |
Author | Jason Huck |
Category | Utility |
Version | 8.5.x |
License | Public Domain |
Posted | 04 Jan 2008 |
Updated | 03 Jan 2011 |
More by this author... |
This custom type provides an interface to the Twitter API from Lasso. It requires Fletcher Sandbeck's JSON library for Lasso and the [string_truncate] tag here. In addition to the usage examples below, consult the official documentation for a complete list of supported methods. A few method names were changed slightly to avoid duplicate member tag names. For example, there are several "show" methods, which I renamed to be more specific, such as ->show_user and ->show_status. A couple methods required special formatting for dates, so a [date_toHTTP] tag is included in this download.
// create a new instance of the twitter type var('t') = twitter( -username='xxxxxxxxx', -password='xxxxxxxxx' ); // get the first item from the public timeline $t->public_timeline->first; // get a slice of your friends timeline $t->friends_timeline( -since=date->subtract( -hour=2)&); // get 4 items from the user timeline $t->user_timeline( -count=4); // show a specific status message $t->show_status(xxxxxxxxx); // update your twitter status $t->update('This Tweet Powered By Lasso.'); // get all replies $t->replies; // get a list of your friends $t->friends; // get a list of your followers (the -lite option does not appear to work) $t->followers( -lite=true); // DEPRECATED: get the current featured twitterers // $t->featured; // view all of your direct messages $t->direct_messages; // view all of your sent direct messages $t->sent; // send a new direct message to a specific user $t->new( -user='xxxxxxxxx', -text='Sent from Lasso. Let me know if you get this.');
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.
// Twitter API for Lasso // (c)2007 - 2011 Jason Huck/Core Five Creative // Thanks to Lieven Gekiere, Brian Loomis, and Rich Fortnum for contributions. // requires: JSON library, string_truncate, date_toHTTP (below) define_tag( 'toHTTP', -namespace='date_', -req='in', -type='date', -priority='replace', -encodenone, -description='HTTP-formats the given date.' ); local('out') = null; !#in->gmt ? #in = date_localtogmt(#in); #in->setformat('%Q %T'); #out = encode_url(string(#in))->replace('%20','+')&; return(#out); /define_tag; define_type( 'twitter', -description='Implements the Twitter API in Lasso.' ); local( 'username' = string, 'password' = string, 'version' = 1 ); define_tag( 'oncreate', -opt='username', -type='string', -opt='password', -type='string', -opt='version' ); local_defined('username') ? self->username = #username; local_defined('password') ? self->password = #password; local_defined('version') ? self->version = #version; /define_tag; define_tag('authcheck'); return(self->username != '' && self->password != ''); /define_tag; define_tag( 'retrieve', -req='path', -type='string', -opt='post', -type='array', -encodenone ); fail_if(!self->authcheck, -1, 'Username or password not set.'); protect; local('response') = string( local_defined('post') ? include_url( 'http://api.supertweet.net/' + self->version + #path, -username=self->username, -password=self->password, -postparams=#post, -timeout=15 ) | include_url( 'http://api.supertweet.net/' + self->version + #path, -username=self->username, -password=self->password, -timeout=15 ) ); handle_error; local('response') = 'There was a problem communicating with Twitter.'; /handle_error; /protect; return(decode_json(#response)); /define_tag; define_tag( 'public_timeline', -opt='since_id', -type='integer', -encodenone ); local('path') = '/statuses/public_timeline.json' + (local_defined('since_id') ? '?since_id=' + #since_id); return(self->retrieve(#path)); /define_tag; define_tag( 'friends_timeline', -opt='id', -opt='since', -type='date', -opt='page', -type='integer', -encodenone ); local('path') = '/statuses/friends_timeline' + (local_defined('id') ? '/' + #id) + '.json'; local_defined('since') || local_defined('page') ? #path += '?'; local_defined('since') ? #path += 'since=' + date_toHTTP(#since); local_defined('page') ? #path += (!#path->endswith('?') ? '&') + 'page=' + #page; return(self->retrieve(#path)); /define_tag; define_tag( 'user_timeline', -opt='id', -opt='count', -type='integer', -opt='since', -type='date', -encodenone ); local('path') = '/statuses/user_timeline' + (local_defined('id') ? '/' + #id) + '.json'; local_defined('count') || local_defined('since') ? #path += '?'; local_defined('count') ? #path += 'count=' + #count; local_defined('since') ? #path += (!#path->endswith('?') ? '&') + 'since=' + date_toHTTP(#since); return(self->retrieve(#path)); /define_tag; define_tag( 'show_status', -req='id', -type='integer', -encodenone ); local('path') = '/statuses/show/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'update', -req='status', -type='string', -encodenone ); local('path') = '/statuses/update.json'; local('post') = array('status' = string_truncate(#status, 160)); return(self->retrieve(#path, #post)); /define_tag; define_tag( 'replies', -opt='page', -type='integer', -encodenone ); local('path') = '/statuses/replies.json'; local_defined('page') ? #path += '?page=' + #page; return(self->retrieve(#path)); /define_tag; define_tag( 'destroy_status', -req='id', -type='integer', -encodenone ); local('path') = '/statuses/destroy/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'friends', -opt='id', -encodenone ); local('path') = '/statuses/friends' + (local_defined('id') ? '/' + #id) + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'followers', -opt='id', -opt='page', -type='integer', -encodenone ); local('path') = '/statuses/followers'; #path += (local_defined('id') ? '/' + #id) + '.json'; local_defined('page') && #page ? #path += '?page=' + #page; return(self->retrieve(#path)); /define_tag; /* deprecated? define_tag('featured'); local('path') = '/statuses/featured.json'; return(self->retrieve(#path)); /define_tag; */ define_tag( // not working 'show_user', -opt='id', -opt='email', -type='string', -encodenone ); local_defined('id') ? local('path') = '/users/show/' + #id + '.json'; local_defined('email') ? local('path') = '/users/show.json?email=' + #email; return(self->retrieve(#path)); /define_tag; define_tag( 'direct_messages', -opt='since', -type='date', -opt='since_id', -type='integer', -opt='page', -type='integer', -encodenone ); local('path') = '/direct_messages.json'; params->size ? #path += '?'; local_defined('since') ? #path += 'since=' + date_toHTTP(#since) + '&'; local_defined('since_id') ? #path += 'since_id=' + #since_id + '&'; local_defined('page') ? #path += 'page=' + #page; #path->removetrailing('&'); return(self->retrieve(#path)); /define_tag; define_tag( 'sent_direct', -opt='since', -type='date', -opt='since_id', -type='integer', -opt='page', -type='integer', -encodenone ); local('path') = '/direct_messages/sent.json'; params->size ? #path += '?'; local_defined('since') ? #path += 'since=' + date_toHTTP(#since) + '&'; local_defined('since_id') ? #path += 'since_id=' + #since_id + '&'; local_defined('page') ? #path += 'page=' + #page; #path->removetrailing('&'); return(self->retrieve(#path)); /define_tag; define_tag( 'new_direct', -req='user', -req='text', -type='string', -encodenone ); local('path') = '/direct_messages/new.json'; local('post') = array( 'user' = #user, 'text' = string_truncate(#text, -length=140) ); return(self->retrieve(#path, #post)); /define_tag; define_tag( 'destroy_direct', -req='id', -type='integer', -encodenone ); local('path') = '/direct_messages/destroy/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'create_friendship', -req='id', -encodenone ); local('path') = '/friendships/create/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'destroy_friendship', -req='id', -encodenone ); local('path') = '/friendships/destroy/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'exists_friendship', -req='user_a', -req='user_b', -encodenone ); local('path') = '/friendships/exists.json?user_a='; #path += encode_url(#user_a) + '&user_b=' + encode_url(#user_b); return(self->retrieve(#path)); /define_tag; define_tag( 'ids_friends', -opt='id', -encodenone ); local('path') = '/friends/ids'; local_defined('id') ? #path += '/' + encode_url(#id); #path += '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'ids_followers', -opt='id', -encodenone ); local('path') = '/followers/ids'; local_defined('id') ? #path += '/' + encode_url(#id); #path += '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'verify_credentials', -encodenone ); local('path') = '/account/verify_credentials.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'end_session', -encodenone ); local('path') = '/account/end_session'; return(self->retrieve(#path)); /define_tag; define_tag( 'update_location', -req='location', -type='string', -encodenone ); local('path') = '/account/update_location.json'; local('post') = array('location' = string_truncate(#location, 100)); return(self->retrieve(#path, #post)); /define_tag; define_tag( 'update_delivery_device', -req='device', -type='string', -encodenone ); fail_if((: 'sms', 'im', 'none') !>> #device, -1, 'Not an allowed device.'); local('path') = '/account/update_delivery_device.json?device=' + #device; return(self->retrieve(#path)); /define_tag; define_tag( 'update_profile_colors', -opt='profile_background_color', -opt='profile_text_color', -opt='profile_link_color', -opt='profile_sidebar_fill_color', -opt='profile_sidebar_border_color', -encodenone ); fail_if(!params->size, -1, 'At least one color must be specified.'); local('path') = '/account/update_profile_colors.json'; local('post') = array; iterate(params, local('i')); #post->insert(string(#i->first)->removeleading('-')& = #i->second); /iterate; return(self->retrieve(#path, #post)); /define_tag; /* Not currently implemented: update_profile_image, update_profile_background_image */ define_tag( 'rate_limit_status', -encodenone ); local('path') = '/account/rate_limit_status.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'update_profile', -opt='name', -opt='email', -opt='url', -opt='location', -opt='description', -encodenone ); fail_if(!params->size, -1, 'At least one parameter must be provided.'); local('path') = '/account/update_profile.json'; local('post') = array; iterate(params, local('i')); #post->insert(string(#i->first)->removeleading('-')& = #i->second); /iterate; return(self->retrieve(#path, #post)); /define_tag; /* deprecated? define_tag( 'archive', -opt='page', -type='integer', -encodenone ); local('path') = '/account/archive.json'; local_defined('page') ? #path += '?page=' + #page; return(self->retrieve(#path)); /define_tag; */ define_tag( 'favorites', -opt='id', -opt='page', -type='integer', -encodenone ); local('path') = '/favorites' + (local_defined('id') ? '/' + #id) + '.json'; local_defined('page') ? #path += '?page=' + #page; return(self->retrieve(#path)); /define_tag; define_tag( 'create_favorite', -req='id', -type='integer', -encodenone ); local('path') = '/favorites/create/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'destroy_favorite', -req='id', -type='integer', -encodenone ); local('path') = '/favorites/destroy/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'follow_notification', -req='id', -encodenone ); local('path') = '/notifications/follow/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'leave_notification', -req='id', -encodenone ); local('path') = '/notifications/leave/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'create_block', -req='id', -encodenone ); local('path') = '/blocks/create/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag( 'destroy_block', -req='id', -encodenone ); local('path') = '/blocks/destroy/' + #id + '.json'; return(self->retrieve(#path)); /define_tag; define_tag('test'); local('path') = '/help/test.json'; return(self->retrieve(#path)); /define_tag; /define_type;
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
t.co wrapping?