0

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

4

1 回答 1

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
于 2013-07-29T14:47:05.777 回答