如何解析从Ruby工具包返回的Rally缺陷描述

时间:2013-07-29 14:41:40

标签: ruby rally

Rally Ruby REST API使用HTML标记返回Description。如果使用浏览器REST客户端,情况也是如此。是否可以解析描述以删除标记以使描述可读?

1 个答案:

答案 0 :(得分:0)

安装sanitize gem后

gem install sanitize

此示例代码将删除标记:

require 'rally_api'
require 'sanitize'

#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "nmusaelian@rallydev.com"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "P1"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()

@rally = RallyAPI::RallyRestJson.new(config)

query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "Name,Description"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/11111.js" } #
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/project/222222.js" } #
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(FormattedID = \"DE20\")"

results = @rally.find(query)

results.each do |d|
    puts "Name: #{d["Name"]}, FormattedID: #{d["FormattedID"]}, Description: #{Sanitize.clean(d["Description"])}"
    d.read
end