pilha 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe StackExchange::StackOverflow::Answer do
4
+
5
+ it 'should return a answer identified by its id' do
6
+ response = StackOverflow::Answer.find_by_id(666)
7
+ response.total.should == 1
8
+ response.pagesize.should == 30
9
+
10
+ answer = response.answers.first
11
+ answer.id.should == 666
12
+ answer.accepted.should be_false
13
+ answer.answer_comments_url.should == "/answers/666/comments"
14
+ answer.question_id.should == 664
15
+
16
+ user = answer.owner
17
+ user.id.should == 58
18
+ user.user_type.should == "registered"
19
+ user.display_name.should == "cmcculloh"
20
+ user.reputation.should == 2903
21
+ user.email_hash.should == "298e0497aa6b76a573f17e6a2bb22dec"
22
+ end
23
+
24
+ it 'should include user association when option :include => :comments' do
25
+ response = StackOverflow::Answer.find_by_id 555, :query => { :comments => true }
26
+ response.answers.first.comments.size.should_not == 1
27
+ comment = response.answers.first.comments.first
28
+ comment.id.should == 278816
29
+ end
30
+
31
+ it 'should find all answers associated to a user' do
32
+ response = StackOverflow::Answer.find_by_user_id 1
33
+
34
+ response.answers.size.should == 30
35
+ response.total.should == 165
36
+ first_answer = response.answers.first
37
+ first_answer.answer_id.should == 1250987
38
+ end
39
+ end
40
+
41
+
@@ -7,7 +7,7 @@ describe StackExchange::StackOverflow::Badge do
7
7
  end
8
8
 
9
9
  describe 'when querying for badges' do
10
- it 'should return badges' do
10
+ it 'should return all badges' do
11
11
  response = StackOverflow::Badge.all
12
12
  first_badge = response.first
13
13
  first_badge.badge_id.should == 9
@@ -19,5 +19,18 @@ describe StackExchange::StackOverflow::Badge do
19
19
  first_badge.tag_based.should be_false
20
20
  first_badge.badges_recipients_url.should == "/badges/9"
21
21
  end
22
+
23
+ it 'should return all tag-based badges' do
24
+
25
+ response = StackOverflow::Badge.all(:tag_based => true)
26
+ first_tag_based = response.first
27
+ first_tag_based.id.should == 204
28
+ first_tag_based.rank.should == "silver"
29
+ first_tag_based.name.should == ".htaccess"
30
+ first_tag_based.description.should == "Earned 400 upvotes for answers in the .htaccess tag"
31
+ first_tag_based.award_count.should == 1
32
+ first_tag_based.tag_based.should be_true
33
+ first_tag_based.badges_recipients_url.should == "/badges/204"
34
+ end
22
35
  end
23
36
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe StackExchange::StackOverflow::Comment do
4
+ it 'should return a comment identified by its id' do
5
+ response = StackOverflow::Comment.find_by_id(1)
6
+
7
+ response.total.should == 1
8
+ response.page.should == 1
9
+ response.pagesize.should == 30
10
+
11
+ comment = response.comments.first
12
+ comment.id.should == 1
13
+ comment.creation_date.should == 1220688430
14
+ comment.post_id.should == 35314
15
+ comment.post_type.should == "answer"
16
+ comment.score.should == 7
17
+ comment.body.should == "not sure why this is getting downvoted -- it is correct! Double check it in your compiler if you don't believe him!"
18
+ end
19
+ end
@@ -33,15 +33,15 @@ describe StackOverflow::Client do
33
33
  @old_url = @client.url
34
34
 
35
35
  StackOverflow::Client.config do |options|
36
- options[:url] = 'http://test.it'
37
- options[:api_version] = '666'
38
- options[:api_key] = 'key1234'
36
+ options.url = 'http://test.it'
37
+ options.api_version = '666'
38
+ options.api_key = 'key1234'
39
39
  end
40
40
  end
41
41
 
42
42
  after do
43
43
  StackOverflow::Client.config do |options|
44
- options[:url] = @old_url
44
+ options.url = @old_url
45
45
  end
46
46
  end
47
47
 
@@ -40,7 +40,7 @@ describe StackExchange::StackOverflow::User do
40
40
  end
41
41
 
42
42
  it 'should return the right number of items when pagesize is passed in the query parameters' do
43
- response = StackOverflow::User.find_by_badge_id(9, :pagesize => 50)
43
+ response = StackOverflow::User.find_by_badge_id(9, :query => { :pagesize => 50 })
44
44
  response.pagesize.should == 50
45
45
  response.users.size.should == 50
46
46
  end
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ FakeWeb.allow_net_connect = false
14
14
 
15
15
  def register(options)
16
16
  url = api_method_url(options[:url])
17
- FakeWeb.register_uri(:get, url, :body => read_fixture(options[:body] + '.json'))
17
+ FakeWeb.register_uri(:get, url, :body => read_fixture(options[:body] + '.json.gz'))
18
18
  end
19
19
 
20
20
  def read_fixture(fixture)
@@ -31,3 +31,8 @@ end
31
31
 
32
32
  register(:url => 'badges/9/', :body => 'badges_by_id')
33
33
  register(:url => 'badges/9/?pagesize=50', :body => 'badges_by_id_page2')
34
+ register(:url => 'badges/tags/', :body => 'badges_tag_based')
35
+ register(:url => 'answers/666/', :body => 'answers_by_id')
36
+ register(:url => 'answers/555/?comments=true', :body => 'answer_with_comments')
37
+ register(:url => 'comments/1/', :body => 'comments')
38
+ register(:url => 'users/1/answers/', :body => 'users_answers')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dalto Curvelano Junior
@@ -18,7 +18,7 @@ date: 2010-05-27 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: A ruby wrapper to the StackExchange (StackOverflow and friends) API.
21
+ description: A ruby wrapper to the Stack Exchange (Stack Overflow and friends) API.
22
22
  email:
23
23
  executables: []
24
24
 
@@ -31,20 +31,37 @@ files:
31
31
  - lib/pilha/stack_overflow/badge.rb
32
32
  - lib/pilha/stack_overflow/statistics.rb
33
33
  - lib/pilha/stack_overflow/user.rb
34
+ - lib/pilha/stack_overflow/comment.rb
35
+ - lib/pilha/stack_overflow/answer.rb
34
36
  - lib/pilha.rb
37
+ - spec/fixtures/stats.json
38
+ - spec/fixtures/stats.json.gz
35
39
  - spec/fixtures/badges.json
40
+ - spec/fixtures/badges.json.gz
36
41
  - spec/fixtures/badges_by_id.json
42
+ - spec/fixtures/badges_by_id.json.gz
37
43
  - spec/fixtures/badges_by_id_page2.json
38
- - spec/fixtures/badges_name.json
39
- - spec/fixtures/stats.json
44
+ - spec/fixtures/badges_by_id_page2.json.gz
45
+ - spec/fixtures/badges_tag_based.json
46
+ - spec/fixtures/badges_tag_based.json.gz
47
+ - spec/fixtures/answers_by_id.json
48
+ - spec/fixtures/answers_by_id.json.gz
49
+ - spec/fixtures/answer_with_comments.json
50
+ - spec/fixtures/answer_with_comments.json.gz
51
+ - spec/fixtures/comments.json
52
+ - spec/fixtures/comments.json.gz
53
+ - spec/fixtures/users_answers.json
54
+ - spec/fixtures/users_answers.json.gz
40
55
  - spec/pilha/stack_overflow/badge_spec.rb
41
56
  - spec/pilha/stack_overflow/stack_overflow_spec.rb
42
57
  - spec/pilha/stack_overflow/statistics_spec.rb
43
58
  - spec/pilha/stack_overflow/user_spec.rb
59
+ - spec/pilha/stack_overflow/comment_spec.rb
60
+ - spec/pilha/stack_overflow/answer_spec.rb
44
61
  - spec/spec.opts
45
62
  - spec/spec_helper.rb
46
63
  has_rdoc: true
47
- homepage: http://github.com/dlt/stack_exchange
64
+ homepage: http://github.com/dlt/pilha
48
65
  licenses: []
49
66
 
50
67
  post_install_message:
@@ -72,6 +89,6 @@ rubyforge_project:
72
89
  rubygems_version: 1.3.6
73
90
  signing_key:
74
91
  specification_version: 3
75
- summary: A ruby wrapper to the StackExchange (StackOverflow and friends) API.
92
+ summary: A ruby wrapper to the Stack Exchange (Stack Overflow and friends) API.
76
93
  test_files: []
77
94
 
@@ -1,400 +0,0 @@
1
- {
2
- "badges": [
3
- {
4
- "badge_id": 9,
5
- "rank": "bronze",
6
- "name": "Autobiographer",
7
- "description": "Completed all user profile fields",
8
- "award_count": 28066,
9
- "tag_based": false,
10
- "badges_recipients_url": "/badges/9"
11
- },
12
- {
13
- "badge_id": 30,
14
- "rank": "silver",
15
- "name": "Beta",
16
- "description": "Actively participated in the Stack Overflow private beta",
17
- "award_count": 2606,
18
- "tag_based": false,
19
- "badges_recipients_url": "/badges/30"
20
- },
21
- {
22
- "badge_id": 8,
23
- "rank": "bronze",
24
- "name": "Citizen Patrol",
25
- "description": "First flagged post",
26
- "award_count": 5690,
27
- "tag_based": false,
28
- "badges_recipients_url": "/badges/8"
29
- },
30
- {
31
- "badge_id": 32,
32
- "rank": "silver",
33
- "name": "Civic Duty",
34
- "description": "Voted 300 or more times",
35
- "award_count": 4693,
36
- "tag_based": false,
37
- "badges_recipients_url": "/badges/32"
38
- },
39
- {
40
- "badge_id": 4,
41
- "rank": "bronze",
42
- "name": "Cleanup",
43
- "description": "First rollback",
44
- "award_count": 3813,
45
- "tag_based": false,
46
- "badges_recipients_url": "/badges/4"
47
- },
48
- {
49
- "badge_id": 31,
50
- "rank": "bronze",
51
- "name": "Commentator",
52
- "description": "Left 10 comments",
53
- "award_count": 31097,
54
- "tag_based": false,
55
- "badges_recipients_url": "/badges/31"
56
- },
57
- {
58
- "badge_id": 7,
59
- "rank": "bronze",
60
- "name": "Critic",
61
- "description": "First down vote",
62
- "award_count": 25328,
63
- "tag_based": false,
64
- "badges_recipients_url": "/badges/7"
65
- },
66
- {
67
- "badge_id": 37,
68
- "rank": "bronze",
69
- "name": "Disciplined",
70
- "description": "Deleted own post with score of 3 or higher",
71
- "award_count": 1665,
72
- "tag_based": false,
73
- "badges_recipients_url": "/badges/37"
74
- },
75
- {
76
- "badge_id": 3,
77
- "rank": "bronze",
78
- "name": "Editor",
79
- "description": "First edit",
80
- "award_count": 63224,
81
- "tag_based": false,
82
- "badges_recipients_url": "/badges/3"
83
- },
84
- {
85
- "badge_id": 155,
86
- "rank": "gold",
87
- "name": "Electorate",
88
- "description": "Voted on 600 questions and 25% or more of total votes are on questions",
89
- "award_count": 276,
90
- "tag_based": false,
91
- "badges_recipients_url": "/badges/155"
92
- },
93
- {
94
- "badge_id": 19,
95
- "rank": "silver",
96
- "name": "Enlightened",
97
- "description": "First answer was accepted with score of 10 or more",
98
- "award_count": 11407,
99
- "tag_based": false,
100
- "badges_recipients_url": "/badges/19"
101
- },
102
- {
103
- "badge_id": 71,
104
- "rank": "silver",
105
- "name": "Enthusiast",
106
- "description": "Visited the site each day for 30 consecutive days",
107
- "award_count": 6940,
108
- "tag_based": false,
109
- "badges_recipients_url": "/badges/71"
110
- },
111
- {
112
- "badge_id": 145,
113
- "rank": "silver",
114
- "name": "Epic",
115
- "description": "Hit the daily reputation cap on 50 days",
116
- "award_count": 86,
117
- "tag_based": false,
118
- "badges_recipients_url": "/badges/145"
119
- },
120
- {
121
- "badge_id": 28,
122
- "rank": "gold",
123
- "name": "Famous Question",
124
- "description": "Asked a question with 10,000 views",
125
- "award_count": 1063,
126
- "tag_based": false,
127
- "badges_recipients_url": "/badges/28"
128
- },
129
- {
130
- "badge_id": 83,
131
- "rank": "gold",
132
- "name": "Fanatic",
133
- "description": "Visited the site each day for 100 consecutive days",
134
- "award_count": 937,
135
- "tag_based": false,
136
- "badges_recipients_url": "/badges/83"
137
- },
138
- {
139
- "badge_id": 33,
140
- "rank": "silver",
141
- "name": "Favorite Question",
142
- "description": "Question favorited by 25 users",
143
- "award_count": 1082,
144
- "tag_based": false,
145
- "badges_recipients_url": "/badges/33"
146
- },
147
- {
148
- "badge_id": 15,
149
- "rank": "silver",
150
- "name": "Generalist",
151
- "description": "Provided non-wiki answers of 15 total score in 20 of top 40 tags",
152
- "award_count": 133,
153
- "tag_based": false,
154
- "badges_recipients_url": "/badges/15"
155
- },
156
- {
157
- "badge_id": 24,
158
- "rank": "silver",
159
- "name": "Good Answer",
160
- "description": "Answer score of 25 or more",
161
- "award_count": 9093,
162
- "tag_based": false,
163
- "badges_recipients_url": "/badges/24"
164
- },
165
- {
166
- "badge_id": 21,
167
- "rank": "silver",
168
- "name": "Good Question",
169
- "description": "Question score of 25 or more",
170
- "award_count": 2268,
171
- "tag_based": false,
172
- "badges_recipients_url": "/badges/21"
173
- },
174
- {
175
- "badge_id": 25,
176
- "rank": "gold",
177
- "name": "Great Answer",
178
- "description": "Answer score of 100 or more",
179
- "award_count": 1020,
180
- "tag_based": false,
181
- "badges_recipients_url": "/badges/25"
182
- },
183
- {
184
- "badge_id": 22,
185
- "rank": "gold",
186
- "name": "Great Question",
187
- "description": "Question score of 100 or more",
188
- "award_count": 197,
189
- "tag_based": false,
190
- "badges_recipients_url": "/badges/22"
191
- },
192
- {
193
- "badge_id": 18,
194
- "rank": "silver",
195
- "name": "Guru",
196
- "description": "Accepted answer and score of 40 or more",
197
- "award_count": 1128,
198
- "tag_based": false,
199
- "badges_recipients_url": "/badges/18"
200
- },
201
- {
202
- "badge_id": 146,
203
- "rank": "gold",
204
- "name": "Legendary",
205
- "description": "Hit the daily reputation cap on 150 days",
206
- "award_count": 18,
207
- "tag_based": false,
208
- "badges_recipients_url": "/badges/146"
209
- },
210
- {
211
- "badge_id": 144,
212
- "rank": "bronze",
213
- "name": "Mortarboard",
214
- "description": "Hit the daily reputation cap for the first time",
215
- "award_count": 4128,
216
- "tag_based": false,
217
- "badges_recipients_url": "/badges/144"
218
- },
219
- {
220
- "badge_id": 17,
221
- "rank": "silver",
222
- "name": "Necromancer",
223
- "description": "Answered a question more than 60 days later with score of 5 or more",
224
- "award_count": 4894,
225
- "tag_based": false,
226
- "badges_recipients_url": "/badges/17"
227
- },
228
- {
229
- "badge_id": 23,
230
- "rank": "bronze",
231
- "name": "Nice Answer",
232
- "description": "Answer score of 10 or more",
233
- "award_count": 55511,
234
- "tag_based": false,
235
- "badges_recipients_url": "/badges/23"
236
- },
237
- {
238
- "badge_id": 20,
239
- "rank": "bronze",
240
- "name": "Nice Question",
241
- "description": "Question score of 10 or more",
242
- "award_count": 13355,
243
- "tag_based": false,
244
- "badges_recipients_url": "/badges/20"
245
- },
246
- {
247
- "badge_id": 27,
248
- "rank": "silver",
249
- "name": "Notable Question",
250
- "description": "Asked a question with 2,500 views",
251
- "award_count": 14373,
252
- "tag_based": false,
253
- "badges_recipients_url": "/badges/27"
254
- },
255
- {
256
- "badge_id": 5,
257
- "rank": "bronze",
258
- "name": "Organizer",
259
- "description": "First retag",
260
- "award_count": 12069,
261
- "tag_based": false,
262
- "badges_recipients_url": "/badges/5"
263
- },
264
- {
265
- "badge_id": 38,
266
- "rank": "bronze",
267
- "name": "Peer Pressure",
268
- "description": "Deleted own post with score of -3 or lower",
269
- "award_count": 2965,
270
- "tag_based": false,
271
- "badges_recipients_url": "/badges/38"
272
- },
273
- {
274
- "badge_id": 26,
275
- "rank": "bronze",
276
- "name": "Popular Question",
277
- "description": "Asked a question with 1,000 views",
278
- "award_count": 51937,
279
- "tag_based": false,
280
- "badges_recipients_url": "/badges/26"
281
- },
282
- {
283
- "badge_id": 62,
284
- "rank": "gold",
285
- "name": "Populist",
286
- "description": "Answer outscored an accepted answer with score of more than 10 by more than 2x",
287
- "award_count": 344,
288
- "tag_based": false,
289
- "badges_recipients_url": "/badges/62"
290
- },
291
- {
292
- "badge_id": 94,
293
- "rank": "silver",
294
- "name": "Pundit",
295
- "description": "Left 10 comments with score of 10 or more",
296
- "award_count": 83,
297
- "tag_based": false,
298
- "badges_recipients_url": "/badges/94"
299
- },
300
- {
301
- "badge_id": 95,
302
- "rank": "gold",
303
- "name": "Reversal",
304
- "description": "Provided answer of +20 score to a question of -5 score",
305
- "award_count": 38,
306
- "tag_based": false,
307
- "badges_recipients_url": "/badges/95"
308
- },
309
- {
310
- "badge_id": 10,
311
- "rank": "bronze",
312
- "name": "Scholar",
313
- "description": "Asked a question and accepted an answer",
314
- "award_count": 69357,
315
- "tag_based": false,
316
- "badges_recipients_url": "/badges/10"
317
- },
318
- {
319
- "badge_id": 14,
320
- "rank": "bronze",
321
- "name": "Self-Learner",
322
- "description": "Answered your own question with score of 3 or more",
323
- "award_count": 3841,
324
- "tag_based": false,
325
- "badges_recipients_url": "/badges/14"
326
- },
327
- {
328
- "badge_id": 36,
329
- "rank": "gold",
330
- "name": "Stellar Question",
331
- "description": "Question favorited by 100 users",
332
- "award_count": 153,
333
- "tag_based": false,
334
- "badges_recipients_url": "/badges/36"
335
- },
336
- {
337
- "badge_id": 12,
338
- "rank": "silver",
339
- "name": "Strunk & White",
340
- "description": "Edited 100 entries",
341
- "award_count": 649,
342
- "tag_based": false,
343
- "badges_recipients_url": "/badges/12"
344
- },
345
- {
346
- "badge_id": 2,
347
- "rank": "bronze",
348
- "name": "Student",
349
- "description": "Asked first question with at least one up vote",
350
- "award_count": 85755,
351
- "tag_based": false,
352
- "badges_recipients_url": "/badges/2"
353
- },
354
- {
355
- "badge_id": 6,
356
- "rank": "bronze",
357
- "name": "Supporter",
358
- "description": "First up vote",
359
- "award_count": 61321,
360
- "tag_based": false,
361
- "badges_recipients_url": "/badges/6"
362
- },
363
- {
364
- "badge_id": 11,
365
- "rank": "silver",
366
- "name": "Taxonomist",
367
- "description": "Created a tag used by 50 questions",
368
- "award_count": 2083,
369
- "tag_based": false,
370
- "badges_recipients_url": "/badges/11"
371
- },
372
- {
373
- "badge_id": 1,
374
- "rank": "bronze",
375
- "name": "Teacher",
376
- "description": "Answered first question with score of 1 or more",
377
- "award_count": 71525,
378
- "tag_based": false,
379
- "badges_recipients_url": "/badges/1"
380
- },
381
- {
382
- "badge_id": 63,
383
- "rank": "bronze",
384
- "name": "Tumbleweed",
385
- "description": "Asked a question with no answers, no comments, and low views for a week",
386
- "award_count": 23224,
387
- "tag_based": false,
388
- "badges_recipients_url": "/badges/63"
389
- },
390
- {
391
- "badge_id": 13,
392
- "rank": "silver",
393
- "name": "Yearling",
394
- "description": "Active member for a year, earning at least 200 reputation",
395
- "award_count": 19443,
396
- "tag_based": false,
397
- "badges_recipients_url": "/badges/13"
398
- }
399
- ]
400
- }