stackconnect

Ruby API for making StackOverflow queries. This is a limited number of the API calls that can be made to the StackOverflow API, and these are all quota limited. So the response you get is not the full amount of data available, just the most popular/highest ranked data based on activity and date.

Installation

In your Gemfile, add this line:

gem 'stackconnect'

And then execute:

$ bundle 

Or install it yourself as:

$ gem install stackconnect

Usage

These methods are quota restricted. The Stack Exchange API only allows a quota of 10000 without an API key: http://api.stackexchange.com/docs/authentication. Once you get over that quota without a key, your IP address will be throttled from making any more requests until the next day.

Retrieve Total Number of Questions

 sc = StackConnect.new
 total = sc.retrieve_total_questions(from_date)

This will return an number.

From date has to be in Unix date format. So for example, to retrieve the total number of questions from yesterday,

 date = Date.today.to_time.to_i
 total = sc.retrieve_total_questions(from_date)

data = sc.retrieve_most_popular_tags

This will return a JSON data object which you can then parse. An example:

data["items"].each do |trend|
   puts trend["name"]
end

The data looks like this:

{
  "items": [
    {
      "has_synonyms": false,
      "is_moderator_only": false,
      "is_required": false,
      "count": 127787,
      "name": "c"
    },
    {
      "has_synonyms": true,
      "is_moderator_only": false,
      "is_required": false,
      "count": 268773,
      "name": "python"
    },
    {
      "has_synonyms": true,
      "is_moderator_only": false,
      "is_required": false,
      "count": 18729,
      "name": "variables"
    },
  ],
  "has_more": true,
  "backoff": 10,
  "quota_max": 10000,
  "quota_remaining": 9973
}

These are sorted based on activity.

data = StackConnect.retrieve_day_popular_tags(from_date)

Sample Data:

{
  "items": [
    {
      "has_synonyms": false,
      "is_moderator_only": false,
      "is_required": false,
      "count": 1,
      "name": "microsoft-net-http"
    },
    {
      "has_synonyms": false,
      "is_moderator_only": false,
      "is_required": false,
      "count": 1,
      "name": "owin-middleware"
    },
    {
      "has_synonyms": false,
      "is_moderator_only": false,
      "is_required": false,
      "count": 1,
      "name": "mlt"
    },
  ],
  "has_more": true,
  "quota_max": 10000,
  "quota_remaining": 9972
}

Contributing

  1. Fork it ( http://github.com/[my-github-username]/stack-connect/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request