rubyoverflow 0.5 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,62 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Revision
|
3
|
+
attr_reader :body
|
4
|
+
attr_reader :comment
|
5
|
+
attr_reader :creation_date
|
6
|
+
attr_reader :is_question
|
7
|
+
attr_reader :is_rollback
|
8
|
+
attr_reader :last_body
|
9
|
+
attr_reader :last_title
|
10
|
+
attr_reader :last_tags
|
11
|
+
attr_reader :revision_guid
|
12
|
+
attr_reader :revision_number
|
13
|
+
attr_reader :tags
|
14
|
+
attr_reader :title
|
15
|
+
attr_reader :revision_type
|
16
|
+
attr_reader :set_community_wiki
|
17
|
+
attr_reader :user
|
18
|
+
attr_reader :post_id
|
19
|
+
|
20
|
+
def initialize(hash, request_path = '')
|
21
|
+
dash = RevisionDash.new hash
|
22
|
+
|
23
|
+
@body = dash.body
|
24
|
+
@comment = dash.comment
|
25
|
+
@creation_date = dash.creation_date
|
26
|
+
@is_question = dash.is_question
|
27
|
+
@is_rollback = dash.is_rollback
|
28
|
+
@last_body = dash.last_body
|
29
|
+
@last_title = dash.last_title
|
30
|
+
@last_tags = dash.last_tags
|
31
|
+
@revision_guid = dash.revision_guid
|
32
|
+
@revision_number = dash.revision_number
|
33
|
+
@tags = dash.tags
|
34
|
+
@title = dash.title
|
35
|
+
@revision_type = dash.revision_type
|
36
|
+
@set_community_wiki = dash.set_community_wiki
|
37
|
+
@user = User.new dash.user if dash.user
|
38
|
+
@post_id = dash.post_id
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
class RevisionDash < BaseDash
|
45
|
+
property :body
|
46
|
+
property :comment
|
47
|
+
property :creation_date
|
48
|
+
property :is_question
|
49
|
+
property :is_rollback
|
50
|
+
property :last_body
|
51
|
+
property :last_title
|
52
|
+
property :last_tags
|
53
|
+
property :revision_guid
|
54
|
+
property :revision_number
|
55
|
+
property :tags
|
56
|
+
property :title
|
57
|
+
property :revision_type
|
58
|
+
property :set_community_wiki
|
59
|
+
property :user
|
60
|
+
property :post_id
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Revisions < PagedBase
|
3
|
+
attr_reader :revisions
|
4
|
+
|
5
|
+
def initialize(hash, request_path = '')
|
6
|
+
dash = RevisionsDash.new hash
|
7
|
+
super(dash, request_path)
|
8
|
+
|
9
|
+
@revisions = Array.new
|
10
|
+
dash.revisions.each{|revisionHash| @revisions.push(Revision.new revisionHash)}
|
11
|
+
end
|
12
|
+
|
13
|
+
#Retrieves the next set of revisions using the same parameters used to retrieve the current set
|
14
|
+
def get_next_set
|
15
|
+
hash,url = perform_next_page_request
|
16
|
+
Revisions.new hash,url
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
#Retrieves the post history of a set of post(s) by their id(s)
|
22
|
+
#
|
23
|
+
#id can be an int, string or an array of ints or strings
|
24
|
+
#
|
25
|
+
#Maps to 'revisions/{id}'
|
26
|
+
def retrieve_by_post(id, parameters = {})
|
27
|
+
id = convert_to_id_list(id)
|
28
|
+
hash, url = request('/revisions/'+id.to_s, parameters)
|
29
|
+
Revisions.new hash, url
|
30
|
+
end
|
31
|
+
|
32
|
+
#Retrieves a specific post revision by post id and revision guid
|
33
|
+
#
|
34
|
+
#id can be an int, string or an array of ints or strings
|
35
|
+
#
|
36
|
+
#revisionguid must be a string in 8-4-4-4-12 format
|
37
|
+
#
|
38
|
+
#Maps to 'revisions/{id}'
|
39
|
+
def retrieve_post_revision(id, revisionguid, parameters = {})
|
40
|
+
id = convert_to_id_list(id)
|
41
|
+
hash, url = request('/revisions/'+id.to_s + '/' + revisionguid, parameters)
|
42
|
+
Revisions.new hash, url
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class RevisionsDash < PagedDash
|
50
|
+
property :revisions
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Statistics < Base
|
3
|
+
|
4
|
+
attr_reader :total_questions, :total_badges, :total_unanswered, :total_votes, :total_comments, :total_answers, :site,
|
5
|
+
:total_users, :questions_per_minute, :answers_per_minute, :badges_per_minute, :views_per_day, :api_version, :total_accepted
|
6
|
+
|
7
|
+
def initialize(hash, request_path = '')
|
8
|
+
dash = StatisticsDash.new hash
|
9
|
+
|
10
|
+
@total_questions = dash.total_questions
|
11
|
+
@total_accepted = dash.total_accepted
|
12
|
+
@total_badges = dash.total_badges
|
13
|
+
@total_unanswered = dash.total_unanswered
|
14
|
+
@total_votes = dash.total_votes
|
15
|
+
@total_comments = dash.total_comments
|
16
|
+
@total_answers = dash.total_answers
|
17
|
+
@total_users = dash.total_users
|
18
|
+
@questions_per_minute = dash.questions_per_minute
|
19
|
+
@answers_per_minute = dash.answers_per_minute
|
20
|
+
@badges_per_minute = dash.badges_per_minute
|
21
|
+
@views_per_day = dash.views_per_day
|
22
|
+
@site = ApiSite.new dash.site
|
23
|
+
@api_version = ApiVersion.new dash.api_version
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
#Retrieves the stats for the domain
|
30
|
+
#
|
31
|
+
#Maps to 'stats'
|
32
|
+
def retrieve
|
33
|
+
hash, url = request('stats')
|
34
|
+
Statistics.new hash['statistics'].first, url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
class StatisticsDash < BaseDash
|
42
|
+
property :total_questions
|
43
|
+
property :total_badges
|
44
|
+
property :total_unanswered
|
45
|
+
property :total_votes
|
46
|
+
property :total_comments
|
47
|
+
property :total_answers
|
48
|
+
property :total_users
|
49
|
+
property :total_accepted
|
50
|
+
property :questions_per_minute
|
51
|
+
property :answers_per_minute
|
52
|
+
property :badges_per_minute
|
53
|
+
property :views_per_day
|
54
|
+
property :api_version
|
55
|
+
property :site
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Styling
|
3
|
+
attr_reader :link_color, :tag_foreground_color ,:tag_background_color
|
4
|
+
|
5
|
+
def initialize(hash)
|
6
|
+
dash = StylingDash.new hash
|
7
|
+
@link_color = dash.link_color
|
8
|
+
@tag_background_color = dash.tag_background_color
|
9
|
+
@tag_foreground_color = dash.tag_foreground_color
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class StylingDash < BaseDash
|
15
|
+
property :link_color
|
16
|
+
property :tag_foreground_color
|
17
|
+
property :tag_background_color
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Tag
|
3
|
+
attr_reader :name
|
4
|
+
attr_reader :count
|
5
|
+
attr_reader :restricted_to
|
6
|
+
attr_reader :fulfills_required
|
7
|
+
attr_reader :user_id
|
8
|
+
|
9
|
+
def initialize(hash, request_path = '')
|
10
|
+
dash = TagDash.new hash
|
11
|
+
@name = dash.name
|
12
|
+
@count = dash.count
|
13
|
+
@restricted_to = dash.restricted_to
|
14
|
+
@fulfills_required = dash.fulfills_required
|
15
|
+
@user_id = dash.user_id
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class TagDash < BaseDash
|
21
|
+
property :name
|
22
|
+
property :count
|
23
|
+
property :restricted_to
|
24
|
+
property :fulfills_required
|
25
|
+
property :user_id
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Tags < PagedBase
|
3
|
+
|
4
|
+
attr_reader :tags
|
5
|
+
|
6
|
+
def initialize(hash, request_path = '')
|
7
|
+
dash = TagsDash.new hash
|
8
|
+
@tags = Array.new
|
9
|
+
dash.tags.each{ |tagHash| @tags.push(Tag.new tagHash)}
|
10
|
+
|
11
|
+
super(dash, request_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
#Retrieves the next set of tags using the same parameters used to retrieve the current set
|
15
|
+
def get_next_set
|
16
|
+
hash,url = perform_next_page_request
|
17
|
+
Tags.new hash,url
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
#Retrieves all of the tags
|
22
|
+
#
|
23
|
+
#Maps to '/tags/
|
24
|
+
def retrieve_all(parameters = {})
|
25
|
+
hash, url = request('tags', parameters)
|
26
|
+
Tags.new hash, url
|
27
|
+
end
|
28
|
+
|
29
|
+
#Retieves all of the tags assign to a set of users by their ids
|
30
|
+
#
|
31
|
+
#id can be an int, string, or an array of ints or strings
|
32
|
+
#
|
33
|
+
#Maps to 'users/{id}/tags'
|
34
|
+
def retrieve_by_user(id, parameters = {})
|
35
|
+
id = convert_to_id_list(id)
|
36
|
+
hash, url = request('users/'+id.to_s+'/tags',parameters)
|
37
|
+
Tags.new hash, url
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class TagsDash < PagedDash
|
43
|
+
property :tags
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class User < Base
|
3
|
+
|
4
|
+
attr_reader :user_id, :user_type, :creation_date, :display_name, :reputation, :email_hash, :age,
|
5
|
+
:last_access_date, :website_url, :location, :about_me, :question_count, :answer_count, :view_count,
|
6
|
+
:up_vote_count, :down_vote_count, :accept_rate, :user_questions_url, :user_answers_url, :user_favorites_url,
|
7
|
+
:user_tags_url, :user_badges_url, :user_timeline_url, :user_mentioned_url, :user_comments_url,
|
8
|
+
:user_reputation_url, :badge_counts, :timed_penalty_date, :association_id, :on_site
|
9
|
+
|
10
|
+
def initialize(hash, request_path = '')
|
11
|
+
dash = UserDash.new hash
|
12
|
+
|
13
|
+
@user_id = dash.user_id
|
14
|
+
@user_type = dash.user_type
|
15
|
+
@creation_date = dash.creation_date
|
16
|
+
@display_name = dash.display_name
|
17
|
+
@reputation = dash.reputation
|
18
|
+
@email_hash = dash.email_hash
|
19
|
+
@age = dash.age
|
20
|
+
@last_access_date = dash.last_access_date
|
21
|
+
@website_url = dash.website_url
|
22
|
+
@location = dash.location
|
23
|
+
@about_me = dash.about_me
|
24
|
+
@question_count = dash.question_count
|
25
|
+
@answer_count = dash.answer_count
|
26
|
+
@view_count = dash.view_count
|
27
|
+
@up_vote_count = dash.up_vote_count
|
28
|
+
@down_vote_count = dash.down_vote_count
|
29
|
+
@accept_rate = dash.accept_rate
|
30
|
+
@user_questions_url = dash.user_questions_url
|
31
|
+
@user_answers_url = dash.user_answers_url
|
32
|
+
@user_favorites_url = dash.user_favorites_url
|
33
|
+
@user_tags_url = dash.user_tags_url
|
34
|
+
@user_badges_url = dash.user_badges_url
|
35
|
+
@user_timeline_url = dash.user_timeline_url
|
36
|
+
@user_mentioned_url = dash.user_mentioned_url
|
37
|
+
@user_comments_url = dash.user_comments_url
|
38
|
+
@user_reputation_url = dash.user_reputation_url
|
39
|
+
@badge_counts = BadgeCounts.new dash.badge_counts if dash.badge_counts
|
40
|
+
@timed_penalty_date = dash.timed_penalty_date
|
41
|
+
@association_id = dash.association_id
|
42
|
+
@on_site = ApiSite.new dash.on_site if dash.on_site
|
43
|
+
end
|
44
|
+
|
45
|
+
def item_id
|
46
|
+
@user_id
|
47
|
+
end
|
48
|
+
|
49
|
+
#Gets the questions by the user
|
50
|
+
def get_questions(parameters = {})
|
51
|
+
if @user_questions_url
|
52
|
+
hash,url =request(@user_questions_url, parameters)
|
53
|
+
Questions.new hash, url
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#Gets the answers from the user
|
60
|
+
def get_answers(parameters = {})
|
61
|
+
if @user_answers_url
|
62
|
+
hash,url =request(@user_answers_url, parameters)
|
63
|
+
Answers.new hash, url
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#Gets the questions favorited by the user
|
70
|
+
def get_favorites(parameters = {})
|
71
|
+
if @user_favorites_url
|
72
|
+
hash,url =request(@user_favorites_url, parameters)
|
73
|
+
Questions.new hash, url
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#Gets the tags the user has participated in
|
80
|
+
def get_tags(parameters = {})
|
81
|
+
if @user_tags_url
|
82
|
+
hash,url =request(@user_tags_url, parameters)
|
83
|
+
Tags.new hash, url
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#Gets the badges awared to the user
|
90
|
+
def get_badges
|
91
|
+
if @user_badges_url
|
92
|
+
hash,url =request(@user_badges_url,{})
|
93
|
+
Badges.new hash, url
|
94
|
+
else
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#Gets the user's timeline
|
100
|
+
def get_timeline(parameters = {})
|
101
|
+
if @user_timeline_url
|
102
|
+
hash,url =request(@user_timeline_url, parameters)
|
103
|
+
UserTimelineEvents.new hash, url
|
104
|
+
else
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
#Gets the comments that mention the user
|
110
|
+
def get_mentioned(parameters = {})
|
111
|
+
if @user_mentioned_url
|
112
|
+
hash,url =request(@user_mentioned_url, parameters)
|
113
|
+
Comments.new hash, url
|
114
|
+
else
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#Gets the comments by the user
|
120
|
+
def get_comments(parameters = {})
|
121
|
+
if @user_comments_url
|
122
|
+
hash,url =request(@user_comments_url, parameters)
|
123
|
+
Comments.new hash, url
|
124
|
+
else
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
#Gets the user's reputation
|
130
|
+
def get_reputation(parameters = {})
|
131
|
+
if @user_reputation_url
|
132
|
+
hash,url =request(@user_reputation_url, parameters)
|
133
|
+
RepChanges.new hash, url
|
134
|
+
else
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#Gets the user's other accounts
|
140
|
+
def retrieve_associated_accounts
|
141
|
+
if @association_id
|
142
|
+
Users.retrieve_associated_accounts @association_id
|
143
|
+
else
|
144
|
+
nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class UserDash < BaseDash
|
150
|
+
property :user_id
|
151
|
+
property :user_type
|
152
|
+
property :creation_date
|
153
|
+
property :display_name
|
154
|
+
property :reputation
|
155
|
+
property :email_hash
|
156
|
+
property :age
|
157
|
+
property :last_access_date
|
158
|
+
property :website_url
|
159
|
+
property :location
|
160
|
+
property :about_me
|
161
|
+
property :question_count
|
162
|
+
property :answer_count
|
163
|
+
property :view_count
|
164
|
+
property :up_vote_count
|
165
|
+
property :down_vote_count
|
166
|
+
property :accept_rate
|
167
|
+
property :user_questions_url
|
168
|
+
property :user_answers_url
|
169
|
+
property :user_favorites_url
|
170
|
+
property :user_tags_url
|
171
|
+
property :user_badges_url
|
172
|
+
property :user_timeline_url
|
173
|
+
property :user_mentioned_url
|
174
|
+
property :user_comments_url
|
175
|
+
property :user_reputation_url
|
176
|
+
property :badge_counts
|
177
|
+
property :timed_penalty_date
|
178
|
+
property :association_id
|
179
|
+
property :on_site
|
180
|
+
end
|
181
|
+
end
|