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)
Retrieve Most Popular Tags of All Time
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
}
Retrieving the Most Popular Tags of the Day
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
- Fork it ( http://github.com/[my-github-username]/stack-connect/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request