2013-04-22 68 views
0

我成功地建立了到我的Rally項目的連接,但在打開缺陷時無法以編程方式設置"Submitted By"字段。我誤解了參數,或者它不能通過REST API進行設置。任何幫助查詢可修改的參數,鏈接到屬性名稱,或代碼來設置"Submitted By"參數將不勝感激。枚舉可設置的參數

我的目標是建立一個網頁,其中的人們會提交缺陷或故事以及他們的電子郵件,並使用它在「提交者」字段填充他們的用戶名。我目前的設置可以打開故事和缺陷,但只能匿名,因爲倒數第二行不起作用。

我正在使用Ruby API,下面是當用戶單擊主頁面上的按鈕時將被調用的ruby代碼,該頁面將其重定向到localhost:4567/rally_defect,其中Sinatra正在偵聽。

require 'rubygems' 
require 'rally_rest_api' 
require 'sinatra' 

custom_headers = CustomHttpHeader.new 
custom_headers.name = 'Mail 2 Rally' 
custom_headers.version = '0.1' 
custom_headers.vendor = 'Rally Software' 

rally_server = 'https://rally1.rallydev.com/slm' 
rally_username = <insert rally username> 
rally_pwd = <insert rally password> 

rally = RallyRestAPI.new(:base_url => rally_server, 
         :username => rally_username, 
         :password => rally_pwd, 
         :http_headers => custom_headers) 

get '/rally_defect' do 
    rally.create(:defect, :name => "Test Defect", 
         :description => "This is a test", 
         :SubmittedBy => "test")      
end 
+0

您使用的是什麼SDK ... Javascript,.NET ...?你能從代碼中發佈一段代碼來說明你正在做什麼嗎? – 2013-04-22 10:49:14

+0

@MarkW - 謝謝馬克!我已更新了所要求的信息。 – user2306914 2013-04-22 19:44:12

回答

0

如果你要開始建造這種整合,我強烈建議您使用的rally_api代替rally_rest_api

rally_rest_api正在被棄用的過程中的一些問題圍繞性能和穩定性。 rally_rest_api將不會有任何進一步的發展。

您可以在rally_api找到文檔瀏覽:

https://developer.help.rallydev.com/ruby-toolkit-rally-rest-api-json

rally_api確實需要的Ruby 1.9.2或更高版本。

rally_api的語法與rally_rest_api非常相似。你在上面嘗試的rally_api版本看起來像下面的代碼示例。請注意,任何「可設置」參數都可以通過將其名稱包含在對象散列中並將其設置爲一個值來設置。

尋找拉力Web服務API的對象模型,包括神器屬性,允許值,以及他們是否是可寫的是Web服務API文檔的最佳地點:

https://rally1.rallydev.com/slm/doc/webservice

當屬性一個Rally Artifact本身就像一個用戶一樣是一個Rally對象,例如,首先在Rally中查找Object(下面的例子是這樣做的),或者將該值設置爲對Rally中對象的REST URL引用。舉例來說,如果你知道[email protected]已經在拉力賽的objectID 12345678910,那麼你可以做:

user_ref = "/user/12345678910" 
new_defect["SubmittedBy"] = user_ref 

下面的代碼顯示給定的電子郵件格式的用戶ID進行查找到拉力賽,以獲取用戶對象的方式, ,因爲我假設你可能需要容納多個不同的用戶。

require 'rubygems' 
require 'rally_api' 
require 'sinatra' 

#Setting custom headers 
headers = RallyAPI::CustomHttpHeader.new() 
headers.name = 'Mail 2 Rally' 
headers.vendor = "My Company" 
headers.version = "0.1" 

# Rally credentials 
rally_username = <insert rally username> 
rally_pwd = <insert rally password> 
rally_server = 'https://rally1.rallydev.com/slm' 

# Rally REST API config 
config = {:base_url => rally_server} 
config[:username] = rally_username 
config[:password] = rally_pwd 
config[:workspace] = "Workspace Name" 
config[:project] = "Project Name" 
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new() 

# New up rally connection config 
@rally = RallyAPI::RallyRestJson.new(config) 

# Lookup UserID for SubmittedBY 
submitted_by_user_id = "[email protected]"  

user_query = RallyAPI::RallyQuery.new() 
user_query.type = :user 
user_query.fetch = "ObjectID,UserName,DisplayName" 
user_query.order = "UserName Asc" 
user_query.query_string = "(UserName = \"#{submitted_by_user_id}\")" 

# Query for user 
user_query_results = @rally.find(user_query) 
submitted_by_user = user_query_results.first 

# Create the Defect 
new_defect = {} 
new_defect["Name"] = "Test Defect" 
new_defect["Description"] = "This is a test" 
new_defect["SubmittedBy"] = submitted_by_user 

new_defect_create_result = @rally.create(:defect, new_defect) 

puts "New Defect created FormattedID: #{new_defect_create_result.FormattedID}"