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.
@@ -3,6 +3,10 @@ require 'uri'
3
3
  require 'rexml/document'
4
4
  require 'ostruct'
5
5
 
6
+ module Rally
7
+ class NotAuthenticatedError < StandardError; end
8
+ end
9
+
6
10
  #
7
11
  # RallyRestAPI - A Ruby-ized interface to Rally's REST webservice API
8
12
  #
@@ -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
- body = http.start { |http| http.request(req) }.body
91
- debug "RestBuilder#send_request result = #{body}"
92
- check_for_errors(body)
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(s)
103
- document = REXML::Document.new s
104
- node = REXML::XPath.first document, '//Errors'
105
- raise node.to_s if node && node.has_elements?
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)
@@ -2,7 +2,7 @@ module RallyRestVersion #:nodoc:
2
2
  module LIBRARY_VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 7
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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",
@@ -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
@@ -1,4 +1,5 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
3
  require 'spec'
4
+ require 'net/http'
4
5
  require File.dirname(__FILE__) + '/../lib/rally_rest_api'
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.5
7
- date: 2007-10-29 00:00:00 -06:00
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