rally_rest_api 0.6.6 → 0.6.12
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.
- data/Manifest.txt +4 -0
- data/lib/rally_rest_api/rally_rest.rb +3 -2
- data/lib/rally_rest_api/rest_builder.rb +21 -9
- data/lib/rally_rest_api/rest_object.rb +14 -6
- data/lib/rally_rest_api/timeout_catching_rest_builder.rb +11 -0
- data/lib/rally_rest_api/typedef.rb +2 -4
- data/lib/rally_rest_api/version.rb +1 -1
- data/test/query_result_spec.rb +2 -10
- data/test/rest_builder_spec.rb +49 -0
- data/test/rest_object_spec.rb +10 -0
- data/test/tc_rest_api.rb +6 -0
- metadata +20 -8
data/Manifest.txt
CHANGED
@@ -6,6 +6,7 @@ lib/rally_rest_api/query_result.rb
|
|
6
6
|
lib/rally_rest_api/rally_rest.rb
|
7
7
|
lib/rally_rest_api.rb
|
8
8
|
lib/rally_rest_api/rest_builder.rb
|
9
|
+
lib/rally_rest_api/timeout_catching_rest_builder.rb
|
9
10
|
lib/rally_rest_api/rest_object.rb
|
10
11
|
lib/rally_rest_api/typedef.rb
|
11
12
|
lib/rally_rest_api/version.rb
|
@@ -21,3 +22,6 @@ test/tc_rest_api.rb
|
|
21
22
|
test/rest_object_spec.rb
|
22
23
|
test/tc_rest_query.rb
|
23
24
|
test/test_helper.rb
|
25
|
+
test/rest_builder_spec.rb
|
26
|
+
lib/rally_rest_api/timeout_catching_rest_builder.rb
|
27
|
+
|
@@ -37,7 +37,7 @@ class RallyRestAPI
|
|
37
37
|
@parse_collections_as_hash = options[:parse_collections_as_hash] || false
|
38
38
|
|
39
39
|
if options[:builder]
|
40
|
-
builder = options[:builder]
|
40
|
+
builder = options[:builder]
|
41
41
|
else
|
42
42
|
builder = RestBuilder.new(@base_url, @username, @password)
|
43
43
|
end
|
@@ -65,7 +65,8 @@ class RallyRestAPI
|
|
65
65
|
# returns the created object as a RestObject.
|
66
66
|
def create(type, values) # :yields: new_object
|
67
67
|
# raise "'#{type}' is not a supported type. Supported types are: #{ALLOWED_TYPES.inspect}" unless ALLOWED_TYPES.include?(type.to_s)
|
68
|
-
|
68
|
+
xml = builder.create_rest(type, values, @username, @password)
|
69
|
+
object = RestObject.new(self, xml)
|
69
70
|
yield object if block_given?
|
70
71
|
object
|
71
72
|
end
|
@@ -14,7 +14,7 @@ class RestBuilder # :nodoc:
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# create_rest - convert slm builder style:
|
17
|
-
# slm.
|
17
|
+
# slm.create(:feature, :name => "feature name")
|
18
18
|
#
|
19
19
|
# Into xml builder style:
|
20
20
|
# b.feature {
|
@@ -29,8 +29,7 @@ class RestBuilder # :nodoc:
|
|
29
29
|
|
30
30
|
result = post_xml("#{self.base_url}/webservice/1.0/#{type}/create", xml, username, password)
|
31
31
|
doc = REXML::Document.new result
|
32
|
-
|
33
|
-
RestObject.new(self, created_object.to_s)
|
32
|
+
doc.root.elements["Object"].to_s
|
34
33
|
end
|
35
34
|
|
36
35
|
# update_rest - convert slm builder style:
|
@@ -108,7 +107,7 @@ class RestBuilder # :nodoc:
|
|
108
107
|
|
109
108
|
# Because we are adapting to the xml builder as such:
|
110
109
|
# We say to the RallyRestAPI:
|
111
|
-
# slm.
|
110
|
+
# slm.create(:feature, :name => "feature name")
|
112
111
|
#
|
113
112
|
# We tell the xml builder:
|
114
113
|
# b.feature {
|
@@ -116,9 +115,9 @@ class RestBuilder # :nodoc:
|
|
116
115
|
# }
|
117
116
|
#
|
118
117
|
# in the case where one element is a collection, RallyRest would look like
|
119
|
-
# slm.
|
118
|
+
# slm.create(:feature, :name => "name", :dependancies => [sr1, sr2])
|
120
119
|
#
|
121
|
-
# This
|
120
|
+
# This needs to be converted to
|
122
121
|
#
|
123
122
|
# b.feature {
|
124
123
|
# b.name("name")
|
@@ -129,6 +128,17 @@ class RestBuilder # :nodoc:
|
|
129
128
|
# }
|
130
129
|
# in this case we need to create a block to handle the nested calls (b.Supp...)
|
131
130
|
#
|
131
|
+
#
|
132
|
+
# There are also nested/complex values, for example
|
133
|
+
# slm.create(:defect, :web_link => {:id => "123", :description => "foo"} )
|
134
|
+
#
|
135
|
+
# b.defect {
|
136
|
+
# b.web_link {
|
137
|
+
# b.id "123"
|
138
|
+
# b.description "foo"
|
139
|
+
# }
|
140
|
+
# }
|
141
|
+
#
|
132
142
|
# We need to convert the args hash into a block that can be fed to the builder.
|
133
143
|
# This will send the keys of the map as "methods" (b.name) and the values of
|
134
144
|
# map as the arguments to the method ("feature name").
|
@@ -137,13 +147,15 @@ class RestBuilder # :nodoc:
|
|
137
147
|
# #convert_arg_for_builder will convert the value portion of the hash to the appropiate
|
138
148
|
# string, or block for the xml builder
|
139
149
|
def builder_block(args)
|
150
|
+
sort_block = lambda { |a,b| a.to_s <=> b.to_s } # Sort the keys, for testing
|
140
151
|
lambda do |builder|
|
141
|
-
args.each do |attr, value|
|
142
|
-
|
143
|
-
when *COLLECTION_TYPES
|
152
|
+
args.sort(&sort_block).each do |(attr, value)|
|
153
|
+
if COLLECTION_TYPES.include? attr
|
144
154
|
# The call to builder with only a type and a block needs to be marked as such
|
145
155
|
# note the '&'
|
146
156
|
builder.__send__(camel_case_word(attr), &convert_arg_for_builder([value].flatten))
|
157
|
+
elsif value.instance_of? Hash
|
158
|
+
builder.__send__(camel_case_word(attr), &builder_block(value))
|
147
159
|
else
|
148
160
|
builder.__send__(camel_case_word(attr), convert_arg_for_builder(value))
|
149
161
|
end
|
@@ -157,7 +157,7 @@ class RestObject
|
|
157
157
|
|
158
158
|
# The oid of the underlying resource
|
159
159
|
def oid
|
160
|
-
self.elements[:
|
160
|
+
self.elements[:object_i_d]
|
161
161
|
end
|
162
162
|
|
163
163
|
# return the typedef for this resource.
|
@@ -183,11 +183,19 @@ class RestObject
|
|
183
183
|
@elements
|
184
184
|
end
|
185
185
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
186
|
+
def ==(object)
|
187
|
+
object.equal?(self) ||
|
188
|
+
(object.instance_of?(self.class) &&
|
189
|
+
object.ref == ref)
|
190
|
+
end
|
191
|
+
|
192
|
+
def hash
|
193
|
+
ref.hash
|
194
|
+
end
|
195
|
+
|
196
|
+
def eql?(object)
|
197
|
+
self == (object)
|
198
|
+
end
|
191
199
|
|
192
200
|
public
|
193
201
|
|
@@ -15,7 +15,7 @@ class TypeDefinition < RestObject # :nodoc:
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.get_type_definition(workspace, type)
|
18
|
-
# This is a hack
|
18
|
+
# This is a hack - having to do with parse_collections_as_hash?
|
19
19
|
typedefs = case workspace.type_definitions
|
20
20
|
when Hash : workspace.type_definitions.values.flatten
|
21
21
|
when Array : workspace.type_definitions
|
@@ -50,9 +50,7 @@ class TypeDefinition < RestObject # :nodoc:
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def object_attributes(include_parent = false)
|
53
|
-
collect_attributes(include_parent)
|
54
|
-
attrdef.attribute_type == "OBJECT"
|
55
|
-
end
|
53
|
+
collect_attributes(include_parent) { |element_name, attrdef| attrdef.attribute_type == "OBJECT" }
|
56
54
|
end
|
57
55
|
|
58
56
|
def reference_attributes(include_parent = false)
|
data/test/query_result_spec.rb
CHANGED
@@ -3,11 +3,7 @@ require 'test_helper'
|
|
3
3
|
context "A QueryResult" do
|
4
4
|
|
5
5
|
setup do
|
6
|
-
@api =
|
7
|
-
@api.stub! :username
|
8
|
-
@api.stub! :password
|
9
|
-
@api.stub!(:logger).and_return(nil)
|
10
|
-
@api.stub!(:parse_collections_as_hash?).and_return true
|
6
|
+
@api = RallyRestAPI.new(:parse_collections_as_hash => true)
|
11
7
|
end
|
12
8
|
|
13
9
|
def make_result(total = 20, page_size = 20, start_index = 1)
|
@@ -84,11 +80,7 @@ end
|
|
84
80
|
context "A QueryResult with full objects" do
|
85
81
|
|
86
82
|
setup do
|
87
|
-
@api =
|
88
|
-
@api.stub! :username
|
89
|
-
@api.stub! :password
|
90
|
-
@api.stub!(:logger).and_return(nil)
|
91
|
-
@api.stub!(:parse_collections_as_hash?).and_return true
|
83
|
+
@api = RallyRestAPI.new(:parse_collections_as_hash => true)
|
92
84
|
end
|
93
85
|
|
94
86
|
def make_result(total = 20, page_size = 20, start_index = 1)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "a RestBuilder " do
|
4
|
+
|
5
|
+
def xml
|
6
|
+
b = Builder::XmlMarkup.new
|
7
|
+
b.instruct!
|
8
|
+
yield b
|
9
|
+
end
|
10
|
+
|
11
|
+
setup do
|
12
|
+
@username = "username"
|
13
|
+
@password = "password"
|
14
|
+
@builder = RestBuilder.new(nil, @username, @password)
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "should produce correct xml for flat xml" do
|
18
|
+
expected_xml = xml do |b|
|
19
|
+
b.defect(:ref => "url") {
|
20
|
+
b.Name "foo"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
@builder.should_receive(:post_xml).with(:anything, expected_xml, @username, @password)
|
24
|
+
@builder.update_rest(:defect, "url", {:name => "foo"}, @username, @password)
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should produce correct xml for nested values" do
|
28
|
+
expected_xml = xml do |b|
|
29
|
+
b.defect(:ref => "url") {
|
30
|
+
b.Name "foo"
|
31
|
+
b.WebLink {
|
32
|
+
b.DisplayString "desc"
|
33
|
+
b.LinkID "12345"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
@builder.should_receive(:post_xml).with(:anything, expected_xml, @username, @password)
|
39
|
+
@builder.update_rest(:defect, "url",
|
40
|
+
{
|
41
|
+
:name => "foo",
|
42
|
+
:web_link => {
|
43
|
+
:display_string => "desc",
|
44
|
+
:link_i_d => "12345"
|
45
|
+
}
|
46
|
+
}, @username, @password)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/test/rest_object_spec.rb
CHANGED
@@ -48,6 +48,16 @@ context "a RestObject" do
|
|
48
48
|
o.ref.should == "ref"
|
49
49
|
end
|
50
50
|
|
51
|
+
specify "should return the oid" do
|
52
|
+
o = rest_object_xml do |b|
|
53
|
+
b.Defect(:refObjectName => "name", :ref => "ref") {
|
54
|
+
b.Name("name")
|
55
|
+
b.ObjectID("12345")
|
56
|
+
}
|
57
|
+
end
|
58
|
+
o.oid.should == "12345"
|
59
|
+
end
|
60
|
+
|
51
61
|
specify "should underscore element names" do
|
52
62
|
o = rest_object(%Q(<Object ref="bla">
|
53
63
|
<TextNode>text</TextNode>
|
data/test/tc_rest_api.rb
CHANGED
@@ -41,6 +41,12 @@ class RestApiTestCase < Test::Unit::TestCase
|
|
41
41
|
assert_equal(xml, @xml)
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_basic_create
|
45
|
+
xml = "#{preamble}<Feature><Name>name</Name></Feature>"
|
46
|
+
object = @api.create(:feature, :name => "name")
|
47
|
+
assert_equal(RallyRestAPI, object.rally_rest.class)
|
48
|
+
end
|
49
|
+
|
44
50
|
# test that types and keys are camel cased (at least with one underscore)
|
45
51
|
def test_camel_case
|
46
52
|
xml = "#{preamble}<UseCase><NameName>name</NameName></UseCase>"
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
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.6.
|
7
|
-
date: 2007-02-
|
6
|
+
version: 0.6.12
|
7
|
+
date: 2007-02-23 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
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/rally_rest_api/rally_rest.rb
|
38
38
|
- lib/rally_rest_api.rb
|
39
39
|
- lib/rally_rest_api/rest_builder.rb
|
40
|
+
- lib/rally_rest_api/timeout_catching_rest_builder.rb
|
40
41
|
- lib/rally_rest_api/rest_object.rb
|
41
42
|
- lib/rally_rest_api/typedef.rb
|
42
43
|
- lib/rally_rest_api/version.rb
|
@@ -52,15 +53,17 @@ files:
|
|
52
53
|
- test/rest_object_spec.rb
|
53
54
|
- test/tc_rest_query.rb
|
54
55
|
- test/test_helper.rb
|
56
|
+
- test/rest_builder_spec.rb
|
55
57
|
test_files:
|
56
|
-
- test/
|
58
|
+
- test/attribute_definition_spec.rb
|
57
59
|
- test/query_result_spec.rb
|
60
|
+
- test/rest_builder_spec.rb
|
61
|
+
- test/rest_object_spec.rb
|
62
|
+
- test/spec_typedef.rb
|
63
|
+
- test/tc_query_result.rb
|
64
|
+
- test/tc_rest_api.rb
|
58
65
|
- test/tc_rest_query.rb
|
59
66
|
- test/test_helper.rb
|
60
|
-
- test/tc_query_result.rb
|
61
|
-
- test/spec_typedef.rb
|
62
|
-
- test/attribute_definition_spec.rb
|
63
|
-
- test/rest_object_spec.rb
|
64
67
|
rdoc_options: []
|
65
68
|
|
66
69
|
extra_rdoc_files: []
|
@@ -81,3 +84,12 @@ dependencies:
|
|
81
84
|
- !ruby/object:Gem::Version
|
82
85
|
version: 0.0.0
|
83
86
|
version:
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: hoe
|
89
|
+
version_requirement:
|
90
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.1.7
|
95
|
+
version:
|