rally_api 0.8.5 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/rally_api.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
#Copyright (c) 2002-2012 Rally Software Development Corp. All Rights Reserved.
|
3
|
+
#Your use of this Software is governed by the terms and conditions
|
4
|
+
#of the applicable Subscription Agreement between your company and
|
5
|
+
#Rally Software Development Corp.
|
6
|
+
# :startdoc:
|
7
|
+
|
8
|
+
module RallyAPI
|
9
|
+
|
10
|
+
class RallyCollection
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
attr_reader :results
|
14
|
+
alias :values :results
|
15
|
+
|
16
|
+
def initialize(results)
|
17
|
+
@results = results
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](index)
|
21
|
+
if (index.kind_of? Fixnum)
|
22
|
+
@results[index]
|
23
|
+
else
|
24
|
+
all = @results.find_all { |object| object.name == index }
|
25
|
+
all.length == 1 ? all[0] : all
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def each(&block)
|
30
|
+
if (block.parameters.length == 2)
|
31
|
+
@results.each do |record|
|
32
|
+
block.call(record.to_s, record)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@results.each &block
|
36
|
+
end
|
37
|
+
end
|
38
|
+
alias :each_value :each
|
39
|
+
|
40
|
+
def size
|
41
|
+
length
|
42
|
+
end
|
43
|
+
|
44
|
+
def length
|
45
|
+
@results.count
|
46
|
+
end
|
47
|
+
|
48
|
+
def include?(name)
|
49
|
+
self[name.to_s] != []
|
50
|
+
end
|
51
|
+
|
52
|
+
def empty?
|
53
|
+
length == 0
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -25,7 +25,7 @@ module RallyAPI
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def to_s(*args)
|
28
|
-
|
28
|
+
get_val('Name') || get_val('_refObjectName')
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_json(*args)
|
@@ -45,6 +45,7 @@ module RallyAPI
|
|
45
45
|
@rally_object = @rally_rest.reread(rally_object, params)
|
46
46
|
self
|
47
47
|
end
|
48
|
+
alias :refresh :read
|
48
49
|
|
49
50
|
def getref
|
50
51
|
ref
|
@@ -54,6 +55,58 @@ module RallyAPI
|
|
54
55
|
rally_object["_ref"]
|
55
56
|
end
|
56
57
|
|
58
|
+
def camel_case_word(sym)
|
59
|
+
RallyAPI::RallyRestJson.camel_case_word(sym)
|
60
|
+
end
|
61
|
+
|
62
|
+
def elements
|
63
|
+
@rally_object.inject({}) do |elements, (key, value)|
|
64
|
+
if key.to_s.starts_with?("c_")
|
65
|
+
key = key.to_s[2..-1]
|
66
|
+
end
|
67
|
+
elements[underscore(key).to_sym] = value
|
68
|
+
elements
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def oid
|
73
|
+
object_i_d
|
74
|
+
end
|
75
|
+
|
76
|
+
def username
|
77
|
+
user_name || login_name
|
78
|
+
end
|
79
|
+
|
80
|
+
def password
|
81
|
+
@rally_rest.rally_password
|
82
|
+
end
|
83
|
+
|
84
|
+
def ==(object)
|
85
|
+
object.equal?(self) ||
|
86
|
+
(object.instance_of?(self.class) &&
|
87
|
+
object.ref == ref)
|
88
|
+
end
|
89
|
+
|
90
|
+
def eql?(object)
|
91
|
+
self == (object)
|
92
|
+
end
|
93
|
+
|
94
|
+
def <=>(object)
|
95
|
+
self.ref <=> object.ref
|
96
|
+
end
|
97
|
+
|
98
|
+
def hash
|
99
|
+
self.ref.hash
|
100
|
+
end
|
101
|
+
|
102
|
+
def name
|
103
|
+
get_val('Name') || get_val('_refObjectName')
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_q
|
107
|
+
@rally_object["_ref"]
|
108
|
+
end
|
109
|
+
|
57
110
|
def rank_above(relative_rally_object)
|
58
111
|
@rally_object = @rally_rest.rank_above(rally_object["_ref"],relative_rally_object["_ref"]).rally_object
|
59
112
|
self
|
@@ -90,21 +143,55 @@ module RallyAPI
|
|
90
143
|
ret_val
|
91
144
|
end
|
92
145
|
|
146
|
+
#def get_val(field)
|
147
|
+
# return_val = rally_object[field]
|
148
|
+
#
|
149
|
+
# if return_val.class == Hash
|
150
|
+
# return RallyObject.new(@rally_rest, return_val)
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# if return_val.class == Array
|
154
|
+
# make_object_array(field)
|
155
|
+
# return_val = rally_object[field]
|
156
|
+
# end
|
157
|
+
#
|
158
|
+
# return_val
|
159
|
+
#end
|
160
|
+
|
93
161
|
def get_val(field)
|
94
|
-
return_val = rally_object[field]
|
162
|
+
return_val = @rally_object[field]
|
163
|
+
return_val = @rally_object["c_#{field}"] if return_val.nil?
|
95
164
|
|
96
165
|
if return_val.class == Hash
|
166
|
+
if return_val.has_key?("_ref")
|
167
|
+
return read_association return_val
|
168
|
+
end
|
97
169
|
return RallyObject.new(@rally_rest, return_val)
|
98
170
|
end
|
99
171
|
|
100
172
|
if return_val.class == Array
|
101
173
|
make_object_array(field)
|
102
|
-
return_val = rally_object[field]
|
174
|
+
return_val = @rally_object[field]
|
103
175
|
end
|
104
176
|
|
105
177
|
return_val
|
106
178
|
end
|
107
179
|
|
180
|
+
def read_association(object_or_collection)
|
181
|
+
return read_collection(object_or_collection) if object_or_collection.has_key? 'Count'
|
182
|
+
return RallyObject.new(@rally_rest, @rally_rest.reread(object_or_collection)) if @rally_rest.rally_rest_api_compat
|
183
|
+
RallyObject.new(@rally_rest, object_or_collection)
|
184
|
+
end
|
185
|
+
|
186
|
+
def read_collection(collection)
|
187
|
+
results = @rally_rest.reread(collection)["Results"]
|
188
|
+
RallyCollection.new(results.collect { |object| RallyObject.new(@rally_rest, object) })
|
189
|
+
end
|
190
|
+
|
191
|
+
def underscore(camel_cased_word)
|
192
|
+
camel_cased_word.split(/(?=[A-Z])/).join('_').downcase
|
193
|
+
end
|
194
|
+
|
108
195
|
def make_object_array(field)
|
109
196
|
object_array = []
|
110
197
|
rally_object[field].each do |rally_obj|
|
@@ -113,11 +200,6 @@ module RallyAPI
|
|
113
200
|
rally_object[field] = object_array
|
114
201
|
end
|
115
202
|
|
116
|
-
#taken from rally_rest_api - to try to help with backwards compatibility
|
117
|
-
def camel_case_word(sym)
|
118
|
-
sym.to_s.split("_").map { |word| word.capitalize }.join
|
119
|
-
end
|
120
|
-
|
121
203
|
end
|
122
204
|
|
123
205
|
end
|
@@ -28,6 +28,8 @@ module RallyAPI
|
|
28
28
|
attr_accessor :type, :query_string, :fetch, :workspace, :project, :project_scope_up, :project_scope_down
|
29
29
|
attr_accessor :order, :page_size, :limit
|
30
30
|
|
31
|
+
alias :pagesize :page_size
|
32
|
+
|
31
33
|
def initialize(query_hash = nil)
|
32
34
|
parse_query_hash(query_hash) if !query_hash.nil?
|
33
35
|
@page_size = 200 if @page_size.nil?
|
@@ -8,7 +8,7 @@ module RallyAPI
|
|
8
8
|
class RallyQueryResult
|
9
9
|
include Enumerable
|
10
10
|
|
11
|
-
|
11
|
+
attr_reader :results, :total_result_count
|
12
12
|
|
13
13
|
def initialize(rally_rest, json_results)
|
14
14
|
@results = json_results["QueryResult"]["Results"]
|
@@ -34,5 +34,13 @@ module RallyAPI
|
|
34
34
|
@results.length
|
35
35
|
end
|
36
36
|
|
37
|
+
def empty?
|
38
|
+
length == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def results #for compatiblity with code using rally_rest_api
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
37
45
|
end
|
38
46
|
end
|
@@ -49,7 +49,6 @@ module RallyAPI
|
|
49
49
|
attr_accessor :rally_url, :rally_user, :rally_password, :rally_workspace_name, :rally_project_name, :wsapi_version
|
50
50
|
attr_accessor :rally_headers, :rally_default_workspace, :rally_default_project, :low_debug, :proxy_info
|
51
51
|
attr_accessor :rally_rest_api_compat, :logger, :rally_alias_types
|
52
|
-
|
53
52
|
attr_reader :rally_connection
|
54
53
|
|
55
54
|
def initialize(args)
|
@@ -143,9 +142,10 @@ module RallyAPI
|
|
143
142
|
end
|
144
143
|
|
145
144
|
ws_ref = fields["Workspace"]
|
146
|
-
ws_ref = ws_ref["_ref"] unless ws_ref.class == String
|
145
|
+
ws_ref = ws_ref["_ref"] unless ws_ref.class == String || ws_ref.nil?
|
147
146
|
params = { :workspace => ws_ref }
|
148
147
|
|
148
|
+
fields = RallyAPI::RallyRestJson.fix_case(fields) if @rally_rest_api_compat
|
149
149
|
object2create = { type => make_ref_fields(fields) }
|
150
150
|
args = { :method => :post, :payload => object2create }
|
151
151
|
#json_response = @rally_connection.create_object(make_create_url(rally_type), args, object2create)
|
@@ -183,10 +183,10 @@ module RallyAPI
|
|
183
183
|
json_response[rally_type]
|
184
184
|
end
|
185
185
|
|
186
|
-
|
187
186
|
def update(type, obj_id, fields)
|
188
187
|
type = check_type(type)
|
189
188
|
ref = check_id(type.to_s, obj_id)
|
189
|
+
fields = RallyAPI::RallyRestJson.fix_case(fields) if @rally_rest_api_compat
|
190
190
|
json_update = { type.to_s => make_ref_fields(fields) }
|
191
191
|
args = { :method => :post, :payload => json_update }
|
192
192
|
#json_response = @rally_connection.update_object(ref, args, json_update)
|
@@ -194,6 +194,7 @@ module RallyAPI
|
|
194
194
|
#todo check for warnings on json_response["OperationResult"]
|
195
195
|
RallyObject.new(self, reread({"_ref" => ref}))
|
196
196
|
end
|
197
|
+
alias :update_ref :update
|
197
198
|
|
198
199
|
##-----
|
199
200
|
#Querying Rally example
|
@@ -356,14 +357,15 @@ module RallyAPI
|
|
356
357
|
false
|
357
358
|
end
|
358
359
|
|
359
|
-
#expecting idstring to have "FormattedID|DE45" or the objectID
|
360
|
+
#expecting idstring to have "FormattedID|DE45" or the objectID or a ref itself
|
360
361
|
def check_id(type, idstring)
|
361
362
|
if idstring.class == Fixnum
|
362
363
|
return make_read_url(type, idstring)
|
363
364
|
end
|
364
365
|
|
365
|
-
if (idstring.class == String)
|
366
|
-
return
|
366
|
+
if (idstring.class == String)
|
367
|
+
return idstring if idstring.index("http") == 0
|
368
|
+
return ref_by_formatted_id(type, idstring.split("|")[1]) if idstring.index("FormattedID") == 0
|
367
369
|
end
|
368
370
|
make_read_url(type, idstring)
|
369
371
|
end
|
@@ -387,14 +389,56 @@ module RallyAPI
|
|
387
389
|
end
|
388
390
|
|
389
391
|
def make_ref_fields(fields)
|
390
|
-
fields.each do |key,val|
|
391
|
-
|
392
|
-
fields[key] = val.getref
|
393
|
-
end
|
392
|
+
fields.each do |key, val|
|
393
|
+
fields[key] = make_ref_field(val)
|
394
394
|
end
|
395
395
|
fields
|
396
396
|
end
|
397
397
|
|
398
|
+
def make_ref_field(val)
|
399
|
+
return val.getref if val.kind_of? RallyObject
|
400
|
+
return val if val.kind_of? Hash
|
401
|
+
return val if val.is_a?(Hash)
|
402
|
+
|
403
|
+
if val.kind_of? Enumerable
|
404
|
+
return val.collect do |collection_element|
|
405
|
+
if collection_element.kind_of? RallyObject
|
406
|
+
{"_type" => collection_element.type, "_ref" => collection_element.getref}
|
407
|
+
else
|
408
|
+
collection_element
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
val
|
414
|
+
end
|
415
|
+
|
416
|
+
def self.fix_case(values)
|
417
|
+
values.inject({}) do |new_values, (key, value)|
|
418
|
+
new_values[camel_case_word(key)] = value.is_a?(Hash) ? fix_case(value) : value
|
419
|
+
new_values
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
def self.camel_case_word(sym)
|
424
|
+
word = sym.to_s
|
425
|
+
|
426
|
+
if word.start_with? ("c_")
|
427
|
+
custom_field_without_c = word.sub("c_", "")
|
428
|
+
camelized = camelize(custom_field_without_c)
|
429
|
+
camelized[0] = custom_field_without_c[0]
|
430
|
+
"c_#{camelized}"
|
431
|
+
else
|
432
|
+
camelize(word)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
#implemented basic version here to not have to include ActiveSupport
|
437
|
+
def self.camelize(str)
|
438
|
+
str.split('_').map {|w| w.capitalize}.join
|
439
|
+
end
|
440
|
+
|
441
|
+
|
398
442
|
end
|
399
443
|
|
400
444
|
end
|
data/lib/rally_api/version.rb
CHANGED
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.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpclient
|
16
|
-
requirement: &
|
16
|
+
requirement: &70127257258460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.2.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70127257258460
|
25
25
|
description: API wrapper for Rally's JSON REST web services api
|
26
26
|
email:
|
27
27
|
- dsmith@rallydev.com
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- Rakefile
|
34
34
|
- lib/rally_api/custom_http_header.rb
|
35
35
|
- lib/rally_api/lookback_api_query.rb
|
36
|
+
- lib/rally_api/rally_collection.rb
|
36
37
|
- lib/rally_api/rally_json_connection.rb
|
37
38
|
- lib/rally_api/rally_object.rb
|
38
39
|
- lib/rally_api/rally_query.rb
|