rally_rest_api 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,58 @@ require 'rexml/document'
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'builder'
|
6
6
|
|
7
|
+
# Intended to extend the Net::HTTP response object
|
8
|
+
# and adds support for decoding gzip and deflate encoded pages
|
9
|
+
#
|
10
|
+
# Author: Jason Stirk <http://griffin.oobleyboo.com>
|
11
|
+
# Home: http://griffin.oobleyboo.com/projects/http_encoding_helper
|
12
|
+
# Created: 5 September 2007
|
13
|
+
# Last Updated: 23 November 2007
|
14
|
+
#
|
15
|
+
# Usage:
|
16
|
+
#
|
17
|
+
# require 'net/http'
|
18
|
+
# require 'http_encoding_helper'
|
19
|
+
# headers={'Accept-Encoding' => 'gzip, deflate' }
|
20
|
+
# http = Net::HTTP.new('griffin.oobleyboo.com', 80)
|
21
|
+
# http.start do |h|
|
22
|
+
# request = Net::HTTP::Get.new('/', headers)
|
23
|
+
# response = http.request(request)
|
24
|
+
# content=response.plain_body # Method from our library
|
25
|
+
# puts "Transferred: #{response.body.length} bytes"
|
26
|
+
# puts "Compression: #{response['content-encoding']}"
|
27
|
+
# puts "Extracted: #{response.plain_body.length} bytes"
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
|
31
|
+
require 'zlib'
|
32
|
+
require 'stringio'
|
33
|
+
|
34
|
+
class Net::HTTPResponse
|
35
|
+
# Return the uncompressed content
|
36
|
+
def plain_body
|
37
|
+
encoding=self['content-encoding']
|
38
|
+
content=nil
|
39
|
+
if encoding then
|
40
|
+
case encoding
|
41
|
+
when 'gzip'
|
42
|
+
i=Zlib::GzipReader.new(StringIO.new(self.body))
|
43
|
+
content=i.read
|
44
|
+
when 'deflate'
|
45
|
+
i=Zlib::Inflate.new
|
46
|
+
content=i.inflate(self.body)
|
47
|
+
else
|
48
|
+
raise "Unknown encoding - #{encoding}"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
content=self.body
|
52
|
+
end
|
53
|
+
return content
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
7
59
|
class RestBuilder # :nodoc:
|
8
60
|
|
9
61
|
attr_reader :base_url, :username, :password, :http_headers
|
@@ -82,15 +134,20 @@ class RestBuilder # :nodoc:
|
|
82
134
|
@http_headers.add_headers(req)
|
83
135
|
req.basic_auth username, password
|
84
136
|
req.content_type = 'text/xml'
|
137
|
+
req.add_field('Accept-Encoding', 'gzip, deflate')
|
85
138
|
proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
|
86
139
|
http = Net::HTTP.new(url.host, url.port, proxy.host, proxy.port, proxy.user, proxy.password)
|
87
140
|
http.use_ssl = true if url.scheme == "https"
|
88
141
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
142
|
+
http.read_timeout = 300
|
89
143
|
debug "RestBuilder#send_request req = #{req.inspect} -- #{url}"
|
90
144
|
response = http.start { |http| http.request(req) }
|
145
|
+
#debug "RestBuilder#send_request result = #{response.body}"
|
146
|
+
#check_for_errors(response)
|
147
|
+
#response.body
|
91
148
|
debug "RestBuilder#send_request result = #{response.body}"
|
92
149
|
check_for_errors(response)
|
93
|
-
response.
|
150
|
+
response.plain_body
|
94
151
|
end
|
95
152
|
|
96
153
|
def create_builder
|
@@ -104,7 +161,8 @@ class RestBuilder # :nodoc:
|
|
104
161
|
when Net::HTTPUnauthorized
|
105
162
|
raise Rally::NotAuthenticatedError.new("Invalid Username or Password.")
|
106
163
|
else
|
107
|
-
s = response.body
|
164
|
+
#s = response.body
|
165
|
+
s = response.plain_body
|
108
166
|
document = REXML::Document.new s
|
109
167
|
node = REXML::XPath.first document, '//Errors'
|
110
168
|
raise node.to_s if node && node.has_elements?
|
@@ -211,3 +269,4 @@ class RestBuilder # :nodoc:
|
|
211
269
|
|
212
270
|
|
213
271
|
end
|
272
|
+
|
@@ -49,7 +49,7 @@ describe "a RestBuilder " do
|
|
49
49
|
it "should raise an error if the response contains an Error element" do
|
50
50
|
body = "<xml><Errors><Error/></Errors></xml>"
|
51
51
|
response = mock("response")
|
52
|
-
response.should_receive(:
|
52
|
+
response.should_receive(:plain_body).and_return(body)
|
53
53
|
lambda { @builder.check_for_errors(response) }.should raise_error(StandardError)
|
54
54
|
end
|
55
55
|
|
data/spec/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,25 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rally_rest_api
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 1.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bob Cotton
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2010-09-17 00:00:00 -06:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-10-09 00:00:00.000000000Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
description: ""
|
14
|
+
description: ''
|
23
15
|
email: bob.cotton@rallydev.com
|
24
16
|
executables: []
|
25
|
-
|
26
17
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
18
|
+
extra_rdoc_files:
|
29
19
|
- CHANGELOG.txt
|
30
20
|
- History.txt
|
31
21
|
- README.txt
|
32
|
-
files:
|
22
|
+
files:
|
33
23
|
- CHANGELOG.txt
|
34
24
|
- History.txt
|
35
25
|
- Manifest.txt
|
@@ -68,40 +58,30 @@ files:
|
|
68
58
|
- tasks/spec.rake
|
69
59
|
- tasks/svn.rake
|
70
60
|
- tasks/test.rake
|
71
|
-
has_rdoc: true
|
72
61
|
homepage: http://rally-rest-api.rubyforge.org/rally_rest_api
|
73
62
|
licenses: []
|
74
|
-
|
75
63
|
post_install_message:
|
76
|
-
rdoc_options:
|
64
|
+
rdoc_options:
|
77
65
|
- --main
|
78
66
|
- README.txt
|
79
|
-
require_paths:
|
67
|
+
require_paths:
|
80
68
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
70
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
88
|
-
- 0
|
89
|
-
version: "0"
|
90
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
76
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
segments:
|
97
|
-
- 0
|
98
|
-
version: "0"
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
99
81
|
requirements: []
|
100
|
-
|
101
82
|
rubyforge_project: rally-rest-api
|
102
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.8.6
|
103
84
|
signing_key:
|
104
85
|
specification_version: 3
|
105
86
|
summary: A Ruby interface to the Rally REST API
|
106
87
|
test_files: []
|
107
|
-
|