rally_rest_api 1.0.6 → 1.1.0
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.
@@ -59,10 +59,11 @@ end
|
|
59
59
|
class RestBuilder # :nodoc:
|
60
60
|
|
61
61
|
attr_reader :base_url, :username, :password, :http_headers
|
62
|
-
attr_accessor :logger
|
62
|
+
attr_accessor :logger, :use_cookies
|
63
63
|
|
64
64
|
def initialize(base_url, username, password, version = "current", http_headers = CustomHttpHeader.new)
|
65
65
|
@base_url, @username, @password, @version, @http_headers = base_url, username, password, version, http_headers
|
66
|
+
@cookie_jar = {}
|
66
67
|
end
|
67
68
|
|
68
69
|
def marshal_dump
|
@@ -130,16 +131,48 @@ class RestBuilder # :nodoc:
|
|
130
131
|
send_request(url, req, username, password)
|
131
132
|
end
|
132
133
|
|
134
|
+
def add_cookies(req)
|
135
|
+
req.add_field('cookie', format_cookie(@cookie_jar))
|
136
|
+
req
|
137
|
+
end
|
138
|
+
|
139
|
+
def parse_cookies (cookie_str)
|
140
|
+
cookies = cookie_str.split(', ')
|
141
|
+
cookies.collect! { |cookie| cookie.split(";")[0] }
|
142
|
+
|
143
|
+
cookie_jar = {}
|
144
|
+
cookies.each do |cookie|
|
145
|
+
c = cookie.split("=")
|
146
|
+
cookie_jar[c[0]] = c[1] || ""
|
147
|
+
end
|
148
|
+
cookie_jar
|
149
|
+
end
|
150
|
+
|
151
|
+
def format_cookie (cookie_jar)
|
152
|
+
cookie_str = ""
|
153
|
+
cookie_jar.each do |cookie_name, cookie_value|
|
154
|
+
cookie_str += "; " unless cookie_str.empty?
|
155
|
+
cookie_str += "#{cookie_name}=#{cookie_value}"
|
156
|
+
end
|
157
|
+
cookie_str
|
158
|
+
end
|
159
|
+
|
160
|
+
def store_cookies(response)
|
161
|
+
@cookie_jar.merge!(parse_cookies(response.response['set-cookie']))
|
162
|
+
response
|
163
|
+
end
|
164
|
+
|
133
165
|
def send_request(url, req, username, password)
|
134
166
|
@http_headers.add_headers(req)
|
135
167
|
req.basic_auth username, password
|
136
168
|
req.content_type = 'text/xml'
|
137
169
|
req.add_field('Accept-Encoding', 'gzip, deflate')
|
170
|
+
add_cookies(req) if @use_cookies
|
138
171
|
proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
|
139
172
|
http = Net::HTTP.new(url.host, url.port, proxy.host, proxy.port, proxy.user, proxy.password)
|
140
173
|
http.use_ssl = true if url.scheme == "https"
|
141
174
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
142
|
-
http.ssl_version = "SSLv3"
|
175
|
+
#http.ssl_version = "SSLv3"
|
143
176
|
http.read_timeout = 300
|
144
177
|
debug "RestBuilder#send_request req = #{req.inspect} -- #{url}"
|
145
178
|
response = http.start { |http| http.request(req) }
|
@@ -149,6 +182,7 @@ class RestBuilder # :nodoc:
|
|
149
182
|
debug "RestBuilder#send_request result = #{response.plain_body}"
|
150
183
|
headerstr = ""
|
151
184
|
response.each_header { |k,v| headerstr << "#{k}--#{v}|" }
|
185
|
+
store_cookies(response) if @use_cookies
|
152
186
|
debug "RestBuilder#send_request result headers = #{headerstr} and length is #{response.plain_body.length}"
|
153
187
|
check_for_errors(response)
|
154
188
|
response.plain_body
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rally_rest_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.6
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bob Cotton
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-05-16 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: ""
|