rubyoverflow 0.5 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/README.rdoc +22 -11
  2. data/RELEASENOTES +97 -1
  3. data/Rakefile +49 -7
  4. data/VERSION +1 -1
  5. data/lib/rubyoverflow.rb +92 -18
  6. data/lib/rubyoverflow/answer.rb +61 -0
  7. data/lib/rubyoverflow/answers.rb +60 -0
  8. data/lib/rubyoverflow/apiSite.rb +32 -0
  9. data/lib/rubyoverflow/apiSites.rb +25 -0
  10. data/lib/rubyoverflow/apiVersion.rb +6 -0
  11. data/lib/rubyoverflow/badge.rb +44 -0
  12. data/lib/rubyoverflow/badgeCounts.rb +22 -0
  13. data/lib/rubyoverflow/badges.rb +59 -0
  14. data/lib/rubyoverflow/base.rb +76 -0
  15. data/lib/rubyoverflow/comment.rb +41 -0
  16. data/lib/rubyoverflow/comments.rb +115 -0
  17. data/lib/rubyoverflow/errors.rb +17 -0
  18. data/lib/rubyoverflow/pagedBase.rb +27 -0
  19. data/lib/rubyoverflow/pagedDash.rb +7 -0
  20. data/lib/rubyoverflow/postTimelineEvent.rb +93 -0
  21. data/lib/rubyoverflow/postTimelineEvents.rb +39 -0
  22. data/lib/rubyoverflow/question.rb +110 -0
  23. data/lib/rubyoverflow/questions.rb +104 -0
  24. data/lib/rubyoverflow/repChange.rb +34 -0
  25. data/lib/rubyoverflow/repChanges.rb +41 -0
  26. data/lib/rubyoverflow/revision.rb +62 -0
  27. data/lib/rubyoverflow/revisions.rb +52 -0
  28. data/lib/rubyoverflow/statistics.rb +57 -0
  29. data/lib/rubyoverflow/styling.rb +19 -0
  30. data/lib/rubyoverflow/tag.rb +27 -0
  31. data/lib/rubyoverflow/tags.rb +46 -0
  32. data/lib/rubyoverflow/user.rb +181 -0
  33. data/lib/rubyoverflow/userTimelineEvent.rb +43 -0
  34. data/lib/rubyoverflow/userTimelineEvents.rb +35 -0
  35. data/lib/rubyoverflow/users.rb +67 -18
  36. data/test/apiKey.rb +5 -0
  37. data/test/helper.rb +159 -0
  38. data/test/test_answer.rb +20 -0
  39. data/test/test_answers.rb +32 -0
  40. data/test/test_badge.rb +18 -0
  41. data/test/test_badges.rb +30 -0
  42. data/test/test_base.rb +63 -0
  43. data/test/test_statistics.rb +26 -0
  44. data/test/test_user.rb +56 -0
  45. data/test/test_users.rb +37 -0
  46. metadata +122 -87
  47. data/.gitignore +0 -4
  48. data/.rvmrc +0 -47
  49. data/.travis.yml +0 -5
  50. data/Gemfile +0 -3
  51. data/lib/rubyoverflow/sites.rb +0 -20
  52. data/lib/rubyoverflow/version.rb +0 -3
  53. data/rubyoverflow.gemspec +0 -26
  54. data/spec/sites_spec.rb +0 -18
  55. data/spec/spec_helper.rb +0 -3
  56. data/spec/users_spec.rb +0 -23
@@ -0,0 +1,32 @@
1
+ module Rubyoverflow
2
+ class ApiSite
3
+ attr_reader :name, :logo_url, :api_endpoint, :site_url, :description, :icon_url, :state, :styling, :aliases
4
+
5
+ def initialize(hash,url='')
6
+ dash = ApiSiteDash.new hash
7
+
8
+ @name = dash.name
9
+ @logo_url = dash.logo_url
10
+ @api_endpoint = dash.api_endpoint
11
+ @site_url = dash.site_url
12
+ @description = dash.description
13
+ @icon_url = dash.icon_url
14
+ @state = dash.state
15
+ @styling = Styling.new dash.styling if dash.styling
16
+ @aliases = dash.aliases
17
+ end
18
+
19
+ end
20
+
21
+ class ApiSiteDash < BaseDash
22
+ property :aliases
23
+ property :name
24
+ property :logo_url
25
+ property :api_endpoint
26
+ property :site_url
27
+ property :description
28
+ property :icon_url
29
+ property :state
30
+ property :styling
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ module Rubyoverflow
2
+ class ApiSites < Base
3
+ attr_reader :api_sites
4
+ def initialize(hash, url = '')
5
+ mash = ApiSitesDash.new hash
6
+ @api_sites = Array.new
7
+
8
+ mash.api_sites.each{|siteHash| @api_sites.push(ApiSite.new siteHash)}
9
+ end
10
+
11
+ class << self
12
+ def retrieve_sites()
13
+ client = Client.stackauth_client(Base.client.api_key)
14
+
15
+ hash,url = client.request('sites',{})
16
+
17
+ ApiSites.new hash,url
18
+ end
19
+ end
20
+ end
21
+
22
+ class ApiSitesDash < BaseDash
23
+ property :api_sites
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ module Rubyoverflow
2
+ class ApiVersion < BaseDash
3
+ property :version
4
+ property :revision
5
+ end
6
+ end
@@ -0,0 +1,44 @@
1
+ module Rubyoverflow
2
+ class Badge < Base
3
+ attr_reader :badge_id, :rank, :name, :description, :award_count, :tag_based, :user, :badges_recipients_url
4
+
5
+ def initialize(hash, request_path = '')
6
+ dash = BadgeDash.new hash
7
+
8
+ @badge_id = dash.badge_id
9
+ @rank = dash.rank
10
+ @name = dash.name
11
+ @description = dash.description
12
+ @award_count = dash.award_count
13
+ @tag_based = dash.tag_based
14
+ @user = User.new dash.user if dash.user
15
+ @badges_recipients_url = dash.badges_recipients_url
16
+ end
17
+
18
+ def item_id
19
+ @badge_id
20
+ end
21
+
22
+ #Retrieves all the users that have received the badge
23
+ def get_recipients(parameters = {})
24
+ if @badges_recipients_url
25
+ hash,url =request(@badges_recipients_url, parameters)
26
+ Users.new hash, url
27
+ else
28
+ nil
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ class BadgeDash < BaseDash
35
+ property :badge_id
36
+ property :rank
37
+ property :name
38
+ property :description
39
+ property :award_count
40
+ property :tag_based
41
+ property :user
42
+ property :badges_recipients_url
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ module Rubyoverflow
2
+ class BadgeCounts
3
+
4
+ attr_reader :gold
5
+ attr_reader :silver
6
+ attr_reader :bronze
7
+
8
+ def initialize(hash, request_path = '')
9
+ dash = BadgeCountsDash.new hash
10
+ @gold = dash.gold
11
+ @silver = dash.silver
12
+ @bronze = dash.bronze
13
+ end
14
+
15
+ end
16
+
17
+ class BadgeCountsDash < BaseDash
18
+ property :gold
19
+ property :silver
20
+ property :bronze
21
+ end
22
+ end
@@ -0,0 +1,59 @@
1
+ module Rubyoverflow
2
+ class Badges < PagedBase
3
+
4
+ attr_reader :badges
5
+
6
+ def initialize(hash, request_path = '')
7
+ dash = BadgesDash.new hash
8
+
9
+ @badges = Array.new
10
+ dash.badges.each{ |badgeHash| @badges.push(Badge.new badgeHash)}
11
+
12
+ super(dash, request_path)
13
+ end
14
+
15
+ class <<self
16
+ #Retrieves all badges in alphabetical order
17
+ #
18
+ #Maps to '/badges'
19
+ def retrieve_all
20
+ hash, url = request('badges')
21
+ Badges.new hash, url
22
+ end
23
+
24
+ #Retrieves all standard, non-tag-based badges in alphabetical order
25
+ #
26
+ #Maps to '/badges/name'
27
+ def retrieve_all_non_tag_based
28
+ hash, url = request('badges/name')
29
+ Badges.new hash, url
30
+ end
31
+
32
+ #Retrieves all tag-based badges in alphabetical order
33
+ #
34
+ #Maps to '/badges/tags'
35
+ def retrieve_all_tag_based
36
+ hash, url = request('badges/tags')
37
+ Badges.new hash, url
38
+ end
39
+
40
+ #Retrieves all badges that have been awarded to a set of users by their id(s)
41
+ #
42
+ #id can be an int, string or an array of ints or strings
43
+ #
44
+ #Maps to '/users/{id}/badges'
45
+ def retrieve_by_user(id)
46
+ id = convert_to_id_list(id)
47
+
48
+ hash, url = request('users/'+id.to_s+'/badges')
49
+ Badges.new hash, url
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ class BadgesDash < PagedDash
57
+ property :badges
58
+ end
59
+ end
@@ -0,0 +1,76 @@
1
+ module Rubyoverflow
2
+ class Base
3
+
4
+ def request(path, parameters = {})
5
+ Base.request(path, parameters)
6
+ end
7
+
8
+ def find_parse_querystring(rawurl)
9
+ queryHash = {}
10
+ if rawurl.include? '?'
11
+ url, querystring = rawurl.split('?')
12
+
13
+ if querystring
14
+ querystring.split('&').each {|pair|
15
+ key,value=pair.split('=')
16
+ queryHash[key]=value
17
+ }
18
+ queryHash
19
+ end
20
+ url.sub!(Base.client.host_path,'')
21
+ return url,queryHash
22
+
23
+ else
24
+ url = rawurl
25
+ end
26
+ url.sub!(Base.client.host_path,'')
27
+ return url,queryHash
28
+ end
29
+
30
+ class << self
31
+ def client
32
+ @client ||= Rubyoverflow::Client.config
33
+ end
34
+
35
+ def request(path, parameters = {})
36
+ client.request(path, parameters)
37
+ end
38
+
39
+ def convert_to_id_list(id)
40
+ id = convert_if_array(id)
41
+ id = id.item_id if id.respond_to?(:item_id)
42
+ id.to_s
43
+ end
44
+
45
+ def convert_if_array(id)
46
+ new_id_list = Array.new
47
+ if id.kind_of?(Array)
48
+ id.each do |item|
49
+ if item.respond_to? :item_id
50
+ new_id_list.push item.item_id
51
+ elsif item.kind_of?(String) || item.kind_of?(Integer)
52
+ new_id_list.push item
53
+ end
54
+ end
55
+ return new_id_list.join(';')
56
+ else
57
+ return id
58
+ end
59
+ end
60
+
61
+ def change_end_point(endpoint)
62
+ Client.change_end_point endpoint
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ class BaseDash < Hashie::Dash
69
+ def initialize(hash={})
70
+ hash2 = Hash.new
71
+ hash.each { |key, value| hash2[key.strip] = value }
72
+ hash = hash2
73
+ super(hash)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,41 @@
1
+ module Rubyoverflow
2
+ class Comment
3
+
4
+ attr_reader :comment_id
5
+ attr_reader :creation_date
6
+ attr_reader :owner
7
+ attr_reader :reply_to_user
8
+ attr_reader :post_id
9
+ attr_reader :post_type
10
+ attr_reader :score
11
+ attr_reader :edit_count
12
+ attr_reader :body
13
+
14
+ def initialize(hash, request_path = '')
15
+ dash = CommentDash.new hash
16
+
17
+ @comment_id = dash.comment_id
18
+ @creation_date = dash.creation_date
19
+ @owner = User.new dash.owner
20
+ @reply_to_user = User.new dash.reply_to_user if dash.reply_to_user
21
+ @post_id = dash.post_id
22
+ @post_type = dash.post_type
23
+ @score = dash.score
24
+ @edit_count = dash.edit_count
25
+ @body = dash.body
26
+ end
27
+
28
+ end
29
+
30
+ class CommentDash < BaseDash
31
+ property :comment_id
32
+ property :creation_date
33
+ property :owner
34
+ property :reply_to_user
35
+ property :post_id
36
+ property :post_type
37
+ property :score
38
+ property :edit_count
39
+ property :body
40
+ end
41
+ end
@@ -0,0 +1,115 @@
1
+ module Rubyoverflow
2
+ class Comments < PagedBase
3
+
4
+ attr_reader :comments
5
+
6
+ def initialize(hash, request_path = '')
7
+ dash = CommentsDash.new hash
8
+
9
+ @comments = Array.new
10
+ dash.comments.each{ |commentHash| @comments.push(Comment.new commentHash)}
11
+
12
+ super(dash, request_path)
13
+ end
14
+
15
+ #Retrieves the next set of comments using the same parameters used to retrieve the current set
16
+ def get_next_set
17
+ hash,url = perform_next_page_request
18
+ Comments.new hash,url
19
+ end
20
+
21
+ class << self
22
+
23
+ #Retieves a set of comments by a set by their ids
24
+ #
25
+ #id can be an int, string, or an array of ints or strings
26
+ #
27
+ #Maps to 'comments/{id}
28
+ def retrieve_by_id(id, parameters = {})
29
+ id = convert_to_id_list(id)
30
+
31
+ hash, url = request('comments/'+id.to_s, parameters)
32
+ Comments.new hash, url
33
+ end
34
+
35
+ #Retrieves a set of comments made by a set of users by their ids
36
+ #
37
+ #id can be an int, string, or an array of ints or strings
38
+ #
39
+ #Maps to 'users/{id}/comments'
40
+ def retrieve_by_user(id, parameters={})
41
+ id = convert_to_id_list(id)
42
+
43
+ hash, url = request('users/'+id.to_s+"/comments", parameters)
44
+ Comments.new hash, url
45
+ end
46
+
47
+ #Retrieves a set of comments made on an answer by the answer's id
48
+ #
49
+ #id can be an int, string, or an array of ints or strings
50
+ #
51
+ #Maps to 'answers/{id}/comments'
52
+ def retrieve_by_answer(id, parameters={})
53
+ id = convert_to_id_list(id)
54
+
55
+ hash, url = request('answers/'+id.to_s+"/comments", parameters)
56
+ Comments.new hash, url
57
+ end
58
+
59
+ #Retrieves a set of comments made on a post by the post's id
60
+ #
61
+ #id can be an int, string, or an array of ints or strings
62
+ #
63
+ #Maps to 'posts/{id}/comments'
64
+ def retrieve_by_post(id, parameters={})
65
+ id = convert_to_id_list(id)
66
+
67
+ hash, url = request('posts/'+id.to_s+"/comments", parameters)
68
+ Comments.new hash, url
69
+ end
70
+
71
+ #Retrieves a set comments made on a question by the post's id
72
+ #
73
+ #id can be an int, string, or an array of ints or strings
74
+ #
75
+ #Maps to 'question/{id}/comments'
76
+ def retrieve_by_question(id, parameters={})
77
+ id = convert_to_id_list(id)
78
+
79
+ hash, url = request('questions/'+id.to_s+"/comments", parameters)
80
+ Comments.new hash, url
81
+ end
82
+
83
+ #Retrieves a set of comments made by a set of users to a user
84
+ #
85
+ #id can be an int, string, or an array of ints or strings
86
+ #
87
+ #toid must be an int or string
88
+ #
89
+ #Maps to 'users/{id}/comments/{toid}'
90
+ def retrieve_from_user_to_user(id, toid, parameters={})
91
+ id = convert_to_id_list(id)
92
+
93
+ hash, url = request('users/'+id.to_s+"/comments/" + toid.to_s, parameters)
94
+ Comments.new hash, url
95
+ end
96
+
97
+ #Retieves a set commments directed at a set of users by their ids
98
+ #
99
+ #id can be an int, string, or an array of ints or strings
100
+ #
101
+ #Maps to 'users/{id}/mentioned'
102
+ def retrieve_to_user(id, parameters={})
103
+ id = convert_to_id_list(id)
104
+
105
+ hash, url = request('users/'+id.to_s+"/mentioned", parameters)
106
+ Comments.new hash, url
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ class CommentsDash < PagedDash
113
+ property :comments
114
+ end
115
+ end
@@ -0,0 +1,17 @@
1
+ module Rubyoverflow
2
+ class Errors < Base
3
+
4
+ class << self
5
+
6
+ #Retrieves errors
7
+ #
8
+ #Maps to 'errors/{id}'
9
+ def retrieve(id)
10
+ request('errors/'+id.to_s)
11
+ end
12
+
13
+ end
14
+
15
+
16
+ end
17
+ end