Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data sample for JSON type provider with optional property

I am trying to use the JSON type provider to access StackOverflow / StackExchange data via the API. It works great, with one caveat. The API has a throttle, which is signaled by a field "backoff" that contains the number of seconds you are supposed to back off until your next request. As a result, I can't just point the JSON TP to the url, because by default the backoff field is not present. This is how the response typically looks:

  {
  "items": [
    {
      "has_synonyms": true,
      "user_id": 1144035,
      "is_moderator_only": false,
      "is_required": false,
      "count": 7054,
      "name": "sql"
    },
    {
      "has_synonyms": true,
      "user_id": 1144035,
      "is_moderator_only": false,
      "is_required": false,
      "count": 16,
      "name": "algorithm"
    }
  ],
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693
}

I assumed what I needed to do was to supply a sample which contains both an example without backoff (as above), and one along the lines of this:

  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693,
  "backoff": 10
}

... so that I get a Backoff Option. However, I am not sure how to structure / prepare the sample to that effect. Help would be much appreciated!

like image 311
Mathias Avatar asked Mar 11 '15 04:03

Mathias


1 Answers

JSON Type Provider has a property SampleIsList, set it to true.
There is a documentation section Parsing Twitter stream about it, JsonProvider please scroll down as there is no way to reference the section directly.

Your sample file should look like this

[{
  ...
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693
},{
  ...
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9693,
  "backoff": 10
}]
like image 154
Max Malook Avatar answered Oct 15 '22 18:10

Max Malook