xcli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/xcli ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path '../../lib/xcli', __FILE__
4
+
5
+ Xcli::Cli.start
data/lib/xcli/cli.rb ADDED
@@ -0,0 +1,167 @@
1
+ module Xcli
2
+ class Cli < Thor
3
+ include CommandLineReporter
4
+ include HTTParty
5
+
6
+ def self.configuration
7
+ @configuration ||= Xcli::Configuration.new
8
+ end
9
+
10
+ def configuration
11
+ self.class.configuration
12
+ end
13
+
14
+ base_uri configuration.url
15
+
16
+ desc 'clients', 'list clients'
17
+ method_option :initials, :type => :string
18
+ def clients
19
+ report(:message => 'Loading Clients...', :complete => '', :indent_size => 8) do
20
+ require_login
21
+ clients = self.class.get("/api/v1/clients", :body => {:auth_token => @token, :initials => options[:initials]})
22
+ table(:border => true) do
23
+ row do
24
+ column('Initials', :width => 20)
25
+ column('NAME', :width => 20)
26
+ end
27
+ clients.each do |client|
28
+ row do
29
+ column(client["initials"])
30
+ column(client["name"])
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ desc 'projects', 'list projects'
38
+ method_option :client_initials, :type => :string
39
+ def projects
40
+ report(:message => 'Loading projects...', :complete => '', :indent_size => 8) do
41
+ require_login
42
+ projects = self.class.get("/api/v1/projects", :body => {:auth_token => @token, :client_initials => options[:client_initials]})
43
+ table(:border => true) do
44
+ row do
45
+ column('NAME', :width => 20)
46
+ end
47
+ projects.each do |project|
48
+ row do
49
+ column(project["name"])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ desc 'ticket', 'show current ticket based on git repo and branch'
57
+ def ticket
58
+ report(:message => 'Loading current ticket...', :complete => '', :indent_size => 8) do
59
+ table(:border => true) do
60
+ row do
61
+ column('NAME', :width => 20)
62
+ column('ESTIMATED HOURS', :width => 20)
63
+ column('HOURS WORKED', :width => 20)
64
+ column('PERCENTAGE COMPLETE', :width => 20)
65
+ end
66
+ row do
67
+ column(current_ticket["name"])
68
+ column(current_ticket["estimated_hours"])
69
+ column(current_ticket["hours"])
70
+ column("#{current_ticket["percentage_complete"].to_s}%")
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ desc 'new_ticket', 'create new ticket based on git repo and branch'
77
+ method_options :estimated_hours => :numeric, :name => :string, :message => :string
78
+ def new_ticket
79
+ report(:message => 'Creating new ticket...', :complete => '', :indent_size => 8) do
80
+ require_login
81
+ 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})
82
+ table(:border => true) do
83
+ row do
84
+ column('NAME', :width => 20)
85
+ column('ESTIMATED HOURS', :width => 20)
86
+ column('HOURS WORKED', :width => 20)
87
+ column('PERCENTAGE COMPLETE', :width => 20)
88
+ end
89
+ row do
90
+ column(current_ticket["name"])
91
+ column(current_ticket["estimated_hours"])
92
+ column(current_ticket["hours"])
93
+ column("#{current_ticket["percentage_complete"].to_s}%")
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ desc 'enter_time', 'enter time to current ticket based on git repo and branch'
100
+ method_options :hours => :numeric, :message => :string
101
+ def enter_time
102
+ report(:message => 'Creating work unit...', :complete => '', :indent_size => 8) do
103
+ require_login
104
+ 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})
105
+ if status["success"]
106
+ puts "Time Entered"
107
+ else
108
+ puts "It didn't work"
109
+ end
110
+ end
111
+ end
112
+
113
+ desc 'status', 'show information about the current user'
114
+ def status
115
+ report(:message => 'Loading status...', :complete => '', :indent_size => 8) do
116
+ require_login
117
+ table(:border => true) do
118
+ row do
119
+ column('USERNAME', :width => 20)
120
+ column('CURRENT HOURS', :width => 20)
121
+ column('OFFSET', :width => 20)
122
+ end
123
+ row do
124
+ column(configuration.email)
125
+ column(@current_hours)
126
+ column(@offset)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ private
133
+
134
+ def current_branch_name
135
+ r = Grit::Repo.new('.')
136
+ r.head.name
137
+ end
138
+
139
+ def git_repo_url
140
+ r = Grit::Repo.new('.')
141
+ r.config["remote.origin.url"]
142
+ end
143
+
144
+ def require_login
145
+ login unless @token
146
+ end
147
+
148
+ def login
149
+ login_response = self.class.post("/api/v1/tokens", :body => {:email => configuration.email, :password => configuration.password})
150
+ @token = login_response["token"]
151
+ @current_hours = login_response["current_hours"]
152
+ @offset = login_response["offset"]
153
+ end
154
+
155
+ def current_ticket
156
+ return @current_ticket if @current_ticket
157
+ require_login
158
+ @current_ticket = self.class.get("/api/v1/tickets", :body => {:auth_token => @token, :repo_url => git_repo_url, :branch => current_branch_name}).first
159
+ end
160
+
161
+ def current_project
162
+ return @current_project if @current_project
163
+ require_login
164
+ @current_project = self.class.get("/api/v1/projects", :body => {:auth_token => @token, :git_repo_url => git_repo_url}).first
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,27 @@
1
+ module Xcli
2
+ class Configuration
3
+ attr_accessor :url, :email, :password
4
+
5
+ def initialize
6
+ load_config
7
+ end
8
+
9
+ private
10
+
11
+ def load_config
12
+ config_file = File.expand_path(File.join(ENV["HOME"],'/.xronorc'))
13
+ if File.exist? config_file
14
+ @config = YAML.load_file config_file
15
+ else
16
+ @config = {}
17
+ end
18
+
19
+ self.url = @config.fetch('url', 'http://127.0.0.1:3000')
20
+ self.email = @config.fetch('email', 'dev@xrono.org')
21
+ self.password = @config.fetch('password', '123456')
22
+
23
+ @config
24
+ end
25
+ end
26
+ end
27
+
data/lib/xcli.rb ADDED
@@ -0,0 +1,11 @@
1
+ lib_dir = File.expand_path '../../lib', __FILE__
2
+ $:.unshift lib_dir unless $:.include? lib_dir
3
+
4
+ require 'command_line_reporter'
5
+ require 'thor'
6
+ require 'httparty'
7
+ require 'grit'
8
+
9
+ require 'xcli/configuration'
10
+ require 'xcli/cli'
11
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Gamble
9
+ - Ben Holley
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-30 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ requirement: &70302048454240 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.14.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70302048454240
26
+ - !ruby/object:Gem::Dependency
27
+ name: command_line_reporter
28
+ requirement: &70302048453760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70302048453760
37
+ - !ruby/object:Gem::Dependency
38
+ name: grit
39
+ requirement: &70302048453300 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.4.1
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70302048453300
48
+ - !ruby/object:Gem::Dependency
49
+ name: httparty
50
+ requirement: &70302048452840 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 0.8.1
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *70302048452840
59
+ description: Xrono Command Line Client
60
+ email:
61
+ - adamgamble@gmail.com
62
+ - ben@isotope11.com
63
+ executables:
64
+ - xcli
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - bin/xcli
69
+ - lib/xcli.rb
70
+ - lib/xcli/configuration.rb
71
+ - lib/xcli/cli.rb
72
+ homepage: http://rubygems.org/gems/example
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.10
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Xrono Command Line Client
96
+ test_files: []