rally_rest_api 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
data/lib/rally_rest_api/query.rb
CHANGED
@@ -8,6 +8,10 @@ class String # :nodoc: all
|
|
8
8
|
alias :to_q :to_s
|
9
9
|
end
|
10
10
|
|
11
|
+
class Fixnum
|
12
|
+
alias :to_q :to_s
|
13
|
+
end
|
14
|
+
|
11
15
|
class Symbol # :nodoc: all
|
12
16
|
def to_q
|
13
17
|
self.to_s.to_camel
|
@@ -66,22 +70,22 @@ end
|
|
66
70
|
class RestQuery
|
67
71
|
attr_reader :type
|
68
72
|
|
69
|
-
def initialize(type,
|
73
|
+
def initialize(type, args = {}, &block)
|
70
74
|
@type = type
|
71
75
|
@query_string = "query=" << URI.escape(QueryBuilder.new("and", &block).to_q) if block_given?
|
72
|
-
@query_params = process_args(args
|
76
|
+
@query_params = process_args(args)
|
73
77
|
end
|
74
78
|
|
75
|
-
def process_args(args) # :nodoc
|
79
|
+
def process_args(args) # :nodoc:
|
76
80
|
return if args.nil?
|
77
81
|
query_string = ""
|
78
|
-
args.each do |
|
79
|
-
case
|
82
|
+
args.each do |k, v|
|
83
|
+
case k
|
80
84
|
when :order
|
81
85
|
# this is a hack, we need a better way to express descending
|
82
|
-
|
86
|
+
v = [v].flatten.map { |e| e.to_s.to_camel }.join(", ").gsub(", Desc", " desc")
|
83
87
|
end
|
84
|
-
query_string << "&#{
|
88
|
+
query_string << "&#{k}=#{URI.escape(v.to_q)}"
|
85
89
|
end
|
86
90
|
query_string
|
87
91
|
end
|
@@ -36,6 +36,7 @@ class QueryResult < RestObject
|
|
36
36
|
@start_index = elements[:start_index].to_i
|
37
37
|
end
|
38
38
|
|
39
|
+
require 'active_support/breakpoint'
|
39
40
|
# fetch the next page of results. Uses the original query to generate the query string.
|
40
41
|
def next_page
|
41
42
|
@rally_rest.query(@query.next_page(:start => self.start_index + self.page_size,
|
@@ -71,13 +71,18 @@ class RallyRestAPI
|
|
71
71
|
# Example :
|
72
72
|
# rally.find(:artifact, :page_size => 20, :start_index => 20) { equal :name, "name" }
|
73
73
|
# See RestQuery for more info.
|
74
|
-
def find(type,
|
74
|
+
def find(type, args = {}, &query)
|
75
75
|
# pass the args to RestQuery, make it generate the string and handle generating the query for the
|
76
76
|
# next page etc.
|
77
77
|
query = RestQuery.new(type, args, &query)
|
78
78
|
query(query)
|
79
79
|
end
|
80
80
|
|
81
|
+
# find all object of a given type. Base types work also (.e.g :artifact)
|
82
|
+
def find_all(type, *args)
|
83
|
+
find(type, args) { gt :object_i_d, "0" }
|
84
|
+
end
|
85
|
+
|
81
86
|
# update - update an object
|
82
87
|
def update(rest_object, attributes)
|
83
88
|
rest_object.update(attributes)
|
@@ -113,7 +113,8 @@ class RestObject
|
|
113
113
|
return elements
|
114
114
|
end
|
115
115
|
|
116
|
-
|
116
|
+
public
|
117
|
+
|
117
118
|
def underscore(camel_cased_word)
|
118
119
|
camel_cased_word.to_s.gsub(/::/, '/').
|
119
120
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
@@ -122,7 +123,6 @@ class RestObject
|
|
122
123
|
downcase
|
123
124
|
end
|
124
125
|
|
125
|
-
public
|
126
126
|
|
127
127
|
# return the XML of the resource
|
128
128
|
def body
|
@@ -150,13 +150,20 @@ class RestObject
|
|
150
150
|
self.elements[:object_id]
|
151
151
|
end
|
152
152
|
|
153
|
+
# return the typedef for this resource.
|
154
|
+
def typedef
|
155
|
+
# this is a little ugly as we start to introduce some type specific info into this class.
|
156
|
+
# All WorkspaceDomainObjects have a #workspace, that excludes user, workspace and subscription.
|
157
|
+
return nil if self.type =~ /User|Workspace|Subscription/
|
158
|
+
TypeDefinition.cached_type_definition(self)
|
159
|
+
end
|
160
|
+
|
153
161
|
# re-read the resource
|
154
162
|
def refresh
|
155
163
|
self.elements(true)
|
156
164
|
self
|
157
165
|
end
|
158
166
|
|
159
|
-
protected
|
160
167
|
def elements(read = @elements.nil?) #:nodoc:
|
161
168
|
if read
|
162
169
|
@document_content = read_rest(self.ref, @username, @password)
|
@@ -1,23 +1,59 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
require 'rally_rest_api/string_utils'
|
3
|
+
require 'rally_rest_api/rest_object'
|
4
|
+
|
5
|
+
class TypeDefinition < RestObject # :nodoc:
|
6
|
+
|
7
|
+
def self.cached_type_definition(workspace_domain_object)
|
8
|
+
# todo, actually cache the value
|
9
|
+
typedef = workspace_domain_object.workspace.type_definitions.values.find do |typedef|
|
10
|
+
puts "#{workspace_domain_object.type} == #{typedef.element_name}"
|
11
|
+
workspace_domain_object.type == typedef.element_name
|
12
|
+
end
|
13
|
+
TypeDefinition.new(typedef.rally_rest, typedef.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection_attributes(include_parent = false)
|
17
|
+
collect_attributes_of_type("COLLECTION", include_parent)
|
18
|
+
end
|
19
|
+
|
20
|
+
def object_attributes(include_parent = false)
|
21
|
+
collect_attributes_of_type("OBJECT", include_parent)
|
6
22
|
end
|
7
23
|
|
8
|
-
def
|
9
|
-
|
10
|
-
attr_def.element_name if attr_def.attribute_type == "COLLECTION"
|
11
|
-
end.compact
|
24
|
+
def reference_attributes(include_parent = false)
|
25
|
+
collection_attributes(include_parent).merge object_attributes(include_parent)
|
12
26
|
end
|
13
27
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
28
|
+
def collect_attributes_of_type(type, include_parent)
|
29
|
+
self.attributes(include_parent).inject({}) do |h, (element_name, attrdef)|
|
30
|
+
h[element_name] = attrdef if attrdef.attribute_type == type
|
31
|
+
h
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def symbol_keyed_attributes(attribute_array)
|
36
|
+
attribute_array.inject({}) do |hash, attrdef|
|
37
|
+
hash[underscore(attrdef.element_name).intern] = attrdef
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def attributes(include_parent = false)
|
43
|
+
return symbol_keyed_attributes(self.elements[:attributes].values) unless include_parent
|
44
|
+
|
45
|
+
typedef = self
|
46
|
+
all_attributes = {}
|
47
|
+
until typedef.parent.nil?
|
48
|
+
all_attributes.merge! typedef.attributes(false)
|
49
|
+
typedef = typedef.parent
|
50
|
+
end
|
51
|
+
all_attributes
|
17
52
|
end
|
18
53
|
|
19
54
|
def parent
|
20
|
-
|
55
|
+
return nil if self.elements[:parent].nil?
|
56
|
+
TypeDefinition.new(self.rally_rest, self.elements[:parent].body)
|
21
57
|
end
|
22
58
|
|
23
59
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rally_rest_api
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2006-11-
|
6
|
+
version: 0.5.8
|
7
|
+
date: 2006-11-29 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
|