rally_api 0.6.0 → 0.7.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.
@@ -1,4 +1,4 @@
1
- require 'rest_client'
1
+ require "httpclient"
2
2
  require 'json'
3
3
 
4
4
  # :stopdoc:
@@ -15,70 +15,30 @@ module RallyAPI
15
15
 
16
16
  DEFAULT_PAGE_SIZE = 200
17
17
 
18
- attr_accessor :rally_headers, :retries, :retry_list, :low_debug, :logger
18
+ attr_accessor :rally_headers, :low_debug, :logger
19
19
 
20
20
  def initialize(headers, low_debug, proxy_info)
21
21
  @rally_headers = headers
22
22
  @low_debug = low_debug
23
23
  @logger = nil
24
24
 
25
- @retries = 0
26
- @retry_list = {}
25
+ @rally_http_client = HTTPClient.new
26
+ @rally_http_client.receive_timeout = 300
27
+ @rally_http_client.send_timeout = 300
28
+ @rally_http_client.transparent_gzip_decompression = true
27
29
 
28
- if (!ENV["http_proxy"].nil?) && (proxy_info.nil?)
29
- RestClient.proxy = ENV['http_proxy']
30
+ #passed in proxy setup overrides env level proxy
31
+ env_proxy = ENV["http_proxy"]
32
+ if (!env_proxy.nil?) && (proxy_info.nil?)
33
+ @rally_http_client.proxy = env_proxy
30
34
  end
31
-
32
- if !proxy_info.nil?
33
- RestClient.proxy = proxy_info
34
- end
35
-
36
- end
37
-
38
- def read_object(url, args, params = nil)
39
- args[:method] = :get
40
- result = send_json_request(url, args, params)
41
- log_info(result) if @low_debug
42
- rally_type = result.keys[0]
43
- result[rally_type]
44
- end
45
-
46
- def create_object(url, args, rally_object)
47
- args[:method] = :post
48
- text_json = rally_object.to_json
49
- args[:payload] = text_json
50
- log_info("create - payload json: #{text_json}") if @low_debug
51
- result = send_json_request(url, args)
52
- log_info("create - result: #{result}") if @low_debug
53
- result["CreateResult"]["Object"]
54
- end
55
-
56
- def update_object(url, args, rally_fields)
57
- args[:method] = :post
58
- text_json = rally_fields.to_json
59
- args[:payload] = text_json
60
- log_info("update payload json: #{text_json}") if @low_debug
61
- result = send_json_request(url, args)
62
- log_info("update - result: #{result}") if @low_debug
63
- result["OperationResult"]
64
- end
65
-
66
- def put_object(url, args, put_params, rally_fields)
67
- args[:method] = :put
68
- text_json = rally_fields.to_json
69
- args[:payload] = text_json
70
- result = send_json_request(url, args, put_params)
71
- result["OperationResult"]
35
+ @rally_http_client.proxy = proxy_info unless !proxy_info.nil?
72
36
  end
73
37
 
74
- def delete_object(url,args)
75
- args[:method] = :delete
76
- result = send_json_request(url,args)
77
- log_info("delete result - #{result}") if @low_debug
78
- result["OperationResult"]
38
+ def set_client_user(base_url, user, password)
39
+ @rally_http_client.set_basic_auth(base_url, user, password)
79
40
  end
80
41
 
81
- #---------------------------------------------
82
42
  def get_all_json_results(url, args, query_params, limit = 99999)
83
43
  all_results = []
84
44
  args[:method] = :get
@@ -87,7 +47,8 @@ module RallyAPI
87
47
  params[:start] = 1
88
48
  params = params.merge(query_params)
89
49
 
90
- query_result = send_json_request(url, args, params)
50
+ #query_result = send_json_request(url, args, params)
51
+ query_result = send_request(url, args, params)
91
52
  all_results.concat(query_result["QueryResult"]["Results"])
92
53
  totals = query_result["QueryResult"]["TotalResultCount"]
93
54
 
@@ -110,6 +71,36 @@ module RallyAPI
110
71
  query_result
111
72
  end
112
73
 
74
+ #args should have :method
75
+ def send_request(url, args, url_params = {})
76
+ method = args[:method]
77
+ req_args = { :query => url_params }
78
+
79
+ req_headers = @rally_headers.headers
80
+ if (args[:method] == :post) || (args[:method] == :put)
81
+ req_headers["Content-Type"] = "application/json"
82
+ req_headers["Accept"] = "application/json"
83
+ text_json =args[:payload].to_json
84
+ req_args[:body] = text_json
85
+ end
86
+ req_args[:header] = req_headers
87
+
88
+ begin
89
+ log_info("Rally API calling #{method} - #{url} with #{req_args}") if @low_debug
90
+ response = @rally_http_client.request(method, url, req_args)
91
+ rescue Exception => ex
92
+ msg = "Rally Rest Json: - rescued exception - #{ex.message} on request to #{url} with params #{url_params}"
93
+ log_info(msg)
94
+ raise StandardError, msg
95
+ end
96
+
97
+ log_info("RallyAPI response was - #{response.inspect}") if @low_debug
98
+ json_obj = JSON.parse(response.body) #todo handle null post error
99
+ errs = check_for_errors(json_obj)
100
+ raise StandardError, "\nError on request - #{url} - \n#{errs}" if errs[:errors].length > 0
101
+ json_obj
102
+ end
103
+
113
104
  private
114
105
 
115
106
  def run_threads(query_array)
@@ -132,57 +123,13 @@ module RallyAPI
132
123
  Thread.new do
133
124
  thread_results = []
134
125
  request_array.each do |req|
135
- page_res = send_json_request(req[:url], req[:args], req[:params])
126
+ page_res = send_request(req[:url], req[:args], req[:params])
136
127
  thread_results.push({:page_num => req[:page_num], :results => page_res})
137
128
  end
138
129
  thread_results
139
130
  end
140
131
  end
141
132
 
142
- def send_json_request(url, args, url_params = nil)
143
- request_args = {}
144
- request_args[:url] = url
145
- request_args[:user] = args[:user]
146
- request_args[:password] = args[:password]
147
- request_args[:method] = args[:method]
148
- request_args[:timeout] = 120
149
- request_args[:open_timeout] = 120
150
-
151
- r_headers = @rally_headers.headers
152
- r_headers[:params] = url_params
153
-
154
- if (args[:method] == :post) || (args[:method] == :put)
155
- r_headers[:content_type] = :json
156
- r_headers[:accept] = :json
157
- request_args[:payload] = args[:payload]
158
- end
159
-
160
- request_args[:headers] = r_headers
161
-
162
- begin
163
- req = RestClient::Request.new(request_args)
164
- log_info(req.url) if @low_debug
165
- response = req.execute
166
- rescue => ex
167
- msg = "Rally Rest Json: - rescued exception - #{ex.message} on request to #{url} with params #{url_params}"
168
- log_info(msg)
169
- if !@retry_list.has_key?(req.url)
170
- @retry_list[req.url] = 0
171
- end
172
- if (@retries > 0) && (retry_list[req.url] < @retries)
173
- @retry_list[req.url] += 1
174
- retry
175
- end
176
- raise StandardError, msg
177
- end
178
- @retry_list.delete(req.url)
179
- log_info(response) if @low_debug
180
- json_obj = JSON.parse(response.body) #todo handle null post error
181
- errs = check_for_errors(json_obj)
182
- raise StandardError, "\nError on request - #{url} - \n#{errs}" if errs[:errors].length > 0
183
- json_obj
184
- end
185
-
186
133
  def log_info(message)
187
134
  puts message if @logger.nil?
188
135
  @logger.debug(message) unless @logger.nil?
@@ -72,7 +72,7 @@ module RallyAPI
72
72
  def method_missing(sym, *args)
73
73
  ret_val = get_val(sym.to_s)
74
74
  if @rally_rest.rally_rest_api_compat && ret_val.nil?
75
- ret_val = get_val(camel_case_word(:sym))
75
+ ret_val = get_val(camel_case_word(sym))
76
76
  end
77
77
  ret_val
78
78
  end
@@ -68,6 +68,7 @@ module RallyAPI
68
68
  @logger = args[:logger] || nil #assumes this is an instance of Logger
69
69
 
70
70
  @rally_connection = RallyJsonConnection.new(@rally_headers, @low_debug, @proxy_info)
71
+ @rally_connection.set_client_user(@rally_url, @rally_user, @rally_password)
71
72
  @rally_connection.logger = @logger unless @logger.nil?
72
73
  @rally_connection.retries = @retries if @retries > 0
73
74
 
@@ -128,9 +129,10 @@ module RallyAPI
128
129
  end
129
130
 
130
131
  def user
131
- args = {:user => @rally_user, :password => @rally_password}
132
- json_response = @rally_connection.read_object(make_get_url(@rally_objects[:user]), args)
133
- RallyObject.new(self, json_response)
132
+ args = { :method => :get }
133
+ json_response = @rally_connection.send_request(make_get_url(@rally_objects[:user]), args)
134
+ rally_type = json_response.keys[0]
135
+ RallyObject.new(self, json_response[rally_type])
134
136
  end
135
137
 
136
138
 
@@ -142,29 +144,38 @@ module RallyAPI
142
144
  fields["Project"] = @rally_default_project._ref unless @rally_default_project.nil?
143
145
  end
144
146
 
145
- args = {:user => @rally_user, :password => @rally_password }
146
147
  object2create = { rally_type => make_ref_fields(fields) }
147
- json_response = @rally_connection.create_object(make_create_url(rally_type), args, object2create)
148
- RallyObject.new(self, json_response).read()
148
+ args = { :method => :post, :payload => object2create }
149
+ #json_response = @rally_connection.create_object(make_create_url(rally_type), args, object2create)
150
+ json_response = @rally_connection.send_request(make_create_url(rally_type), args, object2create)
151
+ #todo - check for warnings
152
+ RallyObject.new(self, json_response["CreateResult"]["Object"]).read()
149
153
  end
150
154
 
151
155
 
152
156
  def read(type, obj_id, params = nil)
153
157
  rally_type = check_type(type)
154
158
  ref = check_id(rally_type, obj_id)
155
- args = {:user => @rally_user, :password => @rally_password}
156
- json_response = @rally_connection.read_object(ref, args, params)
157
- RallyObject.new(self, json_response)
159
+ args = { :method => :get }
160
+ #json_response = @rally_connection.read_object(ref, args, params)
161
+ json_response = @rally_connection.send_request(ref, args, params)
162
+ rally_type = json_response.keys[0]
163
+ RallyObject.new(self, json_response[rally_type])
158
164
  end
159
165
 
160
166
  def delete(ref_to_delete)
161
- args = {:user => @rally_user, :password => @rally_password}
162
- @rally_connection.delete_object(ref_to_delete, args)
167
+ args = { :method => :delete }
168
+ #json_response = @rally_connection.delete_object(ref_to_delete, args)
169
+ json_response = @rally_connection.send_request(ref_to_delete, args)
170
+ json_response["OperationResult"]
163
171
  end
164
172
 
165
173
  def reread(json_object, params = nil)
166
- args = {:user => @rally_user, :password => @rally_password}
167
- @rally_connection.read_object(json_object["_ref"], args, params)
174
+ args = { :method => :get }
175
+ #json_response = @rally_connection.read_object(json_object["_ref"], args, params)
176
+ json_response = @rally_connection.send_request(json_object["_ref"], args, params)
177
+ rally_type = json_response.keys[0]
178
+ json_response[rally_type]
168
179
  end
169
180
 
170
181
 
@@ -172,8 +183,10 @@ module RallyAPI
172
183
  rally_type = check_type(type)
173
184
  ref = check_id(rally_type, obj_id)
174
185
  json_update = { rally_type => make_ref_fields(fields) }
175
- args = {:user => @rally_user, :password => @rally_password}
176
- @rally_connection.update_object(ref, args, json_update)
186
+ args = { :method => :post, :payload => json_update }
187
+ #json_response = @rally_connection.update_object(ref, args, json_update)
188
+ json_response = @rally_connection.send_request(ref, args)
189
+ #todo check for warnings on json_response["OperationResult"]
177
190
  RallyObject.new(self, reread({"_ref" => ref}))
178
191
  end
179
192
 
@@ -228,9 +241,10 @@ module RallyAPI
228
241
  params[:rankAbove] = short_ref(relative_ref)
229
242
  params[:fetch] = "true"
230
243
  json_update = { get_type_from_ref(ref_to_rank) => {"_ref" => ref_to_rank} }
231
- args = {:user => @rally_user, :password => @rally_password}
232
- update = @rally_connection.put_object(ref, args, params, json_update)
233
- RallyObject.new(self, update["Object"])
244
+ args = { :method => :put, :payload => json_update }
245
+ #update = @rally_connection.put_object(ref, args, params, json_update)
246
+ update = @rally_connection.send_request(ref, args, params)
247
+ RallyObject.new(self, update["OperationResult"]["Object"])
234
248
  end
235
249
 
236
250
  #ref to object.js? rankBelow=%2Fhierarchicalrequirement%2F4624552599
@@ -240,11 +254,13 @@ module RallyAPI
240
254
  params[:rankBelow] = short_ref(relative_ref)
241
255
  params[:fetch] = "true"
242
256
  json_update = { get_type_from_ref(ref_to_rank) => {"_ref" => ref_to_rank} }
243
- args = {:user => @rally_user, :password => @rally_password}
244
- update = @rally_connection.put_object(ref, args, params, json_update)
245
- RallyObject.new(self, update["Object"])
257
+ args = { :method => :put, :payload => json_update }
258
+ #update = @rally_connection.put_object(ref, args, params, json_update)
259
+ update = @rally_connection.send_request(ref, args, params)
260
+ RallyObject.new(self, update["OperationResult"]["Object"])
246
261
  end
247
262
 
263
+ #todo - check support for portfolio item fields
248
264
  def allowed_values(type, field)
249
265
  if type.class == Symbol
250
266
  query_type = @rally_objects[type]
@@ -4,5 +4,5 @@
4
4
  #of the applicable Subscription Agreement between your company and
5
5
  #Rally Software Development Corp.
6
6
  module RallyAPI
7
- VERSION = "0.6.0"
7
+ VERSION = "0.7.0"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rally_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-17 00:00:00.000000000Z
12
+ date: 2012-10-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
16
- requirement: &70337979348020 !ruby/object:Gem::Requirement
15
+ name: httpclient
16
+ requirement: &70172871514240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.6.7
21
+ version: 2.2.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70337979348020
24
+ version_requirements: *70172871514240
25
25
  description: API wrapper for Rally's JSON REST web services api
26
26
  email:
27
27
  - dsmith@rallydev.com