rubyoverflow 0.5 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -11
- data/RELEASENOTES +97 -1
- data/Rakefile +49 -7
- data/VERSION +1 -1
- data/lib/rubyoverflow.rb +92 -18
- data/lib/rubyoverflow/answer.rb +61 -0
- data/lib/rubyoverflow/answers.rb +60 -0
- data/lib/rubyoverflow/apiSite.rb +32 -0
- data/lib/rubyoverflow/apiSites.rb +25 -0
- data/lib/rubyoverflow/apiVersion.rb +6 -0
- data/lib/rubyoverflow/badge.rb +44 -0
- data/lib/rubyoverflow/badgeCounts.rb +22 -0
- data/lib/rubyoverflow/badges.rb +59 -0
- data/lib/rubyoverflow/base.rb +76 -0
- data/lib/rubyoverflow/comment.rb +41 -0
- data/lib/rubyoverflow/comments.rb +115 -0
- data/lib/rubyoverflow/errors.rb +17 -0
- data/lib/rubyoverflow/pagedBase.rb +27 -0
- data/lib/rubyoverflow/pagedDash.rb +7 -0
- data/lib/rubyoverflow/postTimelineEvent.rb +93 -0
- data/lib/rubyoverflow/postTimelineEvents.rb +39 -0
- data/lib/rubyoverflow/question.rb +110 -0
- data/lib/rubyoverflow/questions.rb +104 -0
- data/lib/rubyoverflow/repChange.rb +34 -0
- data/lib/rubyoverflow/repChanges.rb +41 -0
- data/lib/rubyoverflow/revision.rb +62 -0
- data/lib/rubyoverflow/revisions.rb +52 -0
- data/lib/rubyoverflow/statistics.rb +57 -0
- data/lib/rubyoverflow/styling.rb +19 -0
- data/lib/rubyoverflow/tag.rb +27 -0
- data/lib/rubyoverflow/tags.rb +46 -0
- data/lib/rubyoverflow/user.rb +181 -0
- data/lib/rubyoverflow/userTimelineEvent.rb +43 -0
- data/lib/rubyoverflow/userTimelineEvents.rb +35 -0
- data/lib/rubyoverflow/users.rb +67 -18
- data/test/apiKey.rb +5 -0
- data/test/helper.rb +159 -0
- data/test/test_answer.rb +20 -0
- data/test/test_answers.rb +32 -0
- data/test/test_badge.rb +18 -0
- data/test/test_badges.rb +30 -0
- data/test/test_base.rb +63 -0
- data/test/test_statistics.rb +26 -0
- data/test/test_user.rb +56 -0
- data/test/test_users.rb +37 -0
- metadata +122 -87
- data/.gitignore +0 -4
- data/.rvmrc +0 -47
- data/.travis.yml +0 -5
- data/Gemfile +0 -3
- data/lib/rubyoverflow/sites.rb +0 -20
- data/lib/rubyoverflow/version.rb +0 -3
- data/rubyoverflow.gemspec +0 -26
- data/spec/sites_spec.rb +0 -18
- data/spec/spec_helper.rb +0 -3
- data/spec/users_spec.rb +0 -23
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class PagedBase < Base
|
3
|
+
attr_reader :total, :pagesize, :page, :request_path, :query_parameters
|
4
|
+
|
5
|
+
def initialize(dash, request_path)
|
6
|
+
@total = dash.total
|
7
|
+
@page = dash.page
|
8
|
+
@pagesize = dash.pagesize
|
9
|
+
@request_path,@query_parameters = find_parse_querystring(request_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def next_page_parameters()
|
13
|
+
temp = @query_parameters
|
14
|
+
if @page.respond_to?(:to_int)
|
15
|
+
temp['page'] = @page.to_i + 1
|
16
|
+
else
|
17
|
+
temp["page"] = 2
|
18
|
+
end
|
19
|
+
return temp
|
20
|
+
end
|
21
|
+
|
22
|
+
def perform_next_page_request()
|
23
|
+
request(@request_path,next_page_parameters)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class PostTimelineEvent < Base
|
3
|
+
attr_reader :timeline_type
|
4
|
+
attr_reader :question_id
|
5
|
+
attr_reader :post_id
|
6
|
+
attr_reader :comment_id
|
7
|
+
attr_reader :revision_guid
|
8
|
+
attr_reader :creation_date
|
9
|
+
attr_reader :user
|
10
|
+
attr_reader :owner
|
11
|
+
attr_reader :action
|
12
|
+
attr_reader :post_revision_url
|
13
|
+
attr_reader :post_url
|
14
|
+
attr_reader :post_comment_url
|
15
|
+
|
16
|
+
def initialize(hash, request_path = '')
|
17
|
+
dash = PostTimelineEventDash.new hash
|
18
|
+
|
19
|
+
@timeline_type = dash.timeline_type
|
20
|
+
@post_id = dash.post_id
|
21
|
+
@comment_id = dash.comment_id
|
22
|
+
@question_id = dash.question_id
|
23
|
+
@revision_guid = dash.revision_guid
|
24
|
+
@creation_date = dash.creation_date
|
25
|
+
@user = User.new dash.user if dash.user
|
26
|
+
@owner = User.new dash.owner if dash.owner
|
27
|
+
@action = dash.action
|
28
|
+
@post_revision_url = dash.post_revision_url
|
29
|
+
@post_url = dash.post_url
|
30
|
+
@post_comment_url = dash.post_comment_url
|
31
|
+
end
|
32
|
+
|
33
|
+
#Gets the post associated with this postTimelineEvent
|
34
|
+
def get_post(parameters={})
|
35
|
+
if @post_url
|
36
|
+
hash,url = request(@post_url, parameters)
|
37
|
+
if @post_url.include? 'question'
|
38
|
+
Questions.new hash, url
|
39
|
+
elsif @post_url.include? 'answer'
|
40
|
+
Answers.new hash, url
|
41
|
+
end
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#Gets the question that this postTimleineEvent belongs to
|
48
|
+
def get_parent_question(parameters={})
|
49
|
+
if @question_id
|
50
|
+
Questions.retrieve_by_id @question_id
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
#Gets the revision associated with this postTimelineEvent
|
58
|
+
def get_post_revision(parameters={})
|
59
|
+
if @post_revision_url
|
60
|
+
hash,url = request(@post_revision_url, parameters)
|
61
|
+
Revisions.new hash, url
|
62
|
+
else
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#Gets the comment associated with this postTimelineEvent
|
68
|
+
def get_post_comment(parameters={})
|
69
|
+
if @post_comment_url
|
70
|
+
hash,url = request(@post_comment_url, parameters)
|
71
|
+
Comments.new hash, url
|
72
|
+
else
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
class PostTimelineEventDash < BaseDash
|
80
|
+
property :timeline_type
|
81
|
+
property :post_id
|
82
|
+
property :question_id
|
83
|
+
property :comment_id
|
84
|
+
property :revision_guid
|
85
|
+
property :creation_date
|
86
|
+
property :user
|
87
|
+
property :owner
|
88
|
+
property :action
|
89
|
+
property :post_revision_url
|
90
|
+
property :post_url
|
91
|
+
property :post_comment_url
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class PostTimelineEvents < PagedBase
|
3
|
+
attr_reader :post_timelines
|
4
|
+
|
5
|
+
def initialize(hash, request_path = '')
|
6
|
+
dash = PostTimelineEventsDash.new hash
|
7
|
+
super(dash, request_path)
|
8
|
+
|
9
|
+
@post_timelines = Array.new
|
10
|
+
dash.post_timelines.each {|postTimeHash| @post_timelines.push(PostTimelineEvent.new postTimeHash)}
|
11
|
+
end
|
12
|
+
|
13
|
+
#Retrieves the next set of PostTimelineEvents using the same parameters used to retrieve the current set
|
14
|
+
def get_next_set
|
15
|
+
hash,url = perform_next_page_request
|
16
|
+
PostTimelineEvents.new hash,url
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
#Retrieve a set of PostTimelineEvent for a set of question(s) by their id(s)
|
22
|
+
#
|
23
|
+
#id can be an int, string, or an array of ints or strings
|
24
|
+
#
|
25
|
+
#Maps to 'questions/{id}/timeline'
|
26
|
+
def retrieve_by_question(id, parameters = {})
|
27
|
+
id = convert_to_id_list(id)
|
28
|
+
|
29
|
+
hash, url = request('questions/' + id.to_s + '/timeline', parameters)
|
30
|
+
PostTimelineEvents.new hash, url
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class PostTimelineEventsDash < PagedDash
|
37
|
+
property :post_timelines
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Question < Base
|
3
|
+
attr_reader :tags, :answer_count, :answers, :accepted_answer_id, :favorite_count, :bounty_closes_date,
|
4
|
+
:bounty_amount, :closed_date, :closed_reason, :question_timeline_url, :question_comments_url,
|
5
|
+
:question_answers_url, :question_id, :locked_date, :owner, :creation_date, :last_edit_date,
|
6
|
+
:last_activity_date, :up_vote_count, :down_vote_count, :view_count, :score, :community_owned,
|
7
|
+
:title, :body, :comments, :migrated, :protected_date
|
8
|
+
|
9
|
+
def initialize(hash, request_path = '')
|
10
|
+
dash = QuestionDash.new hash
|
11
|
+
|
12
|
+
@tags = Array.new
|
13
|
+
@comments = Array.new
|
14
|
+
@answers = Array.new
|
15
|
+
|
16
|
+
dash.tags.each {|tag| @tags.push(tag)} if dash.tags
|
17
|
+
dash.comments.each {|commentHash| @comment.push(Comment.new commentHash)} if dash.comments
|
18
|
+
dash.answers.each {|answerHash| @comment.push(Answer.new answerHash)} if dash.answers
|
19
|
+
|
20
|
+
@migrated = dash.migrated
|
21
|
+
@answer_count = dash.answer_count
|
22
|
+
@accepted_answer_id = dash.accepted_answer_id
|
23
|
+
@favorite_count = dash.favorite_count
|
24
|
+
@bounty_closes_date = dash.bounty_closes_date
|
25
|
+
@bounty_amount = dash.bounty_amount
|
26
|
+
@closed_date = dash.closed_date
|
27
|
+
@closed_reason = dash.closed_reason
|
28
|
+
@question_timeline_url = dash.question_timeline_url
|
29
|
+
@question_comments_url = dash.question_comments_url
|
30
|
+
@question_answers_url = dash.question_answers_url
|
31
|
+
@question_id = dash.question_id
|
32
|
+
@locked_date = dash.locked_date
|
33
|
+
@owner = User.new dash.owner if dash.owner
|
34
|
+
@creation_date = dash.creation_date
|
35
|
+
@last_edit_date = dash.last_edit_date
|
36
|
+
@last_activity_date = dash.last_activity_date
|
37
|
+
@up_vote_count = dash.up_vote_count
|
38
|
+
@down_vote_count = dash.down_vote_count
|
39
|
+
@view_count = dash.view_count
|
40
|
+
@score = dash.score
|
41
|
+
@community_owned = dash.community_owned
|
42
|
+
@title = dash.title
|
43
|
+
@body = dash.body
|
44
|
+
@protected_date = dash.protected_date
|
45
|
+
end
|
46
|
+
|
47
|
+
#Gets the comments made on the question
|
48
|
+
def get_comments(parameters = {})
|
49
|
+
if @question_comments_url
|
50
|
+
hash,url =request(@question_comments_url, parameters)
|
51
|
+
Comments.new hash, url
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#Gets the answers posted to the question
|
58
|
+
def get_answers(parameters = {})
|
59
|
+
if @question_answers_url
|
60
|
+
hash,url =request(@question_answers_url, parameters)
|
61
|
+
Answers.new hash, url
|
62
|
+
else
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#Gets the timeline for the question
|
68
|
+
def get_timeline(parameters = {})
|
69
|
+
if @question_timeline_url
|
70
|
+
hash,url =request(@question_timeline_url, parameters)
|
71
|
+
PostTimelineEvents.new hash, url
|
72
|
+
else
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
class QuestionDash < BaseDash
|
81
|
+
property :tags
|
82
|
+
property :answer_count
|
83
|
+
property :answers
|
84
|
+
property :accepted_answer_id
|
85
|
+
property :favorite_count
|
86
|
+
property :bounty_closes_date
|
87
|
+
property :bounty_amount
|
88
|
+
property :closed_date
|
89
|
+
property :closed_reason
|
90
|
+
property :question_timeline_url
|
91
|
+
property :question_comments_url
|
92
|
+
property :question_answers_url
|
93
|
+
property :question_id
|
94
|
+
property :locked_date
|
95
|
+
property :owner
|
96
|
+
property :creation_date
|
97
|
+
property :last_edit_date
|
98
|
+
property :last_activity_date
|
99
|
+
property :up_vote_count
|
100
|
+
property :down_vote_count
|
101
|
+
property :view_count
|
102
|
+
property :score
|
103
|
+
property :community_owned
|
104
|
+
property :title
|
105
|
+
property :body
|
106
|
+
property :comments
|
107
|
+
property :migrated
|
108
|
+
property :protected_date
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Questions < PagedBase
|
3
|
+
attr_reader :questions
|
4
|
+
|
5
|
+
def initialize(hash, request_path = '')
|
6
|
+
dash = QuestionsDash.new hash
|
7
|
+
|
8
|
+
@questions = Array.new
|
9
|
+
dash.questions.each {|questionHash| @questions.push(Question.new questionHash)}
|
10
|
+
|
11
|
+
super(dash,request_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
#Retrieves the next set of questions using the same parameters used to retrieve the current set
|
15
|
+
def get_next_set
|
16
|
+
hash,url = perform_next_page_request
|
17
|
+
Questions.new hash,url
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
#Retrieves all questions using the parameters provided
|
23
|
+
#
|
24
|
+
#Maps to '/questions'
|
25
|
+
def retrieve_all(parameters = {})
|
26
|
+
hash, url = request('questions',parameters)
|
27
|
+
Questions.new hash, url
|
28
|
+
end
|
29
|
+
|
30
|
+
#Retrieves a set of questions by their id(s)
|
31
|
+
#
|
32
|
+
#id can be an int, string, or an array of ints or strings
|
33
|
+
#
|
34
|
+
#Maps to '/questions/{id}'
|
35
|
+
def retrieve_by_id(id, parameters = {})
|
36
|
+
id = convert_to_id_list(id)
|
37
|
+
|
38
|
+
hash, url = request('questions/' + id.to_s, parameters)
|
39
|
+
Questions.new hash, url
|
40
|
+
end
|
41
|
+
|
42
|
+
#Retrieves a set of questions by their tag(s)
|
43
|
+
#
|
44
|
+
#tag can be a string or an array of strings, tag(s) should be URL Encoded
|
45
|
+
#
|
46
|
+
#Maps to '/questions/tagged/{tags}
|
47
|
+
def retrieve_by_tag(tags, parameters = {})
|
48
|
+
tags = convert_to_id_list(tags)
|
49
|
+
parameters['tagged'] = tags
|
50
|
+
hash, url = request('questions/', parameters)
|
51
|
+
Questions.new hash, url
|
52
|
+
end
|
53
|
+
|
54
|
+
#Retieves a set of unanswered questions using the parameters provided
|
55
|
+
#
|
56
|
+
#Maps to '/questions/unanswered'
|
57
|
+
def retrieve_unanswered(parameters = {})
|
58
|
+
hash, url = request('questions/unanswered', parameters)
|
59
|
+
Questions.new hash, url
|
60
|
+
end
|
61
|
+
|
62
|
+
#Retrieves a set of favorite questions for user(s) by the users' id(s)
|
63
|
+
#
|
64
|
+
#user_id can be an int, string, or an array of ints or strings
|
65
|
+
#
|
66
|
+
#Maps to '/users/{id}/favorites
|
67
|
+
def retrieve_favorites(user_id, parameters = {})
|
68
|
+
user_id = convert_to_id_list(user_id)
|
69
|
+
|
70
|
+
hash, url = request('users/'+user_id.to_s+'/favorites', parameters)
|
71
|
+
Questions.new hash, url
|
72
|
+
end
|
73
|
+
|
74
|
+
#Retrieve question summary for user(s) by their id(s)
|
75
|
+
#
|
76
|
+
#id can be an int, string, or an array of ints or strings
|
77
|
+
#
|
78
|
+
#Maps to '/users/{id}/questions'
|
79
|
+
def retrieve_by_user(id, parameters = {})
|
80
|
+
id = convert_to_id_list(id)
|
81
|
+
|
82
|
+
hash, url = request('users/'+id.to_s+'/questions', parameters)
|
83
|
+
Questions.new hash, url
|
84
|
+
end
|
85
|
+
|
86
|
+
#Searches questions. One of intitle, tagged, or nottagged must be set.
|
87
|
+
#
|
88
|
+
#Example: Questions.search({:tagged=>'c%23',:nottagged=>'sql;asp.net'})
|
89
|
+
#
|
90
|
+
#Maps to '/search'
|
91
|
+
def search(parameters = {})
|
92
|
+
hash, url = request('search', parameters)
|
93
|
+
Questions.new hash, url
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class QuestionsDash < PagedDash
|
102
|
+
property :questions
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class RepChange
|
3
|
+
attr_reader :user_id
|
4
|
+
attr_reader :post_id
|
5
|
+
attr_reader :post_type
|
6
|
+
attr_reader :title
|
7
|
+
attr_reader :positive_rep
|
8
|
+
attr_reader :negative_rep
|
9
|
+
attr_reader :on_date
|
10
|
+
|
11
|
+
def initialize(hash, request_path = '')
|
12
|
+
dash = RepChangeDash.new hash
|
13
|
+
|
14
|
+
@user_id = dash.user_id
|
15
|
+
@post_id = dash.post_id
|
16
|
+
@post_type = dash.post_type
|
17
|
+
@title = dash.title
|
18
|
+
@positive_rep = dash.positive_rep
|
19
|
+
@negative_rep = dash.negative_rep
|
20
|
+
@on_date = dash.on_date
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class RepChangeDash <BaseDash
|
26
|
+
property :user_id
|
27
|
+
property :post_id
|
28
|
+
property :post_type
|
29
|
+
property :title
|
30
|
+
property :positive_rep
|
31
|
+
property :negative_rep
|
32
|
+
property :on_date
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class RepChanges < PagedBase
|
3
|
+
|
4
|
+
attr_reader :rep_changes
|
5
|
+
|
6
|
+
def initialize(hash, request_path = '')
|
7
|
+
dash = RepChangesDash.new hash
|
8
|
+
super(dash, request_path)
|
9
|
+
|
10
|
+
@rep_changes = Array.new
|
11
|
+
dash.rep_changes.each{|repHash| @rep_changes.push(RepChange.new repHash)}
|
12
|
+
end
|
13
|
+
|
14
|
+
#Retrieves the next set of RepChanges using the same parameters used to retrieve the current set
|
15
|
+
def get_next_set
|
16
|
+
hash,url = perform_next_page_request
|
17
|
+
RepChanges.new hash,url
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
#Retrieves all the rep_changes for a set of user(s) by their id(s)
|
23
|
+
#
|
24
|
+
#id can be an int, string, or an array of ints or strings
|
25
|
+
#
|
26
|
+
#Maps to '/users{id}/reputation'
|
27
|
+
def retrieve_by_user(id, parameters={})
|
28
|
+
id = convert_to_id_list(id)
|
29
|
+
hash, url = request('/users/' + id.to_s + '/reputation', parameters)
|
30
|
+
RepChanges.new hash, url
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class RepChangesDash < PagedDash
|
38
|
+
property :rep_changes
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|