Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
New method forrstUserInfo() added and documentation updated according…
Browse files Browse the repository at this point in the history
…ly. Minified version also updated
  • Loading branch information
jackfranklin committed Aug 25, 2010
1 parent 7d8844f commit b1f41d8
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ PLEASE PLEASE PLEASE use the minified version for live sites.

If you want to fork this please do and make your edits. Also, let me hear about it! I'd love to see what you're all up to !


$.forrstPosts():

Options:
//The values of each variable are the defaults
username: 'kyle', //your forrst username [REQUIRED]
Expand Down Expand Up @@ -107,3 +110,50 @@ comment_count [INT] //number of comments the item has received
url_with_wbr [STR] //post URL with <wbr /> inserted to prevent wrapping on long URLs
user_id [INT] //id of user who posted it
views [INT] //number of views the post has recieved


---------

$.forrstUserInfo()

Function: You pass this function either a username or an id, and it will find the ID or Username from what you pass.

Options:
username: 'kyle', //forrst username (use if you want to find an ID)
userId: null, //forrst id (use if you want to find a username)
apiVersion: 'v1', //forrst api version
debugMode: false, //debug mode helps you out if you're stuck
cantFetchInfo: 'We had an issue getting in touch with Forrst',
//error if you cant fetch the data
invalidData: 'The data you passed in was incorrect',
//error if the data you passed is wrong
callback: function() {} //function to handle the data

Examples:

Fetching a username from ID:

$.forrstUserInfo({
'username':null,
'userId':8620,
callback: function(data, success) {
if(success)
{
console.log(data);
//data is the username
}
}
})

Fetching a user id:
$.forrstUserInfo({
'username':'jackfranklin',
'userId':null,
callback: function(data, success) {
if(success)
{
console.log(data);
//data is the ID
}
}
})
11 changes: 11 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
})
*/

$.forrstUserInfo({
'username':'jackfranklin',
'userId':null,
callback: function(data, success) {
if(success)
{
console.log(data);
}
}
})

</script>
<!-- Date: 2010-08-25 -->
</head>
Expand Down
63 changes: 63 additions & 0 deletions jquery.forrstposts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,68 @@ jQuery.extend({
}

})
},
forrstUserInfo: function(options) {
var defaults = {
username: 'kyle',
userId: null,
apiVersion: 'v1',
debugMode: false,
cantFetchInfo: 'We had an issue getting in touch with Forrst',
invalidData: 'The data you passed in was incorrect',
callback: function() {}
}
var options = $.extend({}, defaults, options);
var script = 'http://api.forrst.com/api/' + options.apiVersion + '/users/info?',
dataReturned, getId,success;

if(options.username === null)
{
getId = false;
script += 'id=' + options.userId;
} else {
getId = true;
script += 'username=' + options.username;
}

$.ajax({
url: script,
type: 'GET',
dataType: 'jsonp',
success: function(d) {

if(getId)
{

dataReturned = d.resp.user.id;
} else {
dataReturned = d.resp.user.username;
}
success = true;

},
error:function(req,status,error) {
if(options.debugMode)
{
dataReturned = new Array(req, status, error);
} else {
dataReturned = options.cantFetchInfo;
}
success = false;

},
complete: function()
{

if(dataReturned === null)
{
dataReturned = options.invalidData;
success = false;
}

options.callback(dataReturned, success);

}
})
}
})
10 changes: 10 additions & 0 deletions jquery.forrstposts.v1.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ success=true;},error:function(req,status,error){if(options.debugMode)
success=false;},complete:function()
{if(dataReturned.length<1)
{dataReturned=options.fetchedError;success=false;}
options.callback(dataReturned,success);}})},forrstUserInfo:function(options){var defaults={username:'kyle',userId:null,apiVersion:'v1',debugMode:false,cantFetchInfo:'We had an issue getting in touch with Forrst',invalidData:'The data you passed in was incorrect',callback:function(){}}
var options=$.extend({},defaults,options);var script='http://api.forrst.com/api/'+options.apiVersion+'/users/info?',dataReturned,getId,success;if(options.username===null)
{getId=false;script+='id='+options.userId;}else{getId=true;script+='username='+options.username;}
$.ajax({url:script,type:'GET',dataType:'jsonp',success:function(d){if(getId)
{dataReturned=d.resp.user.id;}else{dataReturned=d.resp.user.username;}
success=true;},error:function(req,status,error){if(options.debugMode)
{dataReturned=new Array(req,status,error);}else{dataReturned=options.cantFetchInfo;}
success=false;},complete:function()
{if(dataReturned===null)
{dataReturned=options.invalidData;success=false;}
options.callback(dataReturned,success);}})}})

0 comments on commit b1f41d8

Please sign in to comment.