/
zendesk_ticket.rb
156 lines (130 loc) · 4.76 KB
/
zendesk_ticket.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
class ZendeskTicket
attr_reader :name, :email, :organisation, :job, :phone, :comment, :subject, :need_by_date, :not_before_date
@@in_comments = {"amend-content" => [:other_organisation, :url1, :url2, :url3],
"create-user" => [:other_organisation, :user_name, :user_email, :additional],
"remove-user" => [:other_organisation, :user_name, :user_email, :additional],
"campaign" => [:other_organisation, :campaign_name, :erg_number, :company, :description, :url, :additional],
"general" => [:other_organisation, :url, :user_agent, :additional],
"publish-tool" => [:other_organisation, :username, :url, :user_agent, :additional]
}
@@in_subject = {"amend-content" => "Content change request",
"create-user" => "Create new user",
"remove-user" => "Remove user",
"campaign" => "Campaign",
"general" => "Govt Agency General Issue",
"publish-tool" => "Publishing Tool"
}
@@in_tag = {"amend-content" => "content_amend",
"create-user" => "new_user",
"remove-user" => "remove_user",
"campaign" => "campaign",
"general" => "govt_agency_general",
"publish-tool" => "publishing_tool_tech"
}
def initialize(params, from_route)
@params = params
@from_route = from_route
#author information
@name = params[:name]
@email = params[:email]
@organisation = params[:organisation]
@job = params[:job]
if has_value(params[:phone])
@phone = remove_space_from_phone_number(params[:phone])
end
#ticket information
@comment = format_comment(from_route, params)
@subject = @@in_subject[from_route]
if has_value(params[:need_by_day])
@need_by_date = params[:need_by_day] + "/" + params[:need_by_month] + "/" + params[:need_by_year]
end
if has_value(params[:start_day])
@need_by_date = params[:start_day] + "/" + params[:start_month] + "/" + params[:start_year]
end
if has_value(params[:not_before_day])
@not_before_date = params[:not_before_day] + "/" + params[:not_before_month] + "/" + params[:not_before_year]
end
end
def tags
inside_government_tag = @params[:inside_government] == "yes" ? ["inside_government"] : []
[@@in_tag[@from_route]] + inside_government_tag
end
private
def has_value(param)
if param
!param.strip.empty?
else
false
end
end
def format_comment(from_route, params)
case from_route
when "amend-content" then
format_comment_for_amend_content(params)
when "general" then
format_comment_for_tech_issues(from_route, params)
when "publish-tool" then
format_comment_for_tech_issues(from_route, params)
else
comment = @@in_comments[from_route].map do |comment_param|
if params[comment_param] && !params[comment_param].empty?
"[" + comment_param.to_s.capitalize.gsub(/_/, " ") + "]\n" + params[comment_param]
end
end
if !comment.join().empty?
comment.join("\n\n")
else
comment.join
end
end
end
def format_comment_for_tech_issues(from_route, params)
all_comments = @@in_comments[from_route].map do |comment_param|
comment = ""
if params[comment_param] && !params[comment_param].empty?
comment = "[" + comment_param.to_s.capitalize.gsub(/_/, " ") + "]\n"
if :url == comment_param
comment += build_full_url_path(params[:url])
else
comment += params[comment_param]
end
end
comment
end
if !all_comments.join.empty?
all_comments.join("\n\n")
else
all_comments.join
end
end
def format_comment_for_amend_content(params)
comments_sections = {"[URl(s) of content to be changed]" => [build_full_url_path(params[:url1]), build_full_url_path(params[:url2]), build_full_url_path(params[:url3])],
"[Details of what should be added, amended or removed]" => [params[:add_content]],
"[Additional Comments]" => [params[:additional]]
}
comments = comments_sections.map do |key, value|
allvalues = value.join("\n")
if !allvalues.chomp.strip.empty?
key+"\n"+allvalues.chomp.strip
end
end
if !comments.join.empty?
comments.join("\n\n")
else
comments.join
end
end
def remove_space_from_phone_number(number)
number.gsub(/\s+/, "")
end
def build_full_url_path(partial_path)
if partial_path && !partial_path.empty?
"http://gov.uk/"+ partial_path
else
partial_path
end
end
def doesFieldHaveValue(field_value)
field_value && !field_value.strip.empty?
end
end