rubyoverflow 1.0.2 → 2.0.2.pre1
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/.gitignore +5 -0
- data/.rvmrc +47 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.rdoc +14 -20
- data/RELEASENOTES +1 -97
- data/Rakefile +7 -49
- data/lib/rubyoverflow.rb +46 -108
- data/lib/rubyoverflow/answers.rb +5 -57
- data/lib/rubyoverflow/base.rb +21 -68
- data/lib/rubyoverflow/questions.rb +5 -101
- data/lib/rubyoverflow/sites.rb +18 -0
- data/lib/rubyoverflow/stats.rb +8 -0
- data/lib/rubyoverflow/users.rb +5 -70
- data/lib/rubyoverflow/version.rb +3 -0
- data/rubyoverflow.gemspec +26 -0
- data/spec/answers_spec.rb +13 -0
- data/spec/questions_spec.rb +13 -0
- data/spec/sites_spec.rb +18 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/stats_spec.rb +12 -0
- data/spec/users_spec.rb +23 -0
- metadata +94 -121
- data/VERSION +0 -1
- data/lib/rubyoverflow/answer.rb +0 -61
- data/lib/rubyoverflow/apiSite.rb +0 -32
- data/lib/rubyoverflow/apiSites.rb +0 -25
- data/lib/rubyoverflow/apiVersion.rb +0 -6
- data/lib/rubyoverflow/badge.rb +0 -44
- data/lib/rubyoverflow/badgeCounts.rb +0 -22
- data/lib/rubyoverflow/badges.rb +0 -59
- data/lib/rubyoverflow/comment.rb +0 -41
- data/lib/rubyoverflow/comments.rb +0 -115
- data/lib/rubyoverflow/errors.rb +0 -17
- data/lib/rubyoverflow/pagedBase.rb +0 -27
- data/lib/rubyoverflow/pagedDash.rb +0 -7
- data/lib/rubyoverflow/postTimelineEvent.rb +0 -93
- data/lib/rubyoverflow/postTimelineEvents.rb +0 -39
- data/lib/rubyoverflow/question.rb +0 -110
- data/lib/rubyoverflow/repChange.rb +0 -34
- data/lib/rubyoverflow/repChanges.rb +0 -41
- data/lib/rubyoverflow/revision.rb +0 -62
- data/lib/rubyoverflow/revisions.rb +0 -52
- data/lib/rubyoverflow/statistics.rb +0 -57
- data/lib/rubyoverflow/styling.rb +0 -19
- data/lib/rubyoverflow/tag.rb +0 -27
- data/lib/rubyoverflow/tags.rb +0 -46
- data/lib/rubyoverflow/user.rb +0 -181
- data/lib/rubyoverflow/userTimelineEvent.rb +0 -43
- data/lib/rubyoverflow/userTimelineEvents.rb +0 -35
- data/test/apiKey.rb +0 -5
- data/test/helper.rb +0 -159
- data/test/test_answer.rb +0 -20
- data/test/test_answers.rb +0 -32
- data/test/test_badge.rb +0 -18
- data/test/test_badges.rb +0 -30
- data/test/test_base.rb +0 -63
- data/test/test_statistics.rb +0 -26
- data/test/test_user.rb +0 -56
- data/test/test_users.rb +0 -37
data/lib/rubyoverflow/answers.rb
CHANGED
@@ -1,60 +1,8 @@
|
|
1
1
|
module Rubyoverflow
|
2
|
-
class Answers <
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
data/lib/rubyoverflow/base.rb
CHANGED
@@ -1,76 +1,29 @@
|
|
1
1
|
module Rubyoverflow
|
2
2
|
class Base
|
3
|
-
|
4
|
-
|
5
|
-
Base.request(path, parameters)
|
3
|
+
def initialize(client)
|
4
|
+
@client = client
|
6
5
|
end
|
7
|
-
|
8
|
-
def
|
9
|
-
|
10
|
-
if
|
11
|
-
url
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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 <
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
data/lib/rubyoverflow/users.rb
CHANGED
@@ -1,73 +1,8 @@
|
|
1
1
|
module Rubyoverflow
|
2
|
-
class Users <
|
3
|
-
|
4
|
-
|
5
|
-
|
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,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
|
data/spec/sites_spec.rb
ADDED
@@ -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
|