Class: RallyAPI
- Inherits:
-
Object
show all
- Defined in:
- lib/rally/rally_api.rb
Defined Under Namespace
Classes: Configure, CredentialsError
Class Method Summary
collapse
Class Method Details
.all(resource, options = {}) ⇒ Object
20
21
22
23
|
# File 'lib/rally/rally_api.rb', line 20
def all resource, options ={}
check_configuration
do_get(resource.rally_uri, parsed_options(options))
end
|
.check_configuration ⇒ Object
96
97
98
99
100
|
# File 'lib/rally/rally_api.rb', line 96
def check_configuration
if self.configuration.user.nil? || self.configuration.password.nil?
raise CredentialsError.new
end
end
|
.configuration ⇒ Object
16
17
18
|
# File 'lib/rally/rally_api.rb', line 16
def configuration
@configuration
end
|
11
12
13
14
|
# File 'lib/rally/rally_api.rb', line 11
def configure(&block)
@configuration = @configuration || Configure.new
yield @configuration
end
|
.do_get(endpoint, options = nil) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/rally/rally_api.rb', line 81
def do_get endpoint, options = nil
if endpoint.match(/https:\/\/.*/)
rally_resource(endpoint).get(:params => options)
else
rally_resource[endpoint].get(:params => options)
end
end
|
.get(resource) ⇒ Object
25
26
27
28
29
|
# File 'lib/rally/rally_api.rb', line 25
def get resource
check_configuration
json = JSON.parse(do_get(resource.rally_uri))
json[resource.class.node_name]
end
|
.parsed_fetch(fetch) ⇒ Object
51
52
53
|
# File 'lib/rally/rally_api.rb', line 51
def parsed_fetch(fetch)
{"fetch" => fetch}
end
|
.parsed_options(options) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/rally/rally_api.rb', line 31
def parsed_options options
option_string = {}
if options.has_key? :conditions
option_string = option_string.merge(parsed_query(options[:conditions]))
end
if options.has_key? :start
option_string = option_string.merge(parsed_start(options[:start]))
end
if options.has_key? :pagesize
option_string = option_string.merge(parsed_pagesize(options[:pagesize]))
end
if options.has_key? :fetch
option_string = option_string.merge(parsed_fetch(options[:fetch]))
end
option_string
end
|
.parsed_pagesize(pagesize) ⇒ Object
59
60
61
|
# File 'lib/rally/rally_api.rb', line 59
def parsed_pagesize(pagesize)
{"pagesize" => pagesize.to_i}
end
|
.parsed_query(conditions) ⇒ Object
63
64
65
66
|
# File 'lib/rally/rally_api.rb', line 63
def parsed_query conditions
tokens = conditions.collect{|k,v| query_token(k,v)}
{"query" => tokens.join(" and ")}
end
|
.parsed_start(start) ⇒ Object
55
56
57
|
# File 'lib/rally/rally_api.rb', line 55
def parsed_start(start)
{"start" => start.to_i}
end
|
.query_token(k, v) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rally/rally_api.rb', line 68
def query_token k,v
operators ={
"gt" => ">",
"gte" => ">=",
"lt" => "<",
"lte" => "<=",
"ne" => "!="}
field = k.respond_to?("key") ? k.key : k
field = field.downcase == field ? field.capitalize : field
operator = k.respond_to?("operator") ? operators[k.operator] : "="
"(#{field.to_s} #{operator} \"#{v}\")"
end
|
.rally_resource(uri = nil) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/rally/rally_api.rb', line 89
def rally_resource uri = nil
uri ||= "https://rally1.rallydev.com/slm/webservice/1.19"
RestClient::Resource.new(uri,
:user => self.configuration.user,
:password => self.configuration.password)
end
|