7

Stack Users Lite

About

Stack Users Lite is a simple single page JavaScript application that searches all Stack Exchange sites for users by partial or complete username and allows you to view the associated accounts for a particular user.

Stack Users Lite was written using only SOAPI.JS, an intuitive JavaScript wrapper library for the Stack Overflow API.

No jQuery scripts were harmed in the making of Stack Users Lite.

License

You may use Stack Users Lite under the terms of either the MIT License or the GNU General Public License (GPL) Version 2.

See http://soapi.info/code/js/license.aspx for more information.

Download

Stack Users Lite can be viewed online here.

The complete source code can be found in the SOAPI.JS download.

Platform

Stack Users Lite has been tested on all modern major browsers. Reports of platform related issues are welcome.

Contact

You can contact the author, me, Sky Sanders (code poet) through my gmail account: sky.sanders

Code

Stack Users Lite was developed as a reference example for Soapi.js to illustrate usage of the StackAuth.com /sites and /users/{id}/associated methods.

View the source of the app to see how painless API usage in JavaScript can be!

6
  • You're not the first to use the 'soapi.js' tag. Eventually, I'll get the taxonomist badge :) Commented Jul 1, 2010 at 3:09
  • 1
    I gave it a go... works flawlessly on Opera Mini. Might want to add it to StackList :) Commented Jul 1, 2010 at 3:11
  • @geo - i will be flooding stacklist as soon as I get all of my rc refactoring, documentation and packaging complete. this was just one of my usage examples that ended up actually being useful. Give me a couple days to get all my *** in one sock. Commented Jul 1, 2010 at 4:03
  • @George, only 47 apps to go before you get that badge ;) Commented Jul 1, 2010 at 5:41
  • 1
    +1 for an impressive and actually quite useful showcase for the simplicity and power of SOAPI.JS! Commented Jul 1, 2010 at 9:14
  • i lol'd @ "no jQuery scripts were harmed in the making of Stack Users Lite". Awesome app though. Commented Jul 5, 2010 at 18:00

1 Answer 1

3

Under the hood

The code required to produce the pretty output, for what it does, is fairly brief but it does distract from the core functions that do all the heavy lifting.

Stack Users Lite is built upon 3 API calls

  • /sites (Route.ApiSites)
  • /users (Route.Users)
  • /users/{id}/associated (Route.UsersByIdAssociated)

Route.ApiSites

Route.ApiSites is a StackAuth route that retrieves the current list of Stack Exchange sites from http://stackauth.com/0.9/sites.

Soapi.RouteFactory("", apiKey)
    .ApiSites()
    .getResponse(function(data) {
        // initialize the application
    }, function(error) {
        // die
    });

You may notice that there is no target site specified in the RouteFactory constructor. This is because the stackauth methods are static and unlike the other routes in Soapi.js, the target is hardcoded. This means that you may either instantiate a factory with no target site specifically for retrieving target sites or you may simply use any instantiated factory instance regardless of the target site specified in the construction.

The same principal applies to Route.UsersByIdAssociated.

Route.Users

Route.Users is called for each of the sites previously retrieved from http://stackauth.com/0.9/sites using the criteria provided in the single input element.

The number of results retrieved and shown is limited by setting the pagesize property of the Route before requesting a response.

Each of these results is aggregated into a common array and then rendered to the page.

var route = Soapi.RouteFactory(site.api_endpoint, apiKey).Users();
route.filter = username;
route.pagesize = 50
route.page = 1;

var count = sites.length // so we know when all sites have returned results

route.getResponse(function(data) {
    // aggregate the users
    users = users.concat(data.items); // aggregate the results from this site
    if (--count == 0) {
        // all sites reported in. display the results
    }
}, function(error) {
    count--; // still need to pop the count
    // report error
});

Route.UsersByIdAssociated

When a username is clicked in the results list, Route.UsersByIdAssociated calls http://stackauth.com/0.9//users/a1c71168-ffb9-42a5-8d71-ce38ad8f2c79/associated to retrieve a list of all the users accounts throughout the Stack Exchange network and displays those in the details view.

Soapi.RouteFactory("", apiKey)
    .UsersByIdAssociated(association_id)
    .getResponse(function(data) {
        for (var i = 0; i < data.items.length; i++) {
            // render the account info
        }
    }, function(error) {
        // log error
    }, 1000);
// set a very short timeout of 1 second
// because there are many users without
// association id and the app has not
// the logic yet to simply not render a link
// and we want a failure to come swiftly

Conclusion

So there you have it. Examined in isolation from the GUI goo, this simple application seems even more simple.

Simple is good (rt).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .