-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_ticket.rb
114 lines (107 loc) · 3.69 KB
/
list_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
require_relative 'get_tickets'
require_relative 'delete_ticket'
require_relative 'update_ticket'
class ListTickets
@@list_ticket_introduction = "---------------------------------------------
Select next step:\n P Print detail information of specific ticket \n D Delete specific ticket \n U Update status of specific ticket \n Q quit
---------------------------------------------"
def initialize(sub_domain, access_token)
@access_token = access_token
@sub_domain = sub_domain
end
def list_ticket
get_tickets = GetTickets.new(@sub_domain, @access_token)
tickets = get_tickets.get_ticket_list
if tickets
print_ticket(tickets)
while 1
puts @@list_ticket_introduction
fun = gets
fun = fun.chomp
if fun == 'P'
print_detail_ticket(tickets)
elsif fun == 'D'
delete_one_ticket(tickets)
break
elsif fun == 'U'
update_one_ticket(tickets)
break
elsif fun == 'Q'
break
else
puts "Invalid input"
end
end
else
puts "Get tickets failed, please check authorization information"
end
end
def print_ticket(tickets)
puts "*** ticket_num: #{tickets.count} ***"
puts "---------------------------------------"
for i in 1..tickets.count
puts "ticket_index: #{i}"
puts "subject: #{tickets[i - 1]['subject']}"
puts "description: #{tickets[i - 1]['description']}"
puts "status: #{tickets[i-1]['status']}"
puts "---------------------------------------"
end
end
def print_detail_ticket(tickets)
puts "Which ticket for more detail, input the ticket index 1 - #{tickets.count}(input Q to quit)"
input = gets
while input.chomp != "Q"
num = input.to_i
if num <= 0 || num > tickets.count
puts "Error, invalid input. Input must be Integer and in the index range: 1 - #{tickets.count}"
puts "Which ticket for more detail, input Q to exit"
input = gets
next
end
pp tickets.at(num - 1)
puts "Which ticket for more detail, input the ticket index 1 - #{tickets.count}(input Q to quit)"
input = gets
end
end
def delete_one_ticket(tickets)
delete_ticket = DeleteTicket.new(@sub_domain,@access_token)
puts "Which ticket to delete, input the ticket index 1 - #{tickets.count}(input Q to quit)"
input = gets
while input.chomp != "Q"
num = input.to_i
if num <= 0 || num > tickets.count
puts "Error, invalid input. Input must be Integer and in the index range: 1 - #{tickets.count} \nPlease re-enter the index (input Q to quit)"
input = gets
else
res = delete_ticket.delete_ticket(tickets.at(num-1)['id'].to_i)
if res.is_a?(Net::HTTPSuccess)
puts "Delete success"
else
puts "Delete fail"
end
break
end
end
end
def update_one_ticket(tickets)
update_ticket = UpdateTicket.new(@sub_domain,@access_token)
puts "Which ticket to update, input the ticket index 1 - #{tickets.count}(input Q to quit)"
input = gets
while input.chomp != "Q"
num = input.to_i
if num <= 0 || num > tickets.count
puts "Error, invalid input. Input must be Integer and in the index range: 1 - #{tickets.count} \nPlease re-enter the index (input Q to quit)"
else
puts "Current status is #{tickets.at(num-1)['status']}"
res = update_ticket.update_ticket(tickets.at(num-1)['id'].to_i)
if res.is_a?(Net::HTTPSuccess)
puts "Update success"
break
else
puts "Update fail, please check input format. re-enter index or quit"
end
end
input = gets
end
end
end