Class: RallyRestAPI

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  parse_options(options)
  user
end

Instance Attribute Details

#base_urlObject (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

#builderObject (readonly)

Returns the value of attribute builder.



15
16
17
# File 'lib/rally_rest_api/rally_rest.rb', line 15

def builder
  @builder
end

#loggerObject (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_hashObject

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

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/rally_rest_api/rally_rest.rb', line 15

def password
  @password
end

#usernameObject (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.

Yields:

  • (object)


79
80
81
82
83
84
85
# File 'lib/rally_rest_api/rally_rest.rb', line 79

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



109
110
111
# File 'lib/rally_rest_api/rally_rest.rb', line 109

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.



91
92
93
94
95
96
# File 'lib/rally_rest_api/rally_rest.rb', line 91

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)



99
100
101
# File 'lib/rally_rest_api/rally_rest.rb', line 99

def find_all(type, args = {})
  find(type, args) { gt :object_i_d, "0" }
end

#marshal_dumpObject



57
58
59
# File 'lib/rally_rest_api/rally_rest.rb', line 57

def marshal_dump
  [@username, @password, @base_url, @version, @builder, @parse_collections_as_hash]
end

#marshal_load(stuff) ⇒ Object



61
62
63
# File 'lib/rally_rest_api/rally_rest.rb', line 61

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

Returns:

  • (Boolean)


120
121
122
# File 'lib/rally_rest_api/rally_rest.rb', line 120

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
55
# File 'lib/rally_rest_api/rally_rest.rb', line 38

def parse_options(options)
  @username = options[:username]
  @password = options[:password]
  @base_url = options[:base_url] || "https://rally1.rallydev.com/slm"
  @version = options[:version] || "1.36"
  @logger = options[:logger]
  @http_headers = options[:http_headers] || CustomHttpHeader.new
  @parse_collections_as_hash = options[:parse_collections_as_hash] || false

  if options[:builder]
    builder = options[:builder]
  else
    builder = RestBuilder.new(@base_url, @username, @password, @version, @http_headers)
  end
  builder.logger = @logger if @logger
  builder.use_cookies = true if options[:use_cookies]
  @builder = builder
end

#query(query) ⇒ Object

:nodoc:



113
114
115
116
117
# File 'lib/rally_rest_api/rally_rest.rb', line 113

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



104
105
106
# File 'lib/rally_rest_api/rally_rest.rb', line 104

def update(rest_object, attributes)
  rest_object.update(attributes)
end

#userObject Also known as: start

return an instance of User, for the currently logged in user.



67
68
69
# File 'lib/rally_rest_api/rally_rest.rb', line 67

def user
  RestObject.new(self, builder.read_rest("#{@base_url}/webservice/#{@version}/user", @username, @password))
end