/
stackoverflow.rb
298 lines (241 loc) · 7.97 KB
/
stackoverflow.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
require "rubygems"
require "httparty"
# #
# http://dev.meta.stackoverflow.com/questions/34594/overall-api-method-list
# #
class Stackoverflow
include HTTParty
base_uri "http://api.stackoverflow.com/0.6/"
default_params :output => "json"
format :json
def initialize(key, version="")
self.class.default_params :key => key
end
##########################################
# QUESTIONS METHODS
##########################################
# GENERAL
def questions(options={})
self.class.get("/questions", options)
end
def active_questions(options={})
options.merge(:sort => "active")
self.class.get("/questions", options)
end
def newest_questions(options={})
options.merge(:sort => "newest")
self.class.get("/questions", options)
end
def featured_questions(options={})
options.merge(:sort => "featured")
self.class.get("/questions", options)
end
def hot_questions(options={})
options.merge(:sort => "hot")
self.class.get("/questions", options)
end
def weekly_hot_questions(options={})
options.merge(:sort => "week")
self.class.get("/questions", options)
end
def monthly_hot_questions(options={})
options.merge(:sort => "month")
self.class.get("/questions", options)
end
def highest_voted_questions(options={})
options.merge(:sort => "votes")
self.class.get("/questions", options)
end
def unanswered_questions(options={})
self.class.get("/questions/unanswered", options)
end
def newest_unanswered_questions(options={})
options.merge(:sort => "newest")
self.class.get("/questions/unanswered", options)
end
def unanswered_questions_by_votes(options={})
options.merge(:sort => "votes")
self.class.get("/questions/unanswered", options)
end
# TODO
# http://api.stackoverflow.com/0.5/questions/tagged?tagged={tags} - uses tagged parameter, returns questions containing all the provided tags.
# QUESTIONS CREATED BY A SPECIFIC USER
def user_questions(user_id, options={})
self.class.get("/users/#{user_id}/questions", options)
end
def user_recent_questions(user_id, options={})
options.merge(:sort => "recent")
self.class.get("/users/#{user_id}/questions", options)
end
def user_questions_by_views(user_id, options={})
options.merge(:sort => "views")
self.class.get("/users/#{user_id}/questions", options)
end
def user_newest_questions(user_id, options={})
options.merge(:sort => "newest")
self.class.get("/users/#{user_id}/questions", options)
end
def user_questions_by_votes(user_id, options={})
options.merge(:sort => "votes")
self.class.get("/users/#{user_id}/questions", options)
end
# QUESTIONS MARKED AS FAVORITE BY A SPECIFIC USER
def user_favorites(user_id, options={})
self.class.get("/users/#{user_id}/favorites", options)
end
def user_recent_favorites(user_id, options={})
options.merge(:sort => "recent")
self.class.get("/users/#{user_id}/favorites", options)
end
def user_favorites_by_views(user_id, options={})
options.merge(:sort => "views")
self.class.get("/users/#{user_id}/favorites", options)
end
def user_newest_favorites(user_id, options={})
options.merge(:sort => "newest")
self.class.get("/users/#{user_id}/favorites", options)
end
# QUESTION TIMELINE
def question_timeline(question_id, options={})
self.class.get("/questions/#{question_id}/timeline", options)
end
# SINGLE QUESTION
def question_by_id(question_id, options={})
self.class.get("/questions/#{question_id}", options)
end
##########################################
# USERS METHODS
##########################################
# GENERAL
def users(options={})
self.class.get("/users", options)
end
def user_by_id(user_id, options={})
self.class.get("/users/#{user_id}", options)
end
def users_by_reputation(options={})
options.merge(:sort => "reputation")
self.class.get("/users", options)
end
def newest_users(options={})
options.merge(:sort => "creation")
self.class.get("/users", options)
end
def users_by_name(options={})
options.merge(:sort => "name")
self.class.get("/users", options)
end
# MENTIONS
def user_mentions(user_id,options={})
self.class.get("/users/#{user_id}/mentioned", options)
end
##########################################
# BADGES METHODS
##########################################
# GENERAL
def badges(options={})
self.class.get("/badges", options)
end
def badges_by_name(options={})
self.class.get("/badges/name", options)
end
def tags_badges(options={})
self.class.get("/badges/tags", options)
end
def badges_for_user_id(user_id, options={})
self.class.get("/users/#{user_id}/badges", options)
end
##########################################
# TAGS METHODS
##########################################
# GENERAL
def tags(options={})
self.class.get("/tags", options)
end
def popular_tags(options={})
options.merge(:sort => "popular")
self.class.get("/tags", options)
end
def tags_by_name(options={})
options.merge(:sort => "name")
self.class.get("/tags", options)
end
def recent_tags(options={})
options.merge(:sort => "activity")
self.class.get("/tags", options)
end
def tags_for_user(user_id, options={})
self.class.get("/user/#{user_id}/tag", options)
end
##########################################
# ANSWERS METHODS
##########################################
# GENERAL
def answers_by_user(user_id,options={})
self.class.get("/users/#{user_id}/answers", options)
end
def recent_answers_by_user(user_id, options={})
options.merge(:sort => "creation")
self.class.get("/users/#{user_id}/answers", options)
end
def answers_by_user_by_views(user_id, options={})
options.merge(:sort => "views")
self.class.get("/users/#{user_id}/answers", options)
end
def newest_answers_by_user(user_id, options={})
options.merge(:sort => "creation")
self.class.get("/users/#{user_id}/answers", options)
end
def answers_by_user_by_votes(user_id, options={})
options.merge(:sort => "votes")
self.class.get("/users/#{user_id}/answers", options)
end
# SINGLE ANSWER
def answer_by_id(user_id, options={})
self.class.get("/answers/#{user_id}", options)
end
##########################################
# COMMENTS METHODS
##########################################
# GENERAL
# Comments created by a specific user
def comments_by_user(user_id, options={})
self.class.get("/users/#{user_id}/comments", options)
end
def recent_comments_by_user(user_id, options={})
options.merge(:sort => "creation")
self.class.get("/users/#{user_id}/comments", options)
end
def comments_by_user_by_score(user_id, options={})
options.merge(:sort => "votes")
self.class.get("/users/#{user_id}/comments", options)
end
# Comments created by a specific user {id} directed at {toid}:
def comments_by_user_directed_to(from_id, to_id, options={})
self.class.get("/users/#{from_id}/comments/#{to_id}", options)
end
def recent_comments_by_user_directed_to(from_id, to_id, options={})
options.merge(:sort => "creation")
self.class.get("/users/#{from_id}/comments/#{to_id}", options)
end
def comments_by_user_directed_to_by_score(from_id, to_id, options={})
options.merge(:sort => "votes")
self.class.get("/users/#{from_id}/comments/#{to_id}", options)
end
# Single Comment Method - Topic Here
def comment_by_id(comment_id, options={})
self.class.get("/comments/#{comment_id}", options)
end
##########################################
# STATS METHODS
##########################################
def reputation_for_user(user_id, options={})
self.class.get("/users/#{user_id}/reputation", options)
end
##########################################
# STATS METHODS
##########################################
def stats
self.class.get("/stats")
end
end