I just wrote an app for Chrome extensions and received a request to make it cross-StackExchange compatible. If there's eventually going to be more sites than just the few listed and I don't really know what they'll be called other than by checking here every so often to see what is supported, how do I future-proof my app to work with every SE site? Or am I doomed to hardcode everything?
3 Answers
http://stackauth.com/1.0/sites will get you information about all the sites.
1 Comment
I wrote a Chrome extension myself (details here) that works against all of the Stack sites, and an approach that I found pretty useful was to maintain a simple javascript object that stores anything about the sites that I may need to access. Here's the snippet I'm currently using:
var siteDetails = [
{
siteName: "MetaStackOverflow",
siteUrlMatch: /.*meta.stackoverflow.com.*/,
iconUrl: "http://sstatic.net/mso/favicon.ico",
apiRoot: "http://api.meta.stackoverflow.com/0.8/"
},
{
siteName: "StackOverflow",
siteUrlMatch: /.*stackoverflow.com.*/,
iconUrl: "http://sstatic.net/so/favicon.ico",
apiRoot: "http://api.stackoverflow.com/0.8/"
},
{
siteName: "SuperUser",
siteUrlMatch: /.*superuser.com.*/,
iconUrl: "http://sstatic.net/su/favicon.ico",
apiRoot: "http://api.superuser.com/0.8/"
},
{
siteName: "ServerFault",
siteUrlMatch: /.*serverfault.com.*/,
iconUrl: "http://sstatic.net/sf/favicon.ico",
apiRoot: "http://api.serverfault.com/0.8/"
}
];
Extending this to include future StackExchange sites or even user submitted sites would be pretty trivial with a helper method.
I'm personally choosing which API I'm using by investigating the URL of the page the user is visiting, but if the user is selecting which sites to use or activate, including a simple boolean flag with the site structure would suffice.
2 Comments
I think it varies by application, and I'm not sure how you'd want to do it for yours, but for many it'd probably be sufficient to allow the user to add a site in the "stackoverflow.com" format, from which you can derive the API URL.