pilha 0.1.6 → 0.1.7
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/lib/pilha.rb +18 -19
- data/lib/pilha/stack_overflow/answer.rb +0 -5
- data/lib/pilha/stack_overflow/badge.rb +1 -6
- data/lib/pilha/stack_overflow/base.rb +7 -4
- data/lib/pilha/stack_overflow/comment.rb +0 -5
- data/lib/pilha/stack_overflow/question.rb +20 -5
- data/lib/pilha/stack_overflow/statistics.rb +3 -10
- data/lib/pilha/stack_overflow/user.rb +0 -7
- data/pilha.gemspec +1 -1
- data/spec/fixtures/all_tags.json +287 -0
- data/spec/fixtures/all_tags.json.gz +0 -0
- data/spec/fixtures/favorite_questions_by_user_id.json +496 -0
- data/spec/fixtures/favorite_questions_by_user_id.json.gz +0 -0
- data/spec/fixtures/post_comments.json +6 -0
- data/spec/fixtures/questions_tagged_gwt_and_googleappengine.json +901 -0
- data/spec/fixtures/questions_tagged_gwt_and_googleappengine.json.gz +0 -0
- data/spec/fixtures/questions_tagged_ruby.json +877 -0
- data/spec/fixtures/questions_tagged_ruby.json.gz +0 -0
- data/spec/fixtures/questions_unanswered.json +845 -0
- data/spec/fixtures/questions_unanswered.json.gz +0 -0
- data/spec/fixtures/revisions_by_id.json +25 -0
- data/spec/fixtures/search_intitle_ruby.json +872 -0
- data/spec/fixtures/search_tagged_ruby_rails.json +877 -0
- data/spec/fixtures/tags_by_user_id.json +357 -0
- data/spec/fixtures/tags_by_user_id.json.gz +0 -0
- data/spec/fixtures/user_tags.json +357 -0
- data/spec/pilha/stack_overflow/badge_spec.rb +0 -4
- data/spec/pilha/stack_overflow/question_spec.rb +65 -0
- data/spec/pilha/stack_overflow/statistics_spec.rb +0 -4
- data/spec/spec_helper.rb +6 -0
- metadata +20 -3
data/lib/pilha.rb
CHANGED
@@ -2,21 +2,22 @@ path = File.expand_path(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
+
|
5
6
|
require 'zlib'
|
6
7
|
require 'json'
|
7
8
|
require 'open-uri'
|
8
9
|
require 'forwardable'
|
9
10
|
|
10
11
|
require 'pilha/stack_overflow/base'
|
11
|
-
require 'pilha/stack_overflow/
|
12
|
-
require 'pilha/stack_overflow/badge'
|
12
|
+
require 'pilha/stack_overflow/tag'
|
13
13
|
require 'pilha/stack_overflow/user'
|
14
|
+
require 'pilha/stack_overflow/badge'
|
14
15
|
require 'pilha/stack_overflow/answer'
|
15
16
|
require 'pilha/stack_overflow/comment'
|
16
17
|
require 'pilha/stack_overflow/question'
|
18
|
+
require 'pilha/stack_overflow/statistics'
|
17
19
|
|
18
20
|
module StackExchange
|
19
|
-
|
20
21
|
module StackOverflow
|
21
22
|
class Client
|
22
23
|
URL = 'http://api.stackoverflow.com/'
|
@@ -30,15 +31,15 @@ module StackExchange
|
|
30
31
|
def config &block
|
31
32
|
options = OpenStruct.new
|
32
33
|
yield options if block_given?
|
33
|
-
|
34
|
-
client = Client.new(options)
|
35
|
-
include_client(client, Badge, Statistics, User, Answer, Comment, Question)
|
34
|
+
init_client! Client.new(options)
|
36
35
|
end
|
37
36
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
37
|
+
def init_client!(client)
|
38
|
+
base_eigenclass = class << Base; self; end
|
39
|
+
base_eigenclass.send :define_method, :client do
|
40
|
+
@client = client
|
41
41
|
end
|
42
|
+
client
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -50,7 +51,7 @@ module StackExchange
|
|
50
51
|
|
51
52
|
def api_method_path(pattern, options = {})
|
52
53
|
pattern = normalize(pattern)
|
53
|
-
parts
|
54
|
+
parts = pattern.split('/').select { |part| part =~ /^:/ }
|
54
55
|
|
55
56
|
parts.each do |part|
|
56
57
|
key = part.sub(':', '').intern
|
@@ -80,15 +81,13 @@ module StackExchange
|
|
80
81
|
|
81
82
|
private
|
82
83
|
def query_string(options)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
''
|
91
|
-
end
|
84
|
+
params = options[:query] || options[:conditions]
|
85
|
+
return '' unless params
|
86
|
+
|
87
|
+
params = params.sort_by { |k, v| k.to_s }
|
88
|
+
pairs = params.map { |key, value| "#{key}=#{value}" }
|
89
|
+
|
90
|
+
'?' + pairs.join('&')
|
92
91
|
end
|
93
92
|
|
94
93
|
def normalize(url)
|
@@ -8,7 +8,6 @@ module StackExchange
|
|
8
8
|
:view_count, :score, :community_owned, :title, :comments
|
9
9
|
|
10
10
|
class << self
|
11
|
-
attr_reader :client
|
12
11
|
|
13
12
|
def find(id, options = {})
|
14
13
|
request('/answers/:id', id, options).answers.first
|
@@ -32,10 +31,6 @@ module StackExchange
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
def initialize(hash)
|
36
|
-
@struct = OpenStruct.new hash
|
37
|
-
end
|
38
|
-
|
39
34
|
def id
|
40
35
|
@struct.answer_id
|
41
36
|
end
|
@@ -8,7 +8,6 @@ module StackExchange
|
|
8
8
|
:award_count, :tag_based, :badges_recipients_url
|
9
9
|
|
10
10
|
class << self
|
11
|
-
attr_reader :client
|
12
11
|
|
13
12
|
def all(options = {})
|
14
13
|
method = select_method(options)
|
@@ -21,15 +20,11 @@ module StackExchange
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def parse(response)
|
24
|
-
response
|
23
|
+
parse_with_class(response, 'badges', Badge)
|
25
24
|
OpenStruct.new response
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
def initialize(hash)
|
30
|
-
@struct = OpenStruct.new hash
|
31
|
-
end
|
32
|
-
|
33
28
|
def id
|
34
29
|
@struct.badge_id
|
35
30
|
end
|
@@ -3,6 +3,10 @@ module StackExchange
|
|
3
3
|
class Base
|
4
4
|
|
5
5
|
class << self
|
6
|
+
def client
|
7
|
+
@client ||= StackExchange::StackOverflow::Client.config
|
8
|
+
end
|
9
|
+
|
6
10
|
def parse_with_class(hash, key, klass)
|
7
11
|
case hash[key]
|
8
12
|
when Hash
|
@@ -16,11 +20,10 @@ module StackExchange
|
|
16
20
|
options.merge! :id => id if id
|
17
21
|
parse client.request(path_pattern, options)
|
18
22
|
end
|
23
|
+
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
@client
|
23
|
-
end
|
25
|
+
def initialize(hash)
|
26
|
+
@struct = OpenStruct.new hash
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -7,7 +7,6 @@ module StackExchange
|
|
7
7
|
:post_type, :score, :body
|
8
8
|
|
9
9
|
class << self
|
10
|
-
attr_reader :client
|
11
10
|
|
12
11
|
def find(id, options = {})
|
13
12
|
request('/comments/:id/', id, options)
|
@@ -39,10 +38,6 @@ module StackExchange
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
|
-
def initialize(hash)
|
43
|
-
@struct = OpenStruct.new hash
|
44
|
-
end
|
45
|
-
|
46
41
|
def id
|
47
42
|
@struct.comment_id
|
48
43
|
end
|
@@ -10,7 +10,6 @@ module StackExchange
|
|
10
10
|
:question_comments_url, :question_answers_url, :owner
|
11
11
|
|
12
12
|
class << self
|
13
|
-
attr_reader :client
|
14
13
|
|
15
14
|
def find(id, options = {})
|
16
15
|
request('/questions/:id/', id, options).questions.first
|
@@ -20,6 +19,26 @@ module StackExchange
|
|
20
19
|
request('/users/:id/questions', id, options)
|
21
20
|
end
|
22
21
|
|
22
|
+
def find_favorites_by_user_id(id, options = {})
|
23
|
+
request('/users/:id/favorites', id, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_by_tags(*tags)
|
27
|
+
if tags.last.is_a? Hash
|
28
|
+
options = tags.last
|
29
|
+
tags = tags[0, tags.size - 1]
|
30
|
+
else
|
31
|
+
options = {}
|
32
|
+
end
|
33
|
+
|
34
|
+
options.merge!(:conditions => { :tagged => tags.join('+') })
|
35
|
+
request('/questions', nil, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def unanswered(options = {})
|
39
|
+
request('/questions/unanswered', nil, options)
|
40
|
+
end
|
41
|
+
|
23
42
|
def parse(response)
|
24
43
|
response['questions'].each do |comment|
|
25
44
|
parse_with_class(comment, 'owner', User)
|
@@ -29,10 +48,6 @@ module StackExchange
|
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
32
|
-
def initialize(hash)
|
33
|
-
@struct = OpenStruct.new hash
|
34
|
-
end
|
35
|
-
|
36
51
|
def id
|
37
52
|
@struct.question_id
|
38
53
|
end
|
@@ -9,21 +9,14 @@ module StackExchange
|
|
9
9
|
:total_users, :questions_per_minute, :answers_per_minute,
|
10
10
|
:badges_per_minute, :api_version
|
11
11
|
|
12
|
-
def initialize(hash)
|
13
|
-
@struct = OpenStruct.new hash
|
14
|
-
end
|
15
|
-
|
16
12
|
class << self
|
17
|
-
attr_reader :client
|
18
|
-
|
19
13
|
def all(options = {})
|
20
14
|
request('/stats', nil, options)
|
21
15
|
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
17
|
+
def parse(response)
|
18
|
+
Statistics.new response['statistics'].first
|
19
|
+
end
|
27
20
|
end
|
28
21
|
end
|
29
22
|
end
|
@@ -13,9 +13,6 @@ module StackExchange
|
|
13
13
|
:badge_counts
|
14
14
|
|
15
15
|
class << self
|
16
|
-
|
17
|
-
attr_reader :client
|
18
|
-
|
19
16
|
def all(options = {})
|
20
17
|
request('/users', nil, options)
|
21
18
|
end
|
@@ -34,10 +31,6 @@ module StackExchange
|
|
34
31
|
end
|
35
32
|
end
|
36
33
|
|
37
|
-
def initialize(hash)
|
38
|
-
@struct = OpenStruct.new hash
|
39
|
-
end
|
40
|
-
|
41
34
|
def id
|
42
35
|
@struct.user_id
|
43
36
|
end
|
data/pilha.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "pilha"
|
3
|
-
gem.version = "0.1.
|
3
|
+
gem.version = "0.1.7"
|
4
4
|
gem.authors = ["Dalto Curvelano Junior"]
|
5
5
|
gem.description = "A ruby wrapper to the Stack Exchange (Stack Overflow and friends) API."
|
6
6
|
gem.summary = "A ruby wrapper to the Stack Exchange (Stack Overflow and friends) API."
|
@@ -0,0 +1,287 @@
|
|
1
|
+
{
|
2
|
+
"total": 29199,
|
3
|
+
"page": 1,
|
4
|
+
"pagesize": 70,
|
5
|
+
"tags": [
|
6
|
+
{
|
7
|
+
"name": "c#",
|
8
|
+
"count": 84875
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"name": "java",
|
12
|
+
"count": 50661
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"name": ".net",
|
16
|
+
"count": 42982
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "php",
|
20
|
+
"count": 42359
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"name": "asp.net",
|
24
|
+
"count": 38560
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "javascript",
|
28
|
+
"count": 37024
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"name": "c++",
|
32
|
+
"count": 31709
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"name": "jquery",
|
36
|
+
"count": 29607
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"name": "iphone",
|
40
|
+
"count": 26442
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"name": "python",
|
44
|
+
"count": 25583
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"name": "sql",
|
48
|
+
"count": 20885
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"name": "mysql",
|
52
|
+
"count": 18581
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"name": "html",
|
56
|
+
"count": 17460
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"name": "sql-server",
|
60
|
+
"count": 15911
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"name": "ruby-on-rails",
|
64
|
+
"count": 14369
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"name": "c",
|
68
|
+
"count": 13986
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"name": "asp.net-mvc",
|
72
|
+
"count": 13154
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"name": "css",
|
76
|
+
"count": 13126
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"name": "wpf",
|
80
|
+
"count": 13074
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"name": "objective-c",
|
84
|
+
"count": 12652
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"name": "windows",
|
88
|
+
"count": 10966
|
89
|
+
},
|
90
|
+
{
|
91
|
+
"name": "xml",
|
92
|
+
"count": 10172
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"name": "ruby",
|
96
|
+
"count": 10157
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "database",
|
100
|
+
"count": 9314
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"name": "best-practices",
|
104
|
+
"count": 9280
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"name": "android",
|
108
|
+
"count": 9129
|
109
|
+
},
|
110
|
+
{
|
111
|
+
"name": "vb.net",
|
112
|
+
"count": 8826
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"name": "visual-studio",
|
116
|
+
"count": 8564
|
117
|
+
},
|
118
|
+
{
|
119
|
+
"name": "ajax",
|
120
|
+
"count": 8168
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"name": "winforms",
|
124
|
+
"count": 8154
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"name": "regex",
|
128
|
+
"count": 8120
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"name": "linux",
|
132
|
+
"count": 8031
|
133
|
+
},
|
134
|
+
{
|
135
|
+
"name": "django",
|
136
|
+
"count": 7724
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"name": "iphone-sdk",
|
140
|
+
"count": 7322
|
141
|
+
},
|
142
|
+
{
|
143
|
+
"name": "visual-studio-2008",
|
144
|
+
"count": 6996
|
145
|
+
},
|
146
|
+
{
|
147
|
+
"name": "beginner",
|
148
|
+
"count": 6687
|
149
|
+
},
|
150
|
+
{
|
151
|
+
"name": "web-development",
|
152
|
+
"count": 6485
|
153
|
+
},
|
154
|
+
{
|
155
|
+
"name": "flex",
|
156
|
+
"count": 6404
|
157
|
+
},
|
158
|
+
{
|
159
|
+
"name": "subjective",
|
160
|
+
"count": 6229
|
161
|
+
},
|
162
|
+
{
|
163
|
+
"name": "flash",
|
164
|
+
"count": 6086
|
165
|
+
},
|
166
|
+
{
|
167
|
+
"name": "linq",
|
168
|
+
"count": 5998
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"name": "wcf",
|
172
|
+
"count": 5865
|
173
|
+
},
|
174
|
+
{
|
175
|
+
"name": "silverlight",
|
176
|
+
"count": 5761
|
177
|
+
},
|
178
|
+
{
|
179
|
+
"name": "cocoa",
|
180
|
+
"count": 5659
|
181
|
+
},
|
182
|
+
{
|
183
|
+
"name": "actionscript-3",
|
184
|
+
"count": 5359
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"name": "sql-server-2005",
|
188
|
+
"count": 5329
|
189
|
+
},
|
190
|
+
{
|
191
|
+
"name": "cocoa-touch",
|
192
|
+
"count": 5257
|
193
|
+
},
|
194
|
+
{
|
195
|
+
"name": "performance",
|
196
|
+
"count": 5236
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"name": "algorithm",
|
200
|
+
"count": 5142
|
201
|
+
},
|
202
|
+
{
|
203
|
+
"name": "perl",
|
204
|
+
"count": 5081
|
205
|
+
},
|
206
|
+
{
|
207
|
+
"name": "eclipse",
|
208
|
+
"count": 5072
|
209
|
+
},
|
210
|
+
{
|
211
|
+
"name": "oracle",
|
212
|
+
"count": 5045
|
213
|
+
},
|
214
|
+
{
|
215
|
+
"name": "web-services",
|
216
|
+
"count": 4859
|
217
|
+
},
|
218
|
+
{
|
219
|
+
"name": "security",
|
220
|
+
"count": 4848
|
221
|
+
},
|
222
|
+
{
|
223
|
+
"name": "svn",
|
224
|
+
"count": 4837
|
225
|
+
},
|
226
|
+
{
|
227
|
+
"name": "delphi",
|
228
|
+
"count": 4778
|
229
|
+
},
|
230
|
+
{
|
231
|
+
"name": "multithreading",
|
232
|
+
"count": 4762
|
233
|
+
},
|
234
|
+
{
|
235
|
+
"name": "sharepoint",
|
236
|
+
"count": 4760
|
237
|
+
},
|
238
|
+
{
|
239
|
+
"name": "arrays",
|
240
|
+
"count": 4395
|
241
|
+
},
|
242
|
+
{
|
243
|
+
"name": "unit-testing",
|
244
|
+
"count": 4292
|
245
|
+
},
|
246
|
+
{
|
247
|
+
"name": "nhibernate",
|
248
|
+
"count": 4216
|
249
|
+
},
|
250
|
+
{
|
251
|
+
"name": "linq-to-sql",
|
252
|
+
"count": 4171
|
253
|
+
},
|
254
|
+
{
|
255
|
+
"name": "tsql",
|
256
|
+
"count": 4031
|
257
|
+
},
|
258
|
+
{
|
259
|
+
"name": "apache",
|
260
|
+
"count": 3882
|
261
|
+
},
|
262
|
+
{
|
263
|
+
"name": "string",
|
264
|
+
"count": 3790
|
265
|
+
},
|
266
|
+
{
|
267
|
+
"name": "homework",
|
268
|
+
"count": 3664
|
269
|
+
},
|
270
|
+
{
|
271
|
+
"name": "excel",
|
272
|
+
"count": 3629
|
273
|
+
},
|
274
|
+
{
|
275
|
+
"name": "design",
|
276
|
+
"count": 3506
|
277
|
+
},
|
278
|
+
{
|
279
|
+
"name": "xcode",
|
280
|
+
"count": 3472
|
281
|
+
},
|
282
|
+
{
|
283
|
+
"name": "mvc",
|
284
|
+
"count": 3427
|
285
|
+
}
|
286
|
+
]
|
287
|
+
}
|