pilha 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/lib/pilha.rb +7 -10
  2. data/lib/pilha/stack_overflow/answer.rb +7 -8
  3. data/lib/pilha/stack_overflow/badge.rb +8 -6
  4. data/lib/pilha/stack_overflow/base.rb +27 -0
  5. data/lib/pilha/stack_overflow/comment.rb +21 -9
  6. data/lib/pilha/stack_overflow/question.rb +41 -0
  7. data/lib/pilha/stack_overflow/statistics.rb +7 -6
  8. data/lib/pilha/stack_overflow/user.rb +5 -8
  9. data/pilha.gemspec +8 -21
  10. data/spec/fixtures/answer_comments.json +37 -0
  11. data/spec/fixtures/answers_by_question_id.json +430 -0
  12. data/spec/fixtures/answers_by_question_id.json.gz +0 -0
  13. data/spec/fixtures/badges_name.json +400 -0
  14. data/spec/fixtures/badges_name.json.gz +0 -0
  15. data/spec/fixtures/comments_by_mentioned_user_id.json +117 -0
  16. data/spec/fixtures/comments_by_mentioned_user_id.json.gz +0 -0
  17. data/spec/fixtures/comments_by_question_id.json +22 -0
  18. data/spec/fixtures/comments_by_question_id.json.gz +0 -0
  19. data/spec/fixtures/comments_by_user_id.json +464 -0
  20. data/spec/fixtures/comments_by_user_id.json.gz +0 -0
  21. data/spec/fixtures/comments_by_user_id_to_mentioned_user_id.json.gz +0 -0
  22. data/spec/fixtures/comments_by_user_to_mentioned_user.json +29 -0
  23. data/spec/fixtures/comments_by_user_to_mentioned_user.json.gz +0 -0
  24. data/spec/fixtures/comments_by_user_to_mentioned_user_id.json.gz +0 -0
  25. data/spec/fixtures/question_by_id.json +162 -0
  26. data/spec/fixtures/question_by_id.json.gz +0 -0
  27. data/spec/fixtures/question_by_id_with_body.json +169 -0
  28. data/spec/fixtures/question_by_id_with_body.json.gz +0 -0
  29. data/spec/fixtures/question_by_user_id.json.gz +0 -0
  30. data/spec/fixtures/questions.json +1773 -0
  31. data/spec/fixtures/questions.json.gz +0 -0
  32. data/spec/fixtures/questions.part +859 -0
  33. data/spec/fixtures/questions_by_user_id.json +35 -0
  34. data/spec/fixtures/questions_by_user_id.json.gz +0 -0
  35. data/spec/fixtures/users.json +983 -0
  36. data/spec/fixtures/users_by_id.json +40 -0
  37. data/spec/fixtures/users_by_id.json.gz +0 -0
  38. data/spec/pilha/stack_overflow/badge_spec.rb +3 -3
  39. data/spec/pilha/stack_overflow/comment_spec.rb +52 -1
  40. data/spec/pilha/stack_overflow/question_spec.rb +63 -0
  41. data/spec/pilha/stack_overflow/stack_overflow_spec.rb +2 -4
  42. data/spec/spec_helper.rb +7 -1
  43. metadata +53 -22
@@ -0,0 +1,40 @@
1
+ {
2
+ "total": 1,
3
+ "page": 1,
4
+ "pagesize": 30,
5
+ "users": [
6
+ {
7
+ "user_id": 555,
8
+ "user_type": "registered",
9
+ "creation_date": 1218041039,
10
+ "display_name": "Hunter",
11
+ "reputation": 980,
12
+ "email_hash": "fed6c543fa3473193cecf34d0ccb1b77",
13
+ "age": 30,
14
+ "last_access_date": 1274807905,
15
+ "website_url": "http://www.hanchorllc.com",
16
+ "location": "Santa Barbara, CA",
17
+ "about_me": "",
18
+ "question_count": 6,
19
+ "answer_count": 29,
20
+ "view_count": 110,
21
+ "up_vote_count": 18,
22
+ "down_vote_count": 7,
23
+ "accept_rate": 100,
24
+ "user_questions_url": "/users/555/questions",
25
+ "user_answers_url": "/users/555/answers",
26
+ "user_favorites_url": "/users/555/favorites",
27
+ "user_tags_url": "/users/555/tags",
28
+ "user_badges_url": "/users/555/badges",
29
+ "user_timeline_url": "/users/555/timeline",
30
+ "user_mentioned_url": "/users/555/mentioned",
31
+ "user_comments_url": "/users/555/comments",
32
+ "user_reputation_url": "/users/555/reputation",
33
+ "badge_counts": {
34
+ "gold": 0,
35
+ "silver": 2,
36
+ "bronze": 10
37
+ }
38
+ }
39
+ ]
40
+ }
Binary file
@@ -9,7 +9,8 @@ describe StackExchange::StackOverflow::Badge do
9
9
  describe 'when querying for badges' do
10
10
  it 'should return all badges' do
11
11
  response = StackOverflow::Badge.all
12
- first_badge = response.first
12
+
13
+ first_badge = response.badges.first
13
14
  first_badge.badge_id.should == 9
14
15
  first_badge.id.should == 9
15
16
  first_badge.rank.should == "bronze"
@@ -21,9 +22,8 @@ describe StackExchange::StackOverflow::Badge do
21
22
  end
22
23
 
23
24
  it 'should return all tag-based badges' do
24
-
25
25
  response = StackOverflow::Badge.all(:tag_based => true)
26
- first_tag_based = response.first
26
+ first_tag_based = response.badges.first
27
27
  first_tag_based.id.should == 204
28
28
  first_tag_based.rank.should == "silver"
29
29
  first_tag_based.name.should == ".htaccess"
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe StackExchange::StackOverflow::Comment do
4
4
  it 'should return a comment identified by its id' do
5
- response = StackOverflow::Comment.find_by_id(1)
5
+ response = StackOverflow::Comment.find 1
6
6
 
7
7
  response.total.should == 1
8
8
  response.page.should == 1
@@ -55,4 +55,55 @@ describe StackExchange::StackOverflow::Comment do
55
55
  comment.owner.reputation.should == 1542
56
56
  comment.owner.email_hash.should == "9e7ef08258f04dab37b43842d261aea8"
57
57
  end
58
+
59
+ it 'should get comments that contains mention to a user identified by id' do
60
+ response = StackOverflow::Comment.find_by_mentioned_user_id 549
61
+ response.total.should == 5
62
+
63
+ comment = response.comments.first
64
+ comment.id.should == 2289139
65
+ comment.creation_date.should == 1266949196
66
+ comment.post_id.should == 2320184
67
+ comment.post_type.should == "answer"
68
+ comment.score.should be_zero
69
+ comment.body.should == "@Josh - why not use a pagemethod then? You can just pass back the selected value and then your dependent picklist can use that value to populate itself. Might mean you need to change your approach, but less stuff goes down the wire this way."
70
+
71
+
72
+ comment.owner.id.should == 77814
73
+ comment.owner.user_type.should == "registered"
74
+ comment.owner.display_name.should == "nickyt"
75
+ comment.owner.reputation.should == 1130
76
+ comment.owner.email_hash.should == "243668a44dc257d64fa88656beb94469"
77
+
78
+ comment.mentioned_user.id.should == 549
79
+ comment.mentioned_user.user_type.should == "registered"
80
+ comment.mentioned_user.display_name.should == "Josh Kodroff"
81
+ comment.mentioned_user.reputation.should == 1542
82
+ comment.mentioned_user.email_hash.should == "9e7ef08258f04dab37b43842d261aea8"
83
+ end
84
+
85
+ it 'should get all comments of a user directed to another user' do
86
+ response = StackOverflow::Comment.find_by_user_id(77814, :to_user => 549)
87
+ response.total.should == 1
88
+
89
+ comment = response.comments.first
90
+ comment.id.should == 2289139
91
+ comment.creation_date.should == 1266949196
92
+ comment.post_id.should == 2320184
93
+ comment.post_type.should == "answer"
94
+ comment.score.should be_zero
95
+ comment.body.should == "@Josh - why not use a pagemethod then? You can just pass back the selected value and then your dependent picklist can use that value to populate itself. Might mean you need to change your approach, but less stuff goes down the wire this way."
96
+
97
+ comment.owner.id.should == 77814
98
+ comment.owner.user_type.should == "registered"
99
+ comment.owner.display_name.should == "nickyt"
100
+ comment.owner.reputation.should == 1130
101
+ comment.owner.email_hash.should == "243668a44dc257d64fa88656beb94469"
102
+
103
+ comment.mentioned_user.id.should == 549
104
+ comment.mentioned_user.user_type.should == "registered"
105
+ comment.mentioned_user.display_name.should == "Josh Kodroff"
106
+ comment.mentioned_user.reputation.should == 1542
107
+ comment.mentioned_user.email_hash.should == "9e7ef08258f04dab37b43842d261aea8"
108
+ end
58
109
  end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe StackExchange::StackOverflow::Question do
4
+
5
+ it 'should return a question identified by its id (without body)' do
6
+ question = StackOverflow::Question.find 1234
7
+ question.id.should == 1234
8
+ question.answer_count.should == 6
9
+ question.tags.should == ['csla']
10
+ question.creation_date.should == 1217857235
11
+ question.last_activity_date.should == 1236665990
12
+ question.up_vote_count.should == 2
13
+ question.down_vote_count.should be_zero
14
+ question.view_count.should == 1081
15
+ question.score.should == 2
16
+ question.community_owned.should be_false
17
+ question.accepted_answer_id.should == 1239
18
+ question.favorite_count.should == 1
19
+ question.question_timeline_url.should == "/questions/1234/timeline"
20
+ question.question_comments_url.should == "/questions/1234/comments"
21
+ question.question_answers_url.should == "/questions/1234/answers"
22
+
23
+ question.owner.id.should == 296
24
+ question.owner.user_type.should == "registered"
25
+ question.owner.display_name.should == "jdecuyper"
26
+ question.owner.reputation.should == 1189
27
+ question.owner.email_hash.should == "21ae3e5f2968bc957b7a6fa709bea2a0"
28
+
29
+ question.answers.should be_instance_of Array
30
+ question.answers.size.should == 6
31
+ question.title.should == "CSLA Master Class"
32
+ question.body.should be_nil
33
+ end
34
+
35
+ it 'should include body when using :query => { :body => true }' do
36
+ question = StackOverflow::Question.find 1234, :query => { :body => true }
37
+ question.body.should == "<p>Hi guys!\r\nAs anyone ever assisted the CSLA Master Class from Rockford Lhotka? (<a href=\"http://www.dunntraining.com/training/cslamasterclass.htm\" rel=\"nofollow\">www</a>).\r\n<br><br>\r\nIt seems a good way to enforce my OO knowledge in the asp.net field, but since I have to consider the flight to Atlanta and the course's price ($ 2.500), I'm not convinced yet. <br>\r\n<br>\r\nAlso, I could barrely find any feedback on the web.<br><br>\r\nCould anyone share some experience or comments?<br><br>\r\nThanks a lot. </p>"
38
+ end
39
+
40
+ it 'should find a question identified by its user_id' do
41
+ response = StackOverflow::Question.find_by_user_id 333
42
+ response.page.should == 1
43
+ response.pagesize.should == 30
44
+ question = response.questions.first
45
+ question.tags.should == ['c++', 'gcc']
46
+ question.answer_count.should == 3
47
+ question.accepted_answer_id.should == 267415
48
+ question.favorite_count.should == 1
49
+ question.question_timeline_url.should == "/questions/267248/timeline"
50
+ question.question_comments_url.should == "/questions/267248/comments"
51
+ question.question_answers_url.should == "/questions/267248/answers"
52
+ question.id.should == 267248
53
+ question.creation_date.should == 1225930514
54
+ question.last_activity_date.should == 1225938787
55
+ question.up_vote_count.should == 2
56
+ question.down_vote_count.should be_zero
57
+ question.view_count.should == 266
58
+ question.score.should == 2
59
+ question.community_owned.should be_false
60
+ question.title.should == "Getting rid of gcc shift by negative warning"
61
+ question.owner.id.should == 333
62
+ end
63
+ end
@@ -30,7 +30,6 @@ describe StackOverflow::Client do
30
30
  describe 'when using #config for configuration setup' do
31
31
  before do
32
32
  @client = StackOverflow::Client.new
33
- @old_url = @client.url
34
33
 
35
34
  StackOverflow::Client.config do |options|
36
35
  options.url = 'http://test.it'
@@ -40,9 +39,8 @@ describe StackOverflow::Client do
40
39
  end
41
40
 
42
41
  after do
43
- StackOverflow::Client.config do |options|
44
- options.url = @old_url
45
- end
42
+ # reset to default configuration
43
+ StackOverflow::Client.config
46
44
  end
47
45
 
48
46
  it 'should modify the api url' do
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ require 'spec'
8
8
  require 'pp'
9
9
 
10
10
  include StackExchange
11
+ StackExchange::StackOverflow::Client.config
11
12
  FIXTURES_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
12
13
  ROOT_URL = [StackOverflow::Client::URL.chomp('/'), StackOverflow::Client::API_VERSION].join '/'
13
14
  FakeWeb.allow_net_connect = false
@@ -35,8 +36,13 @@ register(:url => 'badges/tags/', :body => 'badges_tag_based')
35
36
  register(:url => 'answers/666/', :body => 'answers_by_id')
36
37
  register(:url => 'answers/555/', :body => 'answer_with_comments')
37
38
  register(:url => 'comments/1/', :body => 'comments')
38
- register(:url => 'users/1/answers/', :body => 'users_answers')
39
39
  register(:url => 'questions/549/answers/', :body => 'answers_by_question_id')
40
40
  register(:url => 'questions/549/comments/', :body => 'comments_by_question_id')
41
+ register(:url => 'users/333/questions/', :body => 'questions_by_user_id')
42
+ register(:url => 'questions/1234/', :body => 'question_by_id')
43
+ register(:url => 'questions/1234/?body=true', :body => 'question_by_id_with_body')
44
+ register(:url => 'users/1/answers/', :body => 'users_answers')
41
45
  register(:url => 'users/555/', :body => 'users_by_id')
42
46
  register(:url => 'users/549/comments/', :body => 'comments_by_user_id')
47
+ register(:url => 'users/549/mentioned/', :body => 'comments_by_mentioned_user_id')
48
+ register(:url => 'users/77814/comments/549/', :body => 'comments_by_user_to_mentioned_user')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dalto Curvelano Junior
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-28 00:00:00 -03:00
17
+ date: 2010-05-31 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -28,38 +28,69 @@ extra_rdoc_files: []
28
28
 
29
29
  files:
30
30
  - pilha.gemspec
31
+ - lib/pilha.rb
31
32
  - lib/pilha/stack_overflow/badge.rb
32
33
  - lib/pilha/stack_overflow/statistics.rb
33
34
  - lib/pilha/stack_overflow/user.rb
34
35
  - lib/pilha/stack_overflow/comment.rb
35
36
  - lib/pilha/stack_overflow/answer.rb
36
- - lib/pilha.rb
37
- - spec/fixtures/stats.json
38
- - spec/fixtures/stats.json.gz
39
- - spec/fixtures/badges.json
40
- - spec/fixtures/badges.json.gz
41
- - spec/fixtures/badges_by_id.json
42
- - spec/fixtures/badges_by_id.json.gz
43
- - spec/fixtures/badges_by_id_page2.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
37
+ - lib/pilha/stack_overflow/question.rb
38
+ - lib/pilha/stack_overflow/base.rb
55
39
  - spec/pilha/stack_overflow/badge_spec.rb
56
40
  - spec/pilha/stack_overflow/stack_overflow_spec.rb
57
41
  - spec/pilha/stack_overflow/statistics_spec.rb
58
42
  - spec/pilha/stack_overflow/user_spec.rb
59
43
  - spec/pilha/stack_overflow/comment_spec.rb
60
44
  - spec/pilha/stack_overflow/answer_spec.rb
45
+ - spec/pilha/stack_overflow/question_spec.rb
61
46
  - spec/spec.opts
62
47
  - spec/spec_helper.rb
48
+ - spec/fixtures/comments.json.gz
49
+ - spec/fixtures/comments_by_user_id_to_mentioned_user_id.json.gz
50
+ - spec/fixtures/question_by_user_id.json.gz
51
+ - spec/fixtures/users_by_id.json
52
+ - spec/fixtures/badges.json
53
+ - spec/fixtures/comments_by_user_to_mentioned_user.json
54
+ - spec/fixtures/answer_with_comments.json
55
+ - spec/fixtures/answers_by_id.json.gz
56
+ - spec/fixtures/stats.json
57
+ - spec/fixtures/answer_with_comments.json.gz
58
+ - spec/fixtures/badges_name.json
59
+ - spec/fixtures/answers_by_question_id.json.gz
60
+ - spec/fixtures/badges_tag_based.json
61
+ - spec/fixtures/badges.json.gz
62
+ - spec/fixtures/comments.json
63
+ - spec/fixtures/question_by_id.json
64
+ - spec/fixtures/question_by_id_with_body.json.gz
65
+ - spec/fixtures/question_by_id.json.gz
66
+ - spec/fixtures/comments_by_user_to_mentioned_user_id.json.gz
67
+ - spec/fixtures/answer_comments.json
68
+ - spec/fixtures/questions.json
69
+ - spec/fixtures/comments_by_question_id.json.gz
70
+ - spec/fixtures/comments_by_user_to_mentioned_user.json.gz
71
+ - spec/fixtures/answers_by_id.json
72
+ - spec/fixtures/users_by_id.json.gz
73
+ - spec/fixtures/stats.json.gz
74
+ - spec/fixtures/users.json
75
+ - spec/fixtures/comments_by_mentioned_user_id.json.gz
76
+ - spec/fixtures/comments_by_user_id.json.gz
77
+ - spec/fixtures/users_answers.json
78
+ - spec/fixtures/questions_by_user_id.json.gz
79
+ - spec/fixtures/users_answers.json.gz
80
+ - spec/fixtures/badges_by_id.json
81
+ - spec/fixtures/comments_by_question_id.json
82
+ - spec/fixtures/badges_by_id.json.gz
83
+ - spec/fixtures/badges_tag_based.json.gz
84
+ - spec/fixtures/comments_by_user_id.json
85
+ - spec/fixtures/questions.json.gz
86
+ - spec/fixtures/questions_by_user_id.json
87
+ - spec/fixtures/question_by_id_with_body.json
88
+ - spec/fixtures/answers_by_question_id.json
89
+ - spec/fixtures/questions.part
90
+ - spec/fixtures/comments_by_mentioned_user_id.json
91
+ - spec/fixtures/badges_by_id_page2.json.gz
92
+ - spec/fixtures/badges_name.json.gz
93
+ - spec/fixtures/badges_by_id_page2.json
63
94
  has_rdoc: true
64
95
  homepage: http://github.com/dlt/pilha
65
96
  licenses: []