ruby Zendesk报道
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Zendesk报道相关的知识,希望对你有一定的参考价值。
module Zendesk
require 'zendesk_api'
require 'csv'
require 'octokit'
ZD = Zendesk.init
def self.create_report
tickets = Zendesk.get_problem_tickets
tickets = Zendesk.get_incident_counts(tickets)
tickets = Zendesk.get_group_name(tickets)
# tickets = Zendesk.get_github_issues(tickets)
Zendesk.export_to_csv(tickets)
end
def self.export_to_csv(tickets)
CSV.open("problem_tickets.csv", "wb") do |csv|
csv << ["ID","URL","Subject","Created At","Group ID","Group Name","GH URL","Repo","Incident Count"]
tickets.each do |ticket|
p ticket["id"]
csv << [ticket["id"],
ticket["url"],
ticket["subject"],
ticket["created_at"],
ticket["group_id"],
ticket["group_name"],
ticket["gh_url"],
ticket["repo"],
ticket["incident_count"]
# ticket["tags"]
]
end
end
end
# def self.get_github_issues(data)
# tickets = []
# client = Octokit::Client.new(:access_token => GITHUB_TOKEN)
#
# data.each do |t|
# issue = client.issue("octokit/octokit.rb", "25")
# t["issue_subject"] =
# tickets << t
# end
#
# tickets
# end
def self.get_group_name(data)
tickets = []
data.each do |t|
t["group_name"] = ZD.groups.find!(:id => t["group_id"])[:name]
tickets << t
end
tickets
end
def self.get_incident_counts(data)
tickets = []
data.each do |t|
t["incident_count"] = ZD.tickets(:path => "tickets/#{t["id"]}/incidents").count
tickets << t
end
tickets
end
def self.get_problem_tickets
tickets = []
ZD.tickets(:path => "problems").page(1).per_page(100).to_a.each do |t|
ticket = {
"id" => t.id,
"url" => t.url,
"subject" => t.subject,
"created_at" => t.created_at,
"group_id" => t.group_id,
# "tags" => t.tags.to_s,
"gh_url" => t.custom_fields.select{|field| field["id"] == 22826611 }.first[:value],
"repo" => t.custom_fields.select{|field| field["id"] == 22826611 }.first[:value] ? t.custom_fields.select{|field| field["id"] == 22826611 }.first[:value].match(/Shopify\/([\w-]*)/)[1] : nil
}
tickets << ticket
end
tickets
end
def self.init
client = ZendeskAPI::Client.new do |config|
config.url = "https://shopify.zendesk.com/api/v2"
config.username = ZD_USERNAME
config.password = ZD_PASSWORD
config.retry = true
# require 'logger'
# config.logger = Logger.new(STDOUT)
end
end
end
source 'https://rubygems.org'
gem "zendesk_api"
gem "octokit"
以上是关于ruby Zendesk报道的主要内容,如果未能解决你的问题,请参考以下文章
远程服务器返回错误:(401)在Zendesk中未经授权
python Zendesk API Python脚本
html Zendesk:格式化标签
html Zendesk:推荐文章的提醒通知
html Zendesk:推荐文章的提醒通知
Testcafe 无法与本地 zat 服务器通信(zendesk-app-tools)