stackconnect 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bd43f38b8f408dd657b8045fd25f77f91bfbe60
4
- data.tar.gz: 7e318ac6b8d9e6ee2bda70cba17a2f61bd4f0a40
3
+ metadata.gz: 2de51d7518dfcd0b45c0ef3ed60f279fff9097aa
4
+ data.tar.gz: 8726a8cc6d90d9ebc4b9d4883c89d98cde070bcc
5
5
  SHA512:
6
- metadata.gz: fcedc0c7268ed8cf41cfe1e356d24bcb0d7f56931c96ca8f0f073e4949ae002123b13f1b3b0390de3b62f66d8cdf786f78c63748ad53b6482a7cd2d68a0e5d9f
7
- data.tar.gz: 2db8dce20edf4fa8bd873d9c4ab2f0db56de9fd83ffcb919b7fd873a64ae8384483f1bec8a7969563336d790b894598b2c648abed61ecb16ecb2160dbeb9fb78
6
+ metadata.gz: e17c4d2d92d6009cb48ce02392081ebe0c36ff059cb9c57a3782b5b724920b684f157f35d2b04bf84ad40943fda131cf58f0d59999fd71ff91f1073a6baf4ebb
7
+ data.tar.gz: 3ae270f51d823113f757569d5725649a5de0bfb1baa11b9369cfa8ea2db1866ce2a005a703fd6636d73db248f6049c6916c690ac61f0df4aff8fe487326e35c2
data/.README.md.swo ADDED
Binary file
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.swo
1
2
  *.gem
2
3
  *.swp
3
4
  *.rbc
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # stackconnect
2
2
 
3
- 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.
3
+ Ruby API for making StackOverflow queries. This is a limited number of the API calls that can be made to the StackOverflow API, mainly dealing with tags, questions, and users.
4
+
5
+ ## Software Versions
6
+
7
+ This has been tested and written for Rails 4.0 and above, and Ruby 2.0.0 and above.
4
8
 
5
9
  ## Installation
6
10
 
@@ -16,9 +20,15 @@ Or install it yourself as:
16
20
 
17
21
  $ gem install stackconnect
18
22
 
23
+ If you want the most current version of the gem, in your Gemfile, add this:
24
+
25
+ gem 'stackconnect', :git => 'git://github.com/stackgems/stackconnect.git'
26
+
19
27
  ## Usage
20
28
 
21
- 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.
29
+ These methods are quota restricted. The Stack Exchange API only allows a quota of 10,000 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.
30
+
31
+ If you get an API key, your limit will still be 10,000 (per application), with a limit of 5 applications.
22
32
 
23
33
  ### Retrieve Total Number of Questions
24
34
  ```
@@ -26,9 +36,9 @@ These methods are quota restricted. The Stack Exchange API only allows a quota o
26
36
  total = sc.retrieve_total_questions(from_date)
27
37
  ```
28
38
 
29
- This will return an number.
39
+ This will return a Ruby Fixnum.
30
40
 
31
- From date has to be in Unix date format. So for example, to retrieve the total number of questions from yesterday,
41
+ `fromdate` has to be in Unix date format. So for example, to retrieve the total number of questions from yesterday:
32
42
 
33
43
  ```
34
44
  date = Date.today.to_time.to_i
@@ -37,6 +47,8 @@ From date has to be in Unix date format. So for example, to retrieve the total n
37
47
 
38
48
  ### Retrieve Most Popular Tags of All Time
39
49
 
50
+ The default sort is `popular`, and the order is `desc` in order to list the most popular tags first.
51
+
40
52
  `data = sc.retrieve_most_popular_tags`
41
53
 
42
54
  This will return a JSON data object which you can then parse. An example:
@@ -80,11 +92,19 @@ The data looks like this:
80
92
  }
81
93
  ```
82
94
 
83
- ### Retrieving the Most Popular Tags of the Day
95
+ ### Retrieving the Most Popular Tags from a Particular Date
84
96
 
85
- These are sorted based on activity.
97
+ The way StackOverflow handles date ranges for tags is not what you would expect: the count returned with each tag is actually the all-time count for that tag, not the count of the tag for that particular day, or date range. If you want to get the total number of tags for a particular day, you would have to parse the `/questions` API call return data, and iterate through all the questions for that day.
86
98
 
87
- `data = StackConnect.retrieve_day_popular_tags(from_date)`
99
+ When you give a date range for the `/tags` call, the `'todate'` parameter is ignored, and will give the same response if it wasn't included at all. However, querying StackOverflow with a `'fromdate'` and sorting on `'popular'` will return the most popular tags for that particular time. Therefore, given the way the data is returned, `retrieve_tags(from_date)` already sorts on popular by default, otherwise, the data isn't very meaningful.
100
+
101
+ The date range is also restricted to be after January 1st, 2009. If a date before this time is given inside the query, an exception will be thrown.
102
+
103
+ If the API call is given any other sort type, such as `'popular'` or `'name'`, and the fromdate is before January 1st, 2009, StackOverflow will return the most popular tags of all time. If the sort type is `'activity'`, no data will be returned.
104
+
105
+ The order is also `'desc'` (descending) by default, so that the most popular tags are shown first.
106
+
107
+ `data = StackConnect.retrieve_tags(from_date)`
88
108
 
89
109
  Sample Data:
90
110
 
@@ -98,13 +118,6 @@ Sample Data:
98
118
  "count": 1,
99
119
  "name": "microsoft-net-http"
100
120
  },
101
- {
102
- "has_synonyms": false,
103
- "is_moderator_only": false,
104
- "is_required": false,
105
- "count": 1,
106
- "name": "owin-middleware"
107
- },
108
121
  {
109
122
  "has_synonyms": false,
110
123
  "is_moderator_only": false,
@@ -119,6 +132,79 @@ Sample Data:
119
132
  }
120
133
  ```
121
134
 
135
+ ### Retrieving User Data
136
+
137
+ This call will retrieve all time user data, since the creation of the site. When making this API call, check for the `'has_more'` attribute to see if there are more pages. If `'has_more'` returns true, then increase the `'page'` parameter before calling the function again to retrieve the next page of data.
138
+
139
+ The query is called with a sort on `'reputation'`, and ordered in descending order. Therefore, the users with the highest reputation will appear first.
140
+
141
+ ```
142
+ sc = StackConnect.new
143
+ data = sc.retrieve_users(1)
144
+ ```
145
+
146
+ Sample data:
147
+
148
+ ```
149
+ {
150
+ "items": [
151
+ {
152
+ "badge_counts": {
153
+ "bronze": 5498,
154
+ "silver": 4081,
155
+ "gold": 261
156
+ },
157
+ "account_id": 11683,
158
+ "is_employee": false,
159
+ "last_modified_date": 1394538684,
160
+ "last_access_date": 1394629373,
161
+ "reputation_change_year": 21465,
162
+ "reputation_change_quarter": 21465,
163
+ "reputation_change_month": 3600,
164
+ "reputation_change_week": 1085,
165
+ "reputation_change_day": 215,
166
+ "reputation": 656402,
167
+ "creation_date": 1222430705,
168
+ "user_type": "registered",
169
+ "user_id": 22656,
170
+ "age": 37,
171
+ "accept_rate": 83,
172
+ "location": "Reading, United Kingdom",
173
+ "website_url": "http://csharpindepth.com",
174
+ "link": "http://stackoverflow.com/users/22656/jon-skeet",
175
+ "display_name": "Jon Skeet",
176
+ "profile_image": "https://www.gravatar.com/avatar/6d8ebb117e8d83d74ea95fbdd0f87e13?s=128&d=identicon&r=PG"
177
+ }
178
+ ],
179
+ "has_more": true,
180
+ "quota_max": 10000,
181
+ "quota_remaining": 9990
182
+ }
183
+ ```
184
+ The sample data here only has one item, normally, you'd get the first 30 results. In order to check if there is more data:
185
+
186
+ ```
187
+ has_more = data["has_more"]
188
+ ```
189
+ If `'has_more'` returns true, then increase the page count, and call again:
190
+
191
+ ```
192
+ page = 1
193
+ begin
194
+ data = sc.retrieve_users(page)
195
+
196
+ # work with data
197
+ ..
198
+
199
+ has_more = data["has_more"]
200
+ page += 1
201
+ sleep(1)
202
+ end while has_more == true
203
+
204
+ ```
205
+
206
+ Make sure that in before making the call, you call `sleep()` for at least one second, otherwise, the StackExchange API will throttle your requests and require you to wait a certain amount of time before making another request. Usually increasing this time to about 10 seconds will guarantee your calls won't get throttled for the remainder of the pages.
207
+
122
208
  ## Contributing
123
209
 
124
210
  1. Fork it ( http://github.com/[my-github-username]/stack-connect/fork )
data/lib/stackconnect.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'active_support/all'
1
+ require 'active_support/core_ext/hash'
2
2
  require 'open-uri'
3
3
  require 'uri'
4
4
 
5
5
  class StackConnect
6
6
  attr_accessor :api, :site, :uri
7
7
 
8
- @@VERSION = "0.1.5"
8
+ @@VERSION = "0.1.6"
9
9
  @@api = 'http://api.stackexchange.com/'
10
10
  @@site = 'stackoverflow'
11
11
  @@api_v = '/2.2/'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - amirtcheva
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - .README.md.swo
118
119
  - .gitignore
119
120
  - Gemfile
120
121
  - LICENSE.txt