Skip to main content
Is Improved edit bug fixed?
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

Soapi.js defines Route 'classes' for each and every route, or urlURL, in the StackOverflowStack Overflow API.

A Route is primarily a 'class' off of which to hang the urlURL path and define the parameters for the urlURL. Specifying required 'id' parameters in the factory method call and the application of parameters via explicitly defined parameter objects or jsonJSON literals will be covered later in this post.

  • success (required) - function(data) - data will be a JavaScript object (jsob) built from the response jsonJSON as defined on the route's help-page.
  • error (optional) - function(err) - err will be a jsob shaped like this: { code: number , message: "String", urlURL: "String"}
  • timeout (optional) - number - The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.
  • success (required) - function(data) - data will be a JavaScript object (jsob) built from the response jsonJSON as defined on the route's help-page.
  • error (optional) - function(err) - err will be a jsob shaped like this: { code: number , message: "String", urlURL: "String"}
  • pageCallback (optional) - function(data) - data will be a JavaScript object (jsob) built from the response jsonJSON as defined on the route's help-page. You may examine this object to determine if you would like to terminate the paged request. Simply return true if you wish to terminate and receive the current aggregated results in your success function.
  • timeout (optional) - number - The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.

resulting in a urlURL resembling the following (urlURL-encoded, of course):

The other parameters of the route may be supplied as an object literal in the factory method, as shown, explicitly set on the Route object itself or appiedapplied via the Route.applyParameters function with an object literal.

asyncTest("AnswersByIdSanityCheck", function() {
    expect(1);
    var factory = Soapi.RouteFactory('api.stackoverflow.com', apiKey);
    var route = factory.AnswersById(2917525, 2701766, {
        //id is set in factory method call
        // these are default values that do not result in a 
        // parameter being added to the urlURL
        body: false,
        comments: false,
        sort: "",
        order: "",
        min: 0,
        max: 0,
        fromdate: 0,
        todate: 0,
        page: 0,
        pagesize: 0
    });
    

    
    route.getResponse(
      function (data) {
          ok(data.items.length==2, 'async call succeeded, count inaccurate');
          start();
      }, 
      function(err) {
          ok(err.message);
          start();
      }, 5000);

Next: Complete Route Listing - suprisinglysurprisingly simple mastery of the API via Soapi.js lies here

Soapi.js defines Route 'classes' for each and every route, or url, in the StackOverflow API.

A Route is primarily a 'class' off of which to hang the url path and define the parameters for the url. Specifying required 'id' parameters in the factory method call and the application of parameters via explicitly defined parameter objects or json literals will be covered later in this post.

  • success (required) - function(data) - data will be a JavaScript object (jsob) built from the response json as defined on the route's help-page.
  • error (optional) - function(err) - err will be a jsob shaped like this: { code: number , message: "String", url: "String"}
  • timeout (optional) - number - The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.
  • success (required) - function(data) - data will be a JavaScript object (jsob) built from the response json as defined on the route's help-page.
  • error (optional) - function(err) - err will be a jsob shaped like this: { code: number , message: "String", url: "String"}
  • pageCallback (optional) - function(data) - data will be a JavaScript object (jsob) built from the response json as defined on the route's help-page. You may examine this object to determine if you would like to terminate the paged request. Simply return true if you wish to terminate and receive the current aggregated results in your success function.
  • timeout (optional) - number - The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.

resulting in a url resembling the following (url-encoded, of course):

The other parameters of the route may be supplied as an object literal in the factory method, as shown, explicitly set on the Route object itself or appied via the Route.applyParameters function with an object literal.

asyncTest("AnswersByIdSanityCheck", function() {
    expect(1);
    var factory = Soapi.RouteFactory('api.stackoverflow.com', apiKey);
    var route = factory.AnswersById(2917525, 2701766, {
        //id is set in factory method call
        // these are default values that do not result in a 
        // parameter being added to the url
        body: false,
        comments: false,
        sort: "",
        order: "",
        min: 0,
        max: 0,
        fromdate: 0,
        todate: 0,
        page: 0,
        pagesize: 0
    });
    

    
    route.getResponse(
      function (data) {
          ok(data.items.length==2, 'async call succeeded, count inaccurate');
          start();
      }, 
      function(err) {
          ok(err.message);
          start();
      }, 5000);

Next: Complete Route Listing - suprisingly simple mastery of the API via Soapi.js lies here

Soapi.js defines Route 'classes' for each and every route, or URL, in the Stack Overflow API.

A Route is primarily a 'class' off of which to hang the URL path and define the parameters for the URL. Specifying required 'id' parameters in the factory method call and the application of parameters via explicitly defined parameter objects or JSON literals will be covered later in this post.

  • success (required) - function(data) - data will be a JavaScript object (jsob) built from the response JSON as defined on the route's help-page.
  • error (optional) - function(err) - err will be a jsob shaped like this: { code: number , message: "String", URL: "String"}
  • timeout (optional) - number - The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.
  • success (required) - function(data) - data will be a JavaScript object (jsob) built from the response JSON as defined on the route's help-page.
  • error (optional) - function(err) - err will be a jsob shaped like this: { code: number , message: "String", URL: "String"}
  • pageCallback (optional) - function(data) - data will be a JavaScript object (jsob) built from the response JSON as defined on the route's help-page. You may examine this object to determine if you would like to terminate the paged request. Simply return true if you wish to terminate and receive the current aggregated results in your success function.
  • timeout (optional) - number - The default timeout value is 10,000, or 10 seconds. If this is not acceptable, simply provide a timeout value in ms.

resulting in a URL resembling the following (URL-encoded, of course):

The other parameters of the route may be supplied as an object literal in the factory method, as shown, explicitly set on the Route object itself or applied via the Route.applyParameters function with an object literal.

asyncTest("AnswersByIdSanityCheck", function() {
    expect(1);
    var factory = Soapi.RouteFactory('api.stackoverflow.com', apiKey);
    var route = factory.AnswersById(2917525, 2701766, {
        //id is set in factory method call
        // these are default values that do not result in a 
        // parameter being added to the URL
        body: false,
        comments: false,
        sort: "",
        order: "",
        min: 0,
        max: 0,
        fromdate: 0,
        todate: 0,
        page: 0,
        pagesize: 0
    });
    

    
    route.getResponse(
      function (data) {
          ok(data.items.length==2, 'async call succeeded, count inaccurate');
          start();
      }, 
      function(err) {
          ok(err.message);
          start();
      }, 5000);

Next: Complete Route Listing - surprisingly simple mastery of the API via Soapi.js lies here

broken image fixed (click 'rendered output' to see the difference; images retrieved via Wayback Machine); for more info, see https://gist.github.com/Glorfindel83/9d954d34385d2ac2597bbe864466259f
Source Link
replaced http://stackapps.com/ with https://stackapps.com/
Source Link

Next: Complete Route ListingComplete Route Listing - suprisingly simple mastery of the API via Soapi.js lies here

Next: Complete Route Listing - suprisingly simple mastery of the API via Soapi.js lies here

Next: Complete Route Listing - suprisingly simple mastery of the API via Soapi.js lies here

updated code samples
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
added 166 characters in body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
added 1438 characters in body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading