rubyoverflow 1.0.2 → 2.0.2.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +47 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +1 -1
  6. data/README.rdoc +14 -20
  7. data/RELEASENOTES +1 -97
  8. data/Rakefile +7 -49
  9. data/lib/rubyoverflow.rb +46 -108
  10. data/lib/rubyoverflow/answers.rb +5 -57
  11. data/lib/rubyoverflow/base.rb +21 -68
  12. data/lib/rubyoverflow/questions.rb +5 -101
  13. data/lib/rubyoverflow/sites.rb +18 -0
  14. data/lib/rubyoverflow/stats.rb +8 -0
  15. data/lib/rubyoverflow/users.rb +5 -70
  16. data/lib/rubyoverflow/version.rb +3 -0
  17. data/rubyoverflow.gemspec +26 -0
  18. data/spec/answers_spec.rb +13 -0
  19. data/spec/questions_spec.rb +13 -0
  20. data/spec/sites_spec.rb +18 -0
  21. data/spec/spec_helper.rb +3 -0
  22. data/spec/stats_spec.rb +12 -0
  23. data/spec/users_spec.rb +23 -0
  24. metadata +94 -121
  25. data/VERSION +0 -1
  26. data/lib/rubyoverflow/answer.rb +0 -61
  27. data/lib/rubyoverflow/apiSite.rb +0 -32
  28. data/lib/rubyoverflow/apiSites.rb +0 -25
  29. data/lib/rubyoverflow/apiVersion.rb +0 -6
  30. data/lib/rubyoverflow/badge.rb +0 -44
  31. data/lib/rubyoverflow/badgeCounts.rb +0 -22
  32. data/lib/rubyoverflow/badges.rb +0 -59
  33. data/lib/rubyoverflow/comment.rb +0 -41
  34. data/lib/rubyoverflow/comments.rb +0 -115
  35. data/lib/rubyoverflow/errors.rb +0 -17
  36. data/lib/rubyoverflow/pagedBase.rb +0 -27
  37. data/lib/rubyoverflow/pagedDash.rb +0 -7
  38. data/lib/rubyoverflow/postTimelineEvent.rb +0 -93
  39. data/lib/rubyoverflow/postTimelineEvents.rb +0 -39
  40. data/lib/rubyoverflow/question.rb +0 -110
  41. data/lib/rubyoverflow/repChange.rb +0 -34
  42. data/lib/rubyoverflow/repChanges.rb +0 -41
  43. data/lib/rubyoverflow/revision.rb +0 -62
  44. data/lib/rubyoverflow/revisions.rb +0 -52
  45. data/lib/rubyoverflow/statistics.rb +0 -57
  46. data/lib/rubyoverflow/styling.rb +0 -19
  47. data/lib/rubyoverflow/tag.rb +0 -27
  48. data/lib/rubyoverflow/tags.rb +0 -46
  49. data/lib/rubyoverflow/user.rb +0 -181
  50. data/lib/rubyoverflow/userTimelineEvent.rb +0 -43
  51. data/lib/rubyoverflow/userTimelineEvents.rb +0 -35
  52. data/test/apiKey.rb +0 -5
  53. data/test/helper.rb +0 -159
  54. data/test/test_answer.rb +0 -20
  55. data/test/test_answers.rb +0 -32
  56. data/test/test_badge.rb +0 -18
  57. data/test/test_badges.rb +0 -30
  58. data/test/test_base.rb +0 -63
  59. data/test/test_statistics.rb +0 -26
  60. data/test/test_user.rb +0 -56
  61. data/test/test_users.rb +0 -37
@@ -1,60 +1,8 @@
1
1
  module Rubyoverflow
2
- class Answers < PagedBase
3
- attr_reader :answers
4
-
5
- def initialize(hash, request_path = '')
6
- dash = AnswersDash.new hash
7
-
8
- @answers = Array.new
9
- dash.answers.each {|answerHash| @answers.push(Answer.new answerHash)}
10
-
11
- super(dash, request_path)
2
+ class Answers < Base
3
+ def initialize(client)
4
+ set_path('answers')
5
+ super(client)
12
6
  end
13
-
14
- #Retrieves the next set of answers using the same parameters used to retrieve the current set
15
- def get_next_set
16
- hash,url = perform_next_page_request
17
- Answers.new hash,url
18
- end
19
-
20
- class << self
21
-
22
- #Retrieves a set of questions by their id(s)
23
- #
24
- #id can be an int, string, or an array of ints or strings
25
- #
26
- #Maps to '/answers/{id}'
27
- def retrieve_by_id(id, parameters = {})
28
- id = convert_to_id_list(id)
29
- hash,url = request('answers/'+id.to_s, parameters)
30
- Answers.new hash,url
31
- end
32
-
33
- #Retrieves a set of answers made by a set of users by their ids
34
- #
35
- #id can be an int, string, or an array of ints or strings
36
- #
37
- #Maps to 'users/{id}/answers'
38
- def retrieve_by_user(id, parameters={})
39
- id = convert_to_id_list(id)
40
- hash, url = request('users/'+id.to_s+"/answers", parameters)
41
- Answers.new hash, url
42
- end
43
-
44
- #Retrieves a set of answers from a set of questions by the questions' ids
45
- #
46
- #id can be an int, string, or an array of ints or strings
47
- #
48
- #Maps to 'questions/{id}/answers'
49
- def retrieve_by_question(id, parameters={})
50
- id = convert_to_id_list(id)
51
- hash, url = request('questions/'+id.to_s+"/answers", parameters)
52
- Answers.new hash, url
53
- end
54
- end
55
- end
56
-
57
- class AnswersDash < PagedDash
58
- property :answers
59
7
  end
60
- end
8
+ end
@@ -1,76 +1,29 @@
1
1
  module Rubyoverflow
2
2
  class Base
3
-
4
- def request(path, parameters = {})
5
- Base.request(path, parameters)
3
+ def initialize(client)
4
+ @client = client
6
5
  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
6
+
7
+ def fetch(params = {})
8
+ ids = params.delete(:id) if params[:id]
9
+ ids = ids.join(';') if ids and ids.kind_of? Array
10
+ hash,url = @client.request "#{@path}#{"/#{ids}" if ids}", params
11
+ Hashie::Mash.new hash
28
12
  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
13
+
14
+ def method_missing(name, *args, &block)
15
+ params = args.first
16
+ ids = params.delete(:id) if params[:id]
17
+ ids = ids.join(';') if ids and ids.kind_of? Array
18
+ hash,url = @client.request "#{@path}#{"/#{ids}" if ids}/#{name}", params
19
+ Hashie::Mash.new hash
64
20
  end
65
-
66
- end
67
21
 
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)
22
+ protected
23
+
24
+ def set_path(pa)
25
+ @path = pa
74
26
  end
27
+
75
28
  end
76
- end
29
+ end
@@ -1,104 +1,8 @@
1
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)
2
+ class Questions < Base
3
+ def initialize(client)
4
+ set_path('questions')
5
+ super(client)
12
6
  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
7
  end
104
- end
8
+ end
@@ -0,0 +1,18 @@
1
+ module Rubyoverflow
2
+ class Sites
3
+ @client = nil
4
+ def fetch(params = {})
5
+ @client ||= Client.stackauth_client
6
+ hash,url = @client.request 'sites', params
7
+ Hashie::Mash.new hash
8
+ end
9
+ end
10
+
11
+ class Client
12
+ @sites = nil
13
+
14
+ def sites
15
+ @sites ||= Sites.new
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Rubyoverflow
2
+ class Stats < Base
3
+ def initialize(client)
4
+ set_path('stats')
5
+ super(client)
6
+ end
7
+ end
8
+ end
@@ -1,73 +1,8 @@
1
1
  module Rubyoverflow
2
- class Users < PagedBase
3
- attr_reader :users
4
-
5
- def initialize(hash, request_path = '')
6
- dash = UsersDash.new hash
7
- super(dash, request_path)
8
- @users = Array.new
9
-
10
- dash.users.each{|userHash| @users.push(User.new userHash)} if dash.users
11
- dash.associated_users.each{|userHash| @users.push(User.new userHash)} if dash.associated_users
12
-
2
+ class Users < Base
3
+ def initialize(client)
4
+ set_path('users')
5
+ super(client)
13
6
  end
14
-
15
- #Retrieves the next set of users using the same parameters used to retrieve the current set
16
- def get_next_set
17
- hash,url = perform_next_page_request
18
- Users.new hash,url
19
- end
20
-
21
- class << self
22
-
23
- #Retieves all users using the parameters provided
24
- #
25
- #Maps to '/users'
26
- def retrieve_all(parameters = {})
27
- hash,url = request('users/', parameters)
28
- Users.new hash, url
29
- end
30
-
31
- #Retrieves users by id(s) using the parameters provided
32
- #
33
- #id can be an int, string, or an array of either
34
- #
35
- #Maps to '/users/{id}'
36
- def retrieve_by_id(id, parameters = {})
37
- id = convert_to_id_list(id)
38
- hash,url = request('users/'+id.to_s, parameters)
39
- Users.new hash, url
40
- end
41
-
42
- #Retrieves users that have received badge(s) by badge id(s) using the parameters provided
43
- #
44
- #id can be an int, string, badge or an array of any of the three
45
- #
46
- #Maps to '/badges/{id}'
47
- def retrieve_by_badge(id, parameters = {})
48
- id = convert_to_id_list(id)
49
- hash,url = request('badges/'+id.to_s, parameters)
50
- Users.new hash, url
51
- end
52
-
53
- #Retrieves moderators for the current site the parameters provided
54
- #
55
- #Maps to '/users/moderators'
56
- def retrieve_moderators(parameters = {})
57
- hash,url = request('users/moderators', parameters)
58
- Users.new hash, url
59
- end
60
-
61
- def retrieve_associated_accounts(guid)
62
- client = Client.stackauth_client(Base.client.api_key)
63
- hash,url = client.request('users/' + guid +'/associated',{})
64
- Users.new hash,url
65
- end
66
- end
67
- end
68
-
69
- class UsersDash < PagedDash
70
- property :users
71
- property :associated_users
72
7
  end
73
- end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Rubyoverflow
2
+ VERSION = "2.0.2.pre1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rubyoverflow/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rubyoverflow"
7
+ s.version = Rubyoverflow::VERSION
8
+ s.authors = ["Dan Seaver"]
9
+ s.email = ["git@danseaver.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Rubyoverflow is a Ruby wrapper for the Stack Exchange APIs}
12
+ s.description = %q{Rubyoverflow is a Ruby wrapper for the Stack Exchange APIs}
13
+
14
+ s.rubyforge_project = "rubyoverflow"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('faraday')
22
+ s.add_dependency('hashie')
23
+ s.add_dependency('json')
24
+ s.add_development_dependency('rspec')
25
+ s.add_development_dependency('rake')
26
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Answers do
4
+ before(:each) do
5
+ @client = Client.new
6
+ end
7
+
8
+ it "retrieves answers" do
9
+ result = @client.answers.fetch
10
+ result.should respond_to(:answers)
11
+ result.page.should == 1
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Questions do
4
+ before(:each) do
5
+ @client = Client.new
6
+ end
7
+
8
+ it "retrieves questions" do
9
+ result = @client.questions.fetch
10
+ result.should respond_to(:questions)
11
+ result.page.should == 1
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe Sites do
4
+ before(:each) do
5
+ @client = Client.new
6
+ end
7
+
8
+ it "retrieves sites" do
9
+ result = @client.sites.fetch
10
+ result.should respond_to(:items)
11
+ result.page.should == 1
12
+ end
13
+
14
+ it "retrieves second page of sites" do
15
+ result = @client.sites.fetch :page => 2
16
+ result.page.should == 2
17
+ end
18
+ end