devver-octopi 0.2.8 → 0.2.9

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.
Files changed (4) hide show
  1. data/VERSION.yml +1 -2
  2. data/lib/octopi/api.rb +27 -3
  3. data/test/api_test.rb +16 -1
  4. metadata +16 -16
data/VERSION.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  ---
2
- :build:
2
+ :patch: 9
3
3
  :major: 0
4
4
  :minor: 2
5
- :patch: 8
data/lib/octopi/api.rb CHANGED
@@ -157,6 +157,26 @@ module Octopi
157
157
  end
158
158
 
159
159
  private
160
+
161
+ # http://support.github.com/discussions/site/569-using-the-v2-api-attempting-to-show-a-nonexistent-user-gives-a-500-error
162
+ # Accessing http://github.com/api/v2/json/user/show/USER when USER is a
163
+ # non-existent user will not return YAML as expected, but rather return
164
+ # HTML. HTTParty will attempt to parse the HTML as YAML, which raises
165
+ # an ArgumentError. Until this bug is fixed, we must rescue the error
166
+ # in this case and return a 404 response.
167
+ def handle_github_api_bug_569(path, format)
168
+ yield
169
+ rescue ArgumentError => error
170
+ if error.message =~ /syntax error/ && path=~/user\/show/ && format==:yaml
171
+ message =<<"__"
172
+ Artificial response created on #{__FILE__}:#{__LINE__} due to GitHub API bug 569.
173
+ See comments for details.
174
+ __
175
+ HTTParty::Response.new({}, message, 404, message, {})
176
+ else
177
+ raise
178
+ end
179
+ end
160
180
 
161
181
  def method_missing(method, *args)
162
182
  api.send(method, *args)
@@ -176,10 +196,14 @@ module Octopi
176
196
  key = "#{Api.api.class.to_s}:#{path}"
177
197
  resp = if cache
178
198
  APICache.get(key, :cache => 61) do
179
- yield(path, params, format, auth_parameters)
199
+ handle_github_api_bug_569(path, format) do
200
+ yield(path, params, format, auth_parameters)
201
+ end
180
202
  end
181
203
  else
182
- yield(path, params, format, auth_parameters)
204
+ handle_github_api_bug_569(path, format) do
205
+ yield(path, params, format, auth_parameters)
206
+ end
183
207
  end
184
208
  rescue Net::HTTPBadResponse
185
209
  raise RetryableAPIError
@@ -210,4 +234,4 @@ module Octopi
210
234
  end
211
235
 
212
236
  end
213
- end
237
+ end
data/test/api_test.rb CHANGED
@@ -37,6 +37,21 @@ class AuthenticatedTest < Test::Unit::TestCase
37
37
  end
38
38
  end
39
39
  end
40
+
41
+ context "invalid user" do
42
+
43
+ should "raise Octopi::InvalidLogin" do
44
+ # This simulates the [bad] response returned from the GitHub API due to bug 569
45
+ # http://support.github.com/discussions/site/569-using-the-v2-api-attempting-to-show-a-nonexistent-user-gives-a-500-error
46
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/user/show/invalid_user?",
47
+ :status => ["404", "Not Found"],
48
+ :body => "<html>:\n</html>")
49
+ assert_raise Octopi::NotFound do
50
+ Api.api.get("/user/show/invalid_user?", {})
51
+ end
52
+ end
53
+
54
+ end
40
55
 
41
56
  context "keys" do
42
57
  should "not be able to see keys if not authenticated" do
@@ -55,4 +70,4 @@ class AuthenticatedTest < Test::Unit::TestCase
55
70
  end
56
71
  end
57
72
  end
58
- end
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devver-octopi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Coury
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-06 00:00:00 -05:00
12
+ date: 2010-01-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -130,24 +130,24 @@ signing_key:
130
130
  specification_version: 3
131
131
  summary: A Ruby interface to GitHub API v2 (Devver Fork)
132
132
  test_files:
133
- - test/tag_test.rb
134
- - test/issue_test.rb
135
- - test/stubs/commits/fcoury/octopi/octopi.rb
136
- - test/test_helper.rb
137
- - test/key_set_test.rb
138
- - test/blob_test.rb
139
- - test/repository_test.rb
140
- - test/key_test.rb
141
133
  - test/api_test.rb
142
- - test/file_object_test.rb
143
- - test/issue_set_test.rb
144
- - test/user_test.rb
145
- - test/gist_test.rb
146
134
  - test/authenticated_test.rb
135
+ - test/blob_test.rb
147
136
  - test/branch_test.rb
148
- - test/repository_set_test.rb
149
137
  - test/commit_test.rb
138
+ - test/file_object_test.rb
139
+ - test/gist_test.rb
150
140
  - test/issue_comment.rb
151
- - examples/issues.rb
141
+ - test/issue_set_test.rb
142
+ - test/issue_test.rb
143
+ - test/key_set_test.rb
144
+ - test/key_test.rb
145
+ - test/repository_set_test.rb
146
+ - test/repository_test.rb
147
+ - test/stubs/commits/fcoury/octopi/octopi.rb
148
+ - test/tag_test.rb
149
+ - test/test_helper.rb
150
+ - test/user_test.rb
152
151
  - examples/authenticated.rb
152
+ - examples/issues.rb
153
153
  - examples/overall.rb