3

I want to make an application in which the used API will automatically be updated when a newer version is released. What is the procedure to check if a newer version is available or not?

How can I find what Stack Exchange site (stable or beta) is newly available?

3 Answers 3

2

For future reference: API Documentation and Help

To answer your question:

To discover sites that are available in the Stack Exchange network, monitor http://stackauth.com/1.0/sites (http://stackauth.com/1.0/help/method?method=sites)

{
  "api_sites": [
    {
      "name": "Stack Overflow",
      "logo_url": "http://sstatic.net/stackoverflow/img/logo.png",
      "api_endpoint": "http://api.stackoverflow.com",
      "site_url": "http://stackoverflow.com",
      "description": "Q&A for professional and enthusiast programmers",
      "icon_url": "http://sstatic.net/stackoverflow/img/apple-touch-icon.png",
      "state": "normal",
      "styling": {
        "link_color": "#0077CC",
        "tag_foreground_color": "#3E6D8E",
        "tag_background_color": "#E0EAF1"
      }
    },
    .....
  ]
}

the state field will describe the state of the site

  "state": {
    "description": "state of this site.",
    "values": "one of normal, closed_beta, open_beta, or linked_meta",
    "optional": false
  },

For versions you can monitor statistics[0].api_version.version using the api_endpoint field of the sites element.

http://api.stackoverflow.com/1.0/stats (http://api.stackoverflow.com/1.0/help/method?method=stats)

{
  "statistics": [
    {
      "total_questions": 867714,
      "total_unanswered": 146373,
      "total_accepted": 541467,
      "total_answers": 2293532,
      "total_comments": 3375907,
      "total_votes": 8065879,
      "total_badges": 854136,
      "total_users": 313693,
      "questions_per_minute": 1.19,
      "answers_per_minute": 2.21,
      "badges_per_minute": 1.03,
      "views_per_day": 476762.33,
      "api_version": {
        "version": "1.0",
        "revision": "2010.8.13.1"
      },
      "site": {
        "name": "Stack Overflow",
        "logo_url": "http://sstatic.net/stackoverflow/img/logo.png",
        "api_endpoint": "http://api.stackoverflow.com",
        "site_url": "http://stackoverflow.com",
        "description": "Q&A for professional and enthusiast programmers",
        "icon_url": "http://sstatic.net/stackoverflow/img/apple-touch-icon.png",
        "state": "normal",
        "styling": {
          "link_color": "#0077CC",
          "tag_foreground_color": "#3E6D8E",
          "tag_background_color": "#E0EAF1"
        }
      }
    }
  ]
}

On a practical note:

This has already been beaten to death. There have been many people who initially claimed that they wanted to dynamically respond to API version changes and emplaced common constant values in order to do this.

During a beta period where minor version numbers will increase and functionality is incrementally changed, this might be a viable strategy.

But for production applications, your client library is written to perform against a specific API version, which will be located at a specific url e.g. http://api.xxxx.com/x.x/

In order to access the API, you must specify this url, so the API version will not and cannot change.

So, the idea of 'dynamic updates' or 'self updates' is a red herring.

That is my 3 pesos.

1
  • poet: and what is the answer my second question? (help me to find what stack-exchange site (stable or beta) is newly available.) Commented Aug 16, 2010 at 10:10
2

C# / Soapi.CS


using Soapi.CS

//

[Test]
public void SiteMonitor()
{
    Context.Options.LazyLoadingEnabled(true);

    Context.Sites.ForEach(site=>
        Console.WriteLine("{0} {1} {2} {3}", 
        site.Statistics.ApiVersion.Version, // stats lazy loaded
        site.Statistics.ApiVersion.Revision, 
        site.State, 
        site.Name 
        /*, ad nauseum..*/));
}
//

Output:

LongRunning.SiteMonitor : Passed1.0 2010.8.13.1 Normal Stack Overflow
1.0 2010.8.13.1 Normal Server Fault
1.0 2010.8.13.1 Normal Super User
1.0 2010.8.13.1 Normal Meta Stack Overflow
1.0 2010.8.13.1 Open_Beta Web Apps
1.0 2010.8.13.1 Linked_Meta Web Apps Meta
1.0 2010.8.13.1 Open_Beta Gaming
1.0 2010.8.13.1 Linked_Meta Gaming Meta
1.0 2010.8.13.1 Open_Beta Webmasters
1.0 2010.8.13.1 Linked_Meta Webmasters Meta
1.0 2010.8.13.1 Open_Beta Cooking
1.0 2010.8.13.1 Linked_Meta Cooking Meta
1.0 2010.8.13.1 Open_Beta Game Developers
1.0 2010.8.13.1 Linked_Meta Game Developers Meta
1.0 2010.8.13.1 Open_Beta Electronic Gadgets
1.0 2010.8.13.1 Linked_Meta Electronic Gadgets Meta
1.0 2010.8.13.1 Open_Beta Photography
1.0 2010.8.13.1 Linked_Meta Photography Meta
1.0 2010.8.13.1 Open_Beta Statistical Analysis
1.0 2010.8.13.1 Linked_Meta Statistical Analysis Meta
1.0 2010.8.13.1 Open_Beta Mathematics
1.0 2010.8.13.1 Linked_Meta Mathematics Meta
1.0 2010.8.13.1 Open_Beta Home Improvement
1.0 2010.8.13.1 Linked_Meta Home Improvement Meta
1.0 2010.8.13.1 Linked_Meta Meta Super User
1.0 2010.8.13.1 Linked_Meta Meta Server Fault
1.0 2010.8.13.1 Open_Beta GIS
1.0 2010.8.13.1 Linked_Meta GIS Meta
1.0 2010.8.13.1 Open_Beta TeX - LaTeX
1.0 2010.8.13.1 Linked_Meta TeX - LaTeX Meta
1.0 2010.8.13.1 Open_Beta Ubuntu
1.0 2010.8.13.1 Linked_Meta Ubuntu Meta
1.0 2010.8.13.1 Closed_Beta Personal Finance and Money
1.0 2010.8.13.1 Linked_Meta Personal Finance and Money Meta
1.0 2010.8.13.1 Closed_Beta English Language and Usage
1.0 2010.8.13.1 Linked_Meta English Language and Usage Meta
1.0 2010.8.13.1 Normal Stack Apps

2

JavaSript / Soapi.JS (V2)


Using Soapi.JS (V2)

Yes, this is a teaser - v2 will be released before the weekend.


var apiKey = "my-foo-bar-fu-is-strong";
var ctx = new Soapi.ApiContext(apiKey);
ctx.initialize(function() {
    // All available sites have been loaded from stackauth
    // to track loading of stats.
    var counter = 0;

    // Now we load the .stats property of the Site object.

    for (var i = 0; i < ctx.sites.length; i++) {
        var site = ctx.sites[i];
        if (!site.stats) {
            counter++;
            site.get_stats(function(data, site_as_context) {
                // Keep the user informed
                document.getElementById("output")
                  .innerHTML = "loaded stats for "
                  + site_as_context.name;
                /* Is it */soupYet()/*?*/;
            },
            function(error, site_as_context) { // Site sent as userContext
                // Keep the user informed
                document.getElementById("output")
                  .innerHTML = "failed to loaded stats for "
                  + site_as_context.name;

                // The request failed but we must decrement the counter.
                /* Is it */soupYet()/*?*/;
            }, site /* As context */);
        };
    };

    // That's all the code it takes to get all sites from stackauth and
    // the statistics for each. More than half of it is exception handling
    // and progress updates.

    // The rest is the code to render the /sites and /stats data to HTML.
    function soupYet(/*?*/) {
        // Check to see if all sites have been loaded.
        if (--counter == 0) {
            // Dump all to table
            var output = "<table cellpadding='0' cellspacing='0' style='border:solid 1px silver;'> \
                <tr class='header'><td>Site</td><td>State</td><td>Tags</td><td>Logo</td><td>API</td> \
                <td>v.p.d</td><td>users</td><td>questions</td><td>q.p.m.</td><td>accepted</td> \
                <td>unanswered</td><td>answers</td><td>a.p.m</td><td>comments</td><td>votes</td> \
                <td>badges</td><td>b.p.m.</td></tr>";

            for (var i = 0; i < ctx.sites.length; i++) {
                var site = Soapi.Domain.Site(ctx.sites[i]);
                output += "<tr>"
                    + "<td><img src='" + site.icon_url + "' style='width:32px;height:32px;'/>"
                    + "<a href='" + site.site_url + "' style='color:" + site.styling.link_color
                    + ";' target='_blank' title='" + site.description.replace("'", "`") + "'>" + site.name + "</a></td>"
                    + "<td class='stats'>" + site.state + "</td>"
                    + "<td class='stats'><span style='color:" + site.styling.tag_foreground_color + ";background-color:"
                    + site.styling.tag_background_color + ";'>[tags]</span></td>"
                    + "<td class='stats'>&nbsp;<a href='" + site.logo_url + "' target='_blank'>logo</a></td>"
                    + "<td class='stats'>&nbsp;<a href='" + site.api_endpoint + "/" + site.stats.api_version.version
                    + "/help' target='_blank'>" + site.stats.api_version.version + " " + site.stats.api_version.revision + "</a></td>"
                    + "<td class='stats'>" + Math.ceil(site.stats.views_per_day) + "</td>"
                    + "<td class='stats'>" + site.stats.total_users + "</td>"
                    + "<td class='stats'>" + site.stats.total_questions + "</td>"
                    + "<td class='stats'>" + Math.ceil(site.stats.questions_per_minute) + "</td>"
                    + "<td class='stats'>" + site.stats.total_accepted + "</td>"
                    + "<td class='stats'>" + site.stats.total_unanswered + "</td>"
                    + "<td class='stats'>" + site.stats.total_answers + "</td>"
                    + "<td class='stats'>" + Math.ceil(site.stats.answers_per_minute) + "</td>"
                    + "<td class='stats'>" + site.stats.total_comments + "</td>"
                    + "<td class='stats'>" + site.stats.total_votes + "</td>"
                    + "<td class='stats'>" + site.stats.total_badges + "</td>"
                    + "<td class='stats'>" + Math.ceil(site.stats.badges_per_minute) + "</td>"
                    + "</tr>";
            };

            output += "</table>";
            document.getElementById("output").innerHTML = output;
        }
    };
}, function(error) {
    alert(error.message);
});

Output:

Alt text

You must log in to answer this question.

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