pilha 0.2.1 → 0.2.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.
@@ -22,6 +22,17 @@ Pilha aims to provide a ActiveRecord like interface for querying the StackExchan
22
22
  Badge.all # returns all badges
23
23
  User.find_by_badge_id(2) # returns all users awarded by the badge identified with 'id'
24
24
 
25
+ As all response objects returned by Pilha are instances of OpenStruct, so you need to call
26
+ the 'api_methods' on a desired class to see which methods of the OpenStruct were added
27
+ by the gem.
28
+
29
+ Question.api_methods
30
+
31
+ # => [:@struct, :question_id, :tags, :creation_date, :last_activity_date, :up_vote_count,
32
+ :down_vote_count, :view_count, :score, :community_owned, :title, :body, :answers,
33
+ :answer_count, :accepted_answer_id, :favorite_count, :question_timeline_url,
34
+ :question_comments_url, :question_answers_url, :owner]
35
+
25
36
  = Contributors
26
37
 
27
38
  Michael Barton (http://github.com/michaelbarton)
@@ -19,11 +19,11 @@ require 'pilha/stack_overflow/statistics'
19
19
  module StackExchange
20
20
  module StackOverflow
21
21
 
22
- VERSION = '0.2.1'
22
+ VERSION = '0.2.2'
23
23
 
24
24
  class Client
25
25
  URL = 'http://api.stackoverflow.com/'
26
- API_VERSION = '1.0'
26
+ API_VERSION = '1.1'
27
27
 
28
28
  attr_reader :url
29
29
  attr_reader :api_version
@@ -1,11 +1,10 @@
1
1
  module StackExchange
2
2
  module StackOverflow
3
3
  class Answer < Base
4
- extend Forwardable
5
4
 
6
- def_delegators :@struct, :answer_id, :accepted, :answer_comments_url, :question_id,
7
- :owner, :creation_date, :last_activity_date, :up_vote_count, :down_vote_count,
8
- :view_count, :score, :community_owned, :title, :comments, :body
5
+ setup_delegators :@struct, :answer_id, :accepted, :answer_comments_url, :question_id,
6
+ :owner, :creation_date, :last_activity_date, :up_vote_count, :down_vote_count,
7
+ :view_count, :score, :community_owned, :title, :comments, :body
9
8
 
10
9
  class << self
11
10
 
@@ -2,9 +2,7 @@ module StackExchange
2
2
  module StackOverflow
3
3
  class Badge < Base
4
4
 
5
- extend Forwardable
6
-
7
- def_delegators :@struct, :badge_id, :rank, :name, :description,
5
+ setup_delegators :@struct, :badge_id, :rank, :name, :description,
8
6
  :award_count, :tag_based, :badges_recipients_url
9
7
 
10
8
  class << self
@@ -1,8 +1,16 @@
1
1
  module StackExchange
2
2
  module StackOverflow
3
3
  class Base
4
+ extend Forwardable
4
5
 
5
6
  class << self
7
+ attr_reader :api_methods
8
+
9
+ def setup_delegators(*delegators)
10
+ @api_methods = delegators
11
+ def_delegators *delegators
12
+ end
13
+
6
14
  def parse_with_class(hash, key, klass)
7
15
  case hash[key]
8
16
  when Hash
@@ -25,6 +33,11 @@ module StackExchange
25
33
  def initialize(hash)
26
34
  @struct = OpenStruct.new hash
27
35
  end
36
+
37
+ def api_methods
38
+ self.class.api_methods
39
+ end
40
+
28
41
  end
29
42
  end
30
43
  end
@@ -1,9 +1,8 @@
1
1
  module StackExchange
2
2
  module StackOverflow
3
3
  class Comment < Base
4
- extend Forwardable
5
4
 
6
- def_delegators :@struct, :comment_id, :creation_date, :owner, :post_id,
5
+ setup_delegators :@struct, :comment_id, :creation_date, :owner, :post_id,
7
6
  :post_type, :score, :body
8
7
 
9
8
  class << self
@@ -1,9 +1,8 @@
1
1
  module StackExchange
2
2
  module StackOverflow
3
3
  class Question < Base
4
- extend Forwardable
5
4
 
6
- def_delegators :@struct, :question_id, :tags, :creation_date, :last_activity_date,
5
+ setup_delegators :@struct, :question_id, :tags, :creation_date, :last_activity_date,
7
6
  :up_vote_count, :down_vote_count, :view_count, :score,
8
7
  :community_owned, :title, :body, :answers, :answer_count,
9
8
  :accepted_answer_id, :favorite_count, :question_timeline_url,
@@ -2,9 +2,7 @@ module StackExchange
2
2
  module StackOverflow
3
3
  class Statistics < Base
4
4
 
5
- extend Forwardable
6
-
7
- def_delegators :@struct, :total_questions, :total_unanswered, :total_answers,
5
+ setup_delegators :@struct, :total_questions, :total_unanswered, :total_answers,
8
6
  :total_comments, :total_votes, :total_badges,
9
7
  :total_users, :questions_per_minute, :answers_per_minute,
10
8
  :badges_per_minute, :api_version
@@ -1,9 +1,8 @@
1
1
  module StackExchange
2
2
  module StackOverflow
3
3
  class Tag < Base
4
- extend Forwardable
5
4
 
6
- def_delegators :@struct, :name, :count, :user_id
5
+ setup_delegators :@struct, :name, :count, :user_id
7
6
 
8
7
  class << self
9
8
  def all(options = {})
@@ -1,16 +1,15 @@
1
1
  module StackExchange
2
2
  module StackOverflow
3
3
  class User < Base
4
- extend Forwardable
5
4
 
6
- def_delegators :@struct, :user_id, :user_type, :creation_date, :display_name,
5
+ setup_delegators :@struct, :user_id, :user_type, :creation_date, :display_name,
7
6
  :reputation, :email_hash, :age, :last_access_date,
8
7
  :website_url, :location, :about_me, :question_count,
9
8
  :answer_count, :view_count, :up_vote_count, :down_vote_count,
10
9
  :user_questions_url, :user_answers_url, :user_favorites_url,
11
10
  :user_tags_url, :user_badges_url, :user_timeline_url,
12
11
  :user_mentioned_url, :user_comments_url, :user_reputation_url,
13
- :badge_counts
12
+ :badge_counts, :accept_rate
14
13
 
15
14
  class << self
16
15
  def all(options = {})
@@ -0,0 +1,238 @@
1
+ {
2
+ "total": 11,
3
+ "page": 1,
4
+ "pagesize": 30,
5
+ "answers": [
6
+ {
7
+ "answer_id": 6403189,
8
+ "accepted": false,
9
+ "answer_comments_url": "/answers/6403189/comments",
10
+ "question_id": 2014765,
11
+ "owner": {
12
+ "user_id": 741955,
13
+ "user_type": "registered",
14
+ "display_name": "le_Daf",
15
+ "reputation": 31,
16
+ "email_hash": "70bab86ec7b30209f01d8b1ecd4313cc"
17
+ },
18
+ "creation_date": 1308495989,
19
+ "last_activity_date": 1308495989,
20
+ "up_vote_count": 0,
21
+ "down_vote_count": 0,
22
+ "view_count": 0,
23
+ "score": 0,
24
+ "community_owned": false,
25
+ "title": "Unable to install MySQL on Mac OS X"
26
+ },
27
+ {
28
+ "answer_id": 3636127,
29
+ "accepted": false,
30
+ "answer_comments_url": "/answers/3636127/comments",
31
+ "question_id": 2014765,
32
+ "owner": {
33
+ "user_id": 438990,
34
+ "user_type": "registered",
35
+ "display_name": "Valdis",
36
+ "reputation": 313,
37
+ "email_hash": "6fa86865663eb6ae5b7ba3b66df67bd0"
38
+ },
39
+ "creation_date": 1283520109,
40
+ "last_activity_date": 1283520109,
41
+ "up_vote_count": 1,
42
+ "down_vote_count": 0,
43
+ "view_count": 0,
44
+ "score": 1,
45
+ "community_owned": false,
46
+ "title": "Unable to install MySQL on Mac OS X"
47
+ },
48
+ {
49
+ "answer_id": 2658751,
50
+ "accepted": false,
51
+ "answer_comments_url": "/answers/2658751/comments",
52
+ "question_id": 34325,
53
+ "owner": {
54
+ "user_id": 131060,
55
+ "user_type": "registered",
56
+ "display_name": "Michael E",
57
+ "reputation": 6868,
58
+ "email_hash": "ac3aecf907aaef0c19f5fa6d8ed2b31b"
59
+ },
60
+ "creation_date": 1271515929,
61
+ "last_activity_date": 1271515929,
62
+ "up_vote_count": 2,
63
+ "down_vote_count": 0,
64
+ "view_count": 0,
65
+ "score": 2,
66
+ "community_owned": false,
67
+ "title": "Should I use a cross-platform GUI-toolkit or rely on the native ones?"
68
+ },
69
+ {
70
+ "answer_id": 2015066,
71
+ "accepted": false,
72
+ "answer_comments_url": "/answers/2015066/comments",
73
+ "question_id": 2014765,
74
+ "owner": {
75
+ "user_id": 139226,
76
+ "user_type": "registered",
77
+ "display_name": "nowk",
78
+ "reputation": 2368,
79
+ "email_hash": "abc5e4c1bc544767ddace4f3e28cd6a4"
80
+ },
81
+ "creation_date": 1262800671,
82
+ "last_activity_date": 1262800671,
83
+ "up_vote_count": 0,
84
+ "down_vote_count": 0,
85
+ "view_count": 0,
86
+ "score": 0,
87
+ "community_owned": false,
88
+ "title": "Unable to install MySQL on Mac OS X"
89
+ },
90
+ {
91
+ "answer_id": 2014922,
92
+ "accepted": false,
93
+ "answer_comments_url": "/answers/2014922/comments",
94
+ "question_id": 2014765,
95
+ "owner": {
96
+ "user_id": 160699,
97
+ "user_type": "registered",
98
+ "display_name": "makevoid",
99
+ "reputation": 1087,
100
+ "email_hash": "88e8edffe72efdfadf6b50bb17d50957"
101
+ },
102
+ "creation_date": 1262799519,
103
+ "last_activity_date": 1262799519,
104
+ "up_vote_count": 1,
105
+ "down_vote_count": 0,
106
+ "view_count": 0,
107
+ "score": 1,
108
+ "community_owned": false,
109
+ "title": "Unable to install MySQL on Mac OS X"
110
+ },
111
+ {
112
+ "answer_id": 2014801,
113
+ "accepted": false,
114
+ "answer_comments_url": "/answers/2014801/comments",
115
+ "question_id": 2014765,
116
+ "owner": {
117
+ "user_id": 85309,
118
+ "user_type": "registered",
119
+ "display_name": "Topher Fangio",
120
+ "reputation": 3168,
121
+ "email_hash": "9dda75d7ad467bf2a22de8a9d695a2dd"
122
+ },
123
+ "creation_date": 1262798412,
124
+ "last_activity_date": 1262798412,
125
+ "up_vote_count": 0,
126
+ "down_vote_count": 0,
127
+ "view_count": 0,
128
+ "score": 0,
129
+ "community_owned": false,
130
+ "title": "Unable to install MySQL on Mac OS X"
131
+ },
132
+ {
133
+ "answer_id": 1508577,
134
+ "accepted": false,
135
+ "answer_comments_url": "/answers/1508577/comments",
136
+ "question_id": 34325,
137
+ "owner": {
138
+ "user_id": 155082,
139
+ "user_type": "registered",
140
+ "display_name": "Lothar",
141
+ "reputation": 2924,
142
+ "email_hash": "0f1316ecb725006d020998e6b8a0740c"
143
+ },
144
+ "creation_date": 1254475864,
145
+ "last_activity_date": 1254475864,
146
+ "up_vote_count": 1,
147
+ "down_vote_count": 0,
148
+ "view_count": 0,
149
+ "score": 1,
150
+ "community_owned": false,
151
+ "title": "Should I use a cross-platform GUI-toolkit or rely on the native ones?"
152
+ },
153
+ {
154
+ "answer_id": 34376,
155
+ "accepted": false,
156
+ "answer_comments_url": "/answers/34376/comments",
157
+ "question_id": 34325,
158
+ "owner": {
159
+ "user_id": 3114,
160
+ "user_type": "registered",
161
+ "display_name": "Brian Stewart",
162
+ "reputation": 3197,
163
+ "email_hash": "0fcc606c525ff7c0b9d9f51738abc6db"
164
+ },
165
+ "creation_date": 1220008850,
166
+ "last_activity_date": 1220008850,
167
+ "up_vote_count": 2,
168
+ "down_vote_count": 0,
169
+ "view_count": 0,
170
+ "score": 2,
171
+ "community_owned": false,
172
+ "title": "Should I use a cross-platform GUI-toolkit or rely on the native ones?"
173
+ },
174
+ {
175
+ "answer_id": 34368,
176
+ "accepted": false,
177
+ "answer_comments_url": "/answers/34368/comments",
178
+ "question_id": 34325,
179
+ "owner": {
180
+ "user_id": 1075,
181
+ "user_type": "registered",
182
+ "display_name": "KiwiBastard",
183
+ "reputation": 5922,
184
+ "email_hash": "8918922b70fe7aa6d2533d6bbb47ec76"
185
+ },
186
+ "creation_date": 1220008022,
187
+ "last_activity_date": 1220008022,
188
+ "up_vote_count": 6,
189
+ "down_vote_count": 0,
190
+ "view_count": 0,
191
+ "score": 6,
192
+ "community_owned": false,
193
+ "title": "Should I use a cross-platform GUI-toolkit or rely on the native ones?"
194
+ },
195
+ {
196
+ "answer_id": 34332,
197
+ "accepted": false,
198
+ "answer_comments_url": "/answers/34332/comments",
199
+ "question_id": 34325,
200
+ "owner": {
201
+ "user_id": 797,
202
+ "user_type": "registered",
203
+ "display_name": "Matt Sheppard",
204
+ "reputation": 8642,
205
+ "email_hash": "aef85130bf44caa9b4de0a3153e758f2"
206
+ },
207
+ "creation_date": 1220005360,
208
+ "last_activity_date": 1220005360,
209
+ "up_vote_count": 1,
210
+ "down_vote_count": 0,
211
+ "view_count": 0,
212
+ "score": 1,
213
+ "community_owned": false,
214
+ "title": "Should I use a cross-platform GUI-toolkit or rely on the native ones?"
215
+ },
216
+ {
217
+ "answer_id": 34329,
218
+ "accepted": true,
219
+ "answer_comments_url": "/answers/34329/comments",
220
+ "question_id": 34325,
221
+ "owner": {
222
+ "user_id": 2976,
223
+ "user_type": "registered",
224
+ "display_name": "paan",
225
+ "reputation": 2227,
226
+ "email_hash": "b0bfa6a253fc7106c388967d4d5bdc81"
227
+ },
228
+ "creation_date": 1220005181,
229
+ "last_activity_date": 1220005181,
230
+ "up_vote_count": 8,
231
+ "down_vote_count": 0,
232
+ "view_count": 0,
233
+ "score": 8,
234
+ "community_owned": false,
235
+ "title": "Should I use a cross-platform GUI-toolkit or rely on the native ones?"
236
+ }
237
+ ]
238
+ }
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe StackExchange::StackOverflow::Base do
4
+ it "should allow extended classes to know which of its methods are provided by the SO API" do
5
+ klass = Class.new(StackExchange::StackOverflow::Base) do
6
+ setup_delegators *%w[foo bar baz]
7
+ end
8
+
9
+ klass.api_methods.should == %w[foo bar baz]
10
+ end
11
+ end
@@ -11,6 +11,7 @@ describe StackExchange::StackOverflow::User do
11
11
  first_user = response.users.first
12
12
  first_user.should be_instance_of StackOverflow::User
13
13
  first_user.user_id.should == 349130
14
+ first_user.accept_rate.should_not be_nil
14
15
  first_user.user_type.should == "registered"
15
16
  first_user.creation_date.should == 1274719205
16
17
  first_user.display_name.should == "matias.valdenegro"
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pilha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
5
+ version: 0.2.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - Dalto Curvelano Junior
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-04-28 00:00:00 -03:00
13
+ date: 2011-12-04 00:00:00 -02:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 1
32
- - 4
33
- - 0
34
24
  version: 1.4.0
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,9 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
35
  version: "0"
49
36
  type: :development
50
37
  version_requirements: *id002
@@ -56,9 +43,6 @@ dependencies:
56
43
  requirements:
57
44
  - - ">="
58
45
  - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
46
  version: "0"
63
47
  type: :development
64
48
  version_requirements: *id003
@@ -87,6 +71,7 @@ files:
87
71
  - spec/pilha/stack_overflow/badge_spec.rb
88
72
  - spec/pilha/stack_overflow/stack_overflow_spec.rb
89
73
  - spec/pilha/stack_overflow/comment_spec.rb
74
+ - spec/pilha/stack_overflow/base_spec.rb
90
75
  - spec/pilha/stack_overflow/question_spec.rb
91
76
  - spec/pilha/stack_overflow/tag_spec.rb
92
77
  - spec/spec_helper.rb
@@ -102,6 +87,7 @@ files:
102
87
  - spec/fixtures/answer_by_id.json.gz
103
88
  - spec/fixtures/user_tags.json
104
89
  - spec/fixtures/questions_unanswered.json
90
+ - spec/fixtures/answers_from_set_of_question_ids.json
105
91
  - spec/fixtures/tags_by_user_id.json.gz
106
92
  - spec/fixtures/comments_by_user_to_mentioned_user.json.gz
107
93
  - spec/fixtures/questions.json
@@ -132,6 +118,7 @@ files:
132
118
  - spec/fixtures/questions_tagged_ruby.json
133
119
  - spec/fixtures/stats.json
134
120
  - spec/fixtures/users_answers.json.gz
121
+ - spec/fixtures/answers_from_set_of_question_ids.json.gz
135
122
  - spec/fixtures/answer_comments.json
136
123
  - spec/fixtures/comments_by_user_to_mentioned_user.json
137
124
  - spec/fixtures/comments_by_question_id.json
@@ -164,18 +151,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
151
  requirements:
165
152
  - - ">="
166
153
  - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
169
- - 0
170
154
  version: "0"
171
155
  required_rubygems_version: !ruby/object:Gem::Requirement
172
156
  none: false
173
157
  requirements:
174
158
  - - ">="
175
159
  - !ruby/object:Gem::Version
176
- hash: 3
177
- segments:
178
- - 0
179
160
  version: "0"
180
161
  requirements: []
181
162
 
@@ -191,6 +172,7 @@ test_files:
191
172
  - spec/pilha/stack_overflow/badge_spec.rb
192
173
  - spec/pilha/stack_overflow/stack_overflow_spec.rb
193
174
  - spec/pilha/stack_overflow/comment_spec.rb
175
+ - spec/pilha/stack_overflow/base_spec.rb
194
176
  - spec/pilha/stack_overflow/question_spec.rb
195
177
  - spec/pilha/stack_overflow/tag_spec.rb
196
178
  - spec/spec_helper.rb
@@ -206,6 +188,7 @@ test_files:
206
188
  - spec/fixtures/answer_by_id.json.gz
207
189
  - spec/fixtures/user_tags.json
208
190
  - spec/fixtures/questions_unanswered.json
191
+ - spec/fixtures/answers_from_set_of_question_ids.json
209
192
  - spec/fixtures/tags_by_user_id.json.gz
210
193
  - spec/fixtures/comments_by_user_to_mentioned_user.json.gz
211
194
  - spec/fixtures/questions.json
@@ -236,6 +219,7 @@ test_files:
236
219
  - spec/fixtures/questions_tagged_ruby.json
237
220
  - spec/fixtures/stats.json
238
221
  - spec/fixtures/users_answers.json.gz
222
+ - spec/fixtures/answers_from_set_of_question_ids.json.gz
239
223
  - spec/fixtures/answer_comments.json
240
224
  - spec/fixtures/comments_by_user_to_mentioned_user.json
241
225
  - spec/fixtures/comments_by_question_id.json