Class: Xcli::Cli

Inherits:
Thor
  • Object
show all
Includes:
CommandLineReporter, HTTParty
Defined in:
lib/xcli/cli.rb

Instance Method Summary collapse

Instance Method Details

#clientsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xcli/cli.rb', line 20

def clients
  report(:message => 'Loading Clients...', :complete => '', :indent_size => 8) do
    
    clients = self.class.get("/api/v1/clients", :body => {:auth_token => @token, :initials => options[:initials]})
    table(:border => true) do
      row do
        column('Initials', :width => 20)
        column('NAME', :width => 20)
      end
      clients.each do |client|
        row do
          column(client["initials"])
          column(client["name"])
        end
      end
    end
  end
end

#enter_timeObject



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/xcli/cli.rb', line 103

def enter_time
  report(:message => 'Creating work unit...', :complete => '', :indent_size => 8) do
    
    status = self.class.post("/api/v1/work_units", :body => {:work_unit => {:ticket_id => current_ticket["id"], :hours => options[:hours], :hours_type => "Normal", :description => options[:message], :scheduled_at => Time.now.to_s}, :auth_token => @token})
    if status["success"]
      puts "Time Entered"
    else
      puts "It didn't work"
    end
  end
end

#new_ticketObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/xcli/cli.rb', line 80

def new_ticket
  report(:message => 'Creating new ticket...', :complete => '', :indent_size => 8) do
    
    status = self.class.post("/api/v1/tickets", :body => {:ticket => {:project_id => current_project["id"], :estimated_hours => options[:estimated_hours], :description => options[:message], :git_branch => current_branch_name, :name => options[:name]}, :auth_token => @token})
    table(:border => true) do
      row do
        column('NAME', :width => 20)
        column('ESTIMATED HOURS', :width => 20)
        column('HOURS WORKED', :width => 20)
        column('PERCENTAGE COMPLETE', :width => 20)
      end
      row do
        column(current_ticket["name"])
        column(current_ticket["estimated_hours"])
        column(current_ticket["hours"])
        column("#{current_ticket["percentage_complete"].to_s}%")
      end
    end
  end
end

#projectsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/xcli/cli.rb', line 41

def projects
  report(:message => 'Loading projects...', :complete => '', :indent_size => 8) do
    
    projects = self.class.get("/api/v1/projects", :body => {:auth_token => @token, :client_initials => options[:client_initials]})
    table(:border => true) do
      row do
        column('NAME', :width => 20)
      end
      projects.each do |project|
        row do
          column(project["name"])
        end
      end
    end
  end
end

#statusObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/xcli/cli.rb', line 116

def status
  report(:message => 'Loading status...', :complete => '', :indent_size => 8) do
    
    table(:border => true) do
      row do
        column('USERNAME', :width => 20)
        column('CURRENT HOURS', :width => 20)
        column('OFFSET', :width => 20)
      end
      row do
        column(configuration.email)
        column(@current_hours)
        column(@offset)
      end
    end
  end
end

#ticketObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/xcli/cli.rb', line 59

def ticket
  report(:message => 'Loading current ticket...', :complete => '', :indent_size => 8) do
    table(:border => true) do
      row do
        column('NAME', :width => 20)
        column('ESTIMATED HOURS', :width => 20)
        column('HOURS WORKED', :width => 20)
        column('PERCENTAGE COMPLETE', :width => 20)
      end
      row do
        column(current_ticket["name"])
        column(current_ticket["estimated_hours"])
        column(current_ticket["hours"])
        column("#{current_ticket["percentage_complete"].to_s}%")
      end
    end
  end
end