rally_rest_api 0.7.5 → 0.7.6
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.
@@ -87,10 +87,10 @@ class RestBuilder # :nodoc:
|
|
87
87
|
http.use_ssl = true if url.scheme == "https"
|
88
88
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
89
89
|
debug "RestBuilder#send_request req = #{req.inspect} -- #{url}"
|
90
|
-
|
91
|
-
debug "RestBuilder#send_request result = #{body}"
|
92
|
-
check_for_errors(
|
93
|
-
body
|
90
|
+
response = http.start { |http| http.request(req) }
|
91
|
+
debug "RestBuilder#send_request result = #{response.body}"
|
92
|
+
check_for_errors(response)
|
93
|
+
response.body
|
94
94
|
end
|
95
95
|
|
96
96
|
def create_builder
|
@@ -99,10 +99,16 @@ class RestBuilder # :nodoc:
|
|
99
99
|
b
|
100
100
|
end
|
101
101
|
|
102
|
-
def check_for_errors(
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
def check_for_errors(response)
|
103
|
+
case response
|
104
|
+
when Net::HTTPUnauthorized
|
105
|
+
raise Rally::NotAuthenticatedError.new("Invalid Username or Password.")
|
106
|
+
else
|
107
|
+
s = response.body
|
108
|
+
document = REXML::Document.new s
|
109
|
+
node = REXML::XPath.first document, '//Errors'
|
110
|
+
raise node.to_s if node && node.has_elements?
|
111
|
+
end
|
106
112
|
end
|
107
113
|
|
108
114
|
def camel_case_word(sym)
|
@@ -5,8 +5,8 @@ describe "A CustomHttpHeader" do
|
|
5
5
|
before(:each) do
|
6
6
|
@custom_http_header = CustomHttpHeader.new
|
7
7
|
@sample_values = {
|
8
|
-
:library => RallyRestVersion::LIBRARY_VERSION::STRING,
|
9
|
-
:platform => RUBY_VERSION,
|
8
|
+
:library => "RallyRestAPI version #{RallyRestVersion::LIBRARY_VERSION::STRING}",
|
9
|
+
:platform => "Ruby #{RUBY_VERSION}",
|
10
10
|
:os => RUBY_PLATFORM,
|
11
11
|
:name => 'Guacamole',
|
12
12
|
:vendor => "The Big Enchilda's Burrito Company",
|
data/test/rest_builder_spec.rb
CHANGED
@@ -46,4 +46,16 @@ describe "a RestBuilder " do
|
|
46
46
|
}, @username, @password)
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should raise an error if the response contains an Error element" do
|
50
|
+
body = "<xml><Errors><Error/></Errors></xml>"
|
51
|
+
response = mock("response")
|
52
|
+
response.should_receive(:body).and_return(body)
|
53
|
+
lambda { @builder.check_for_errors(response) }.should raise_error(StandardError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should raise a NotAuthenticatedError when a 401 response is returned" do
|
57
|
+
response = Net::HTTPUnauthorized.new("1.1", "401", "message")
|
58
|
+
lambda { @builder.check_for_errors(response) }.should raise_error(Rally::NotAuthenticatedError, /Invalid Username or Password/)
|
59
|
+
end
|
60
|
+
|
49
61
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rally_rest_api
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.7.6
|
7
|
+
date: 2007-11-21 00:00:00 -07:00
|
8
8
|
summary: A ruby-ized interface to Rally's REST webservices API
|
9
9
|
require_paths:
|
10
10
|
- lib
|