Class: RallyRestAPI
- Inherits:
-
Object
- Object
- RallyRestAPI
- Defined in:
- lib/rally_rest_api/rally_rest.rb
Overview
RallyRestAPI - A Ruby-ized interface to Rally’s REST webservice API
Constant Summary collapse
- ALLOWED_TYPES =
%w[subscription workspace project iteration release defect defect_suite test_case feature supplemental_requirement use_case story actor card program task hierarchical_requirement test_case_result test_case_step]
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#parse_collections_as_hash ⇒ Object
Returns the value of attribute parse_collections_as_hash.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#create(type, values) {|object| ... } ⇒ Object
Create an object.
-
#delete(rest_object) ⇒ Object
delete an object.
-
#find(type, args = {}, &query_block) ⇒ Object
Query Rally for a collection of objects Example : rally.find(:artifact, :pagesize => 20, :start => 20) { equal :name, “name” } See RestQuery for more info.
-
#find_all(type, args = {}) ⇒ Object
find all object of a given type.
-
#initialize(options = {}) ⇒ RallyRestAPI
constructor
new - Create an instance of RallyRestAPI.
- #marshal_dump ⇒ Object
- #marshal_load(stuff) ⇒ Object
-
#parse_collections_as_hash? ⇒ Boolean
Should rest_objects collection parse into hashes.
- #parse_options(options) ⇒ Object
-
#query(query) ⇒ Object
:nodoc:.
-
#update(rest_object, attributes) ⇒ Object
update - update an object.
-
#user ⇒ Object
(also: #start)
return an instance of User, for the currently logged in user.
Constructor Details
#initialize(options = {}) ⇒ RallyRestAPI
new - Create an instance of RallyRestAPI. Each instance corresponds to one named user.
options (as a Hash):
-
username - The Rally username
-
password - The password for the named user
-
base_url - The base url of the system. Defaults to rally1.rallydev.com/slm
-
version - The RallyWebservices Version. Defaults to ‘current’, which will always be the most
recent version of the api. Pass the value as a String, "1.0", "1.01" for example.
-
logger - a Logger to log to.
-
http_headers - an instace of CustomHttpHeader that will send application information with the request
33 34 35 36 |
# File 'lib/rally_rest_api/rally_rest.rb', line 33 def initialize( = {}) () user end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/rally_rest_api/rally_rest.rb', line 15 def base_url @base_url end |
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
15 16 17 |
# File 'lib/rally_rest_api/rally_rest.rb', line 15 def builder @builder end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/rally_rest_api/rally_rest.rb', line 15 def logger @logger end |
#parse_collections_as_hash ⇒ Object
Returns the value of attribute parse_collections_as_hash.
16 17 18 |
# File 'lib/rally_rest_api/rally_rest.rb', line 16 def parse_collections_as_hash @parse_collections_as_hash end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
15 16 17 |
# File 'lib/rally_rest_api/rally_rest.rb', line 15 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
15 16 17 |
# File 'lib/rally_rest_api/rally_rest.rb', line 15 def username @username end |
Instance Method Details
#create(type, values) {|object| ... } ⇒ Object
Create an object.
type - The type to create, as a symbol (e.g. :test_case)
values - The attributes of the new object.
The created instance will be passed to the block
returns the created object as a RestObject.
78 79 80 81 82 83 84 |
# File 'lib/rally_rest_api/rally_rest.rb', line 78 def create(type, values) # :yields: new_object # raise "'#{type}' is not a supported type. Supported types are: #{ALLOWED_TYPES.inspect}" unless ALLOWED_TYPES.include?(type.to_s) xml = builder.create_rest(type, values, @username, @password) object = RestObject.new(self, xml) yield object if block_given? object end |
#delete(rest_object) ⇒ Object
delete an object
108 109 110 |
# File 'lib/rally_rest_api/rally_rest.rb', line 108 def delete(rest_object) rest_object.delete end |
#find(type, args = {}, &query_block) ⇒ Object
Query Rally for a collection of objects Example :
rally.find(:artifact, :pagesize => 20, :start => 20) { equal :name, "name" }
See RestQuery for more info.
90 91 92 93 94 95 |
# File 'lib/rally_rest_api/rally_rest.rb', line 90 def find(type, args = {}, &query_block) # pass the args to RestQuery, make it generate the string and handle generating the query for the # next page etc. query = RestQuery.new(type, args, &query_block) query(query) end |
#find_all(type, args = {}) ⇒ Object
find all object of a given type. Base types work also (e.g. :artifact)
98 99 100 |
# File 'lib/rally_rest_api/rally_rest.rb', line 98 def find_all(type, args = {}) find(type, args) { gt :object_i_d, "0" } end |
#marshal_dump ⇒ Object
56 57 58 |
# File 'lib/rally_rest_api/rally_rest.rb', line 56 def marshal_dump [@username, @password, @base_url, @version, @builder, @parse_collections_as_hash] end |
#marshal_load(stuff) ⇒ Object
60 61 62 |
# File 'lib/rally_rest_api/rally_rest.rb', line 60 def marshal_load(stuff) @username, @password, @base_url, @version, @builder, @parse_collections_as_hash = *stuff end |
#parse_collections_as_hash? ⇒ Boolean
Should rest_objects collection parse into hashes
119 120 121 |
# File 'lib/rally_rest_api/rally_rest.rb', line 119 def parse_collections_as_hash? @parse_collections_as_hash end |
#parse_options(options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rally_rest_api/rally_rest.rb', line 38 def () @username = [:username] @password = [:password] @base_url = [:base_url] || "https://rally1.rallydev.com/slm" @version = [:version] || "current" @logger = [:logger] @http_headers = [:http_headers] || CustomHttpHeader.new @parse_collections_as_hash = [:parse_collections_as_hash] || false if [:builder] builder = [:builder] else builder = RestBuilder.new(@base_url, @username, @password, @version, @http_headers) end builder.logger = @logger if @logger @builder = builder end |
#query(query) ⇒ Object
:nodoc:
112 113 114 115 116 |
# File 'lib/rally_rest_api/rally_rest.rb', line 112 def query(query) # :nodoc: query_url = "#{@base_url}/webservice/#{@version}/#{query.type.to_s.to_camel}?" << query.to_q xml = builder.read_rest(query_url, @username, @password) QueryResult.new(query, self, xml) end |
#update(rest_object, attributes) ⇒ Object
update - update an object
103 104 105 |
# File 'lib/rally_rest_api/rally_rest.rb', line 103 def update(rest_object, attributes) rest_object.update(attributes) end |
#user ⇒ Object Also known as: start
return an instance of User, for the currently logged in user.
66 67 68 |
# File 'lib/rally_rest_api/rally_rest.rb', line 66 def user RestObject.new(self, builder.read_rest("#{@base_url}/webservice/#{@version}/user", @username, @password)) end |