Class: Willpower::Tickets

Inherits:
Thor
  • Object
show all
Defined in:
lib/willpower/commands/tickets.rb

Instance Method Summary collapse

Instance Method Details

#archiveObject



72
73
74
75
76
77
78
79
# File 'lib/willpower/commands/tickets.rb', line 72

def archive
  error_checking_tickets
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/"
  info = JSON.parse(response)
  info.each do |ticket|
    archive_ticket(ticket) if ticket["project_id"] == CONFIG["current_project_id"] && ticket["status"] == "archived"
  end
end

#create(ticket) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/willpower/commands/tickets.rb', line 5

def create(ticket)
  error_checking_tickets
  ticket_name = ticket
  cli = HighLine.new
  ticket_description = cli.ask("description for ticket: ", String)
  RestClient.post"#{CONFIG['current_remote']}/api/v1/tickets/",
                 project_id: CONFIG["current_project_id"], name: ticket_name,
                 user: CONFIG["current_user"], desc: ticket_description, status: ticket_status
  say "Successfully added new ticket!"
end

#listObject



17
18
19
20
21
22
# File 'lib/willpower/commands/tickets.rb', line 17

def list
  error_checking_tickets
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/"
  info = JSON.parse(response)
  print_tickets_list(info)
end

#my_listObject



25
26
27
28
29
30
31
# File 'lib/willpower/commands/tickets.rb', line 25

def my_list
  error_checking_tickets
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/"
  owner = []
  JSON.parse(response).each { |ticket| owner << ticket if ticket["owner"] == CONFIG["current_user"] }
  print_tickets_list(owner)
end

#show(ticket) ⇒ Object



34
35
36
37
38
39
# File 'lib/willpower/commands/tickets.rb', line 34

def show(ticket)
  error_checking_tickets
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}"
  row = JSON.parse(response)
  output_ticket(row["data"]["attributes"])
end

#status(ticket) ⇒ Object



64
65
66
67
68
69
# File 'lib/willpower/commands/tickets.rb', line 64

def status(ticket)
  error_checking_tickets
  RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}",
                 name: ticket, status: ticket_status, type: 3, project_id: CONFIG["current_project_id"]
  say "You take ticket #{ticket}"
end

#take(ticket) ⇒ Object



56
57
58
59
60
61
# File 'lib/willpower/commands/tickets.rb', line 56

def take(ticket)
  error_checking_tickets
  RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}",
                 name: ticket, user: CONFIG["current_user"], type: 2
  say "You take ticket #{ticket}"
end

#update(ticket) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/willpower/commands/tickets.rb', line 42

def update(ticket)
  error_checking_tickets
  choice = HighLine.new
  answer = choice.ask("Choose what you need to edit : name or description (N or D): ", String)
  if answer == "N"
    update_name(ticket)
  elsif answer == "D"
    update_description(ticket)
  else
    say "Try again"
  end
end