mytime 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,13 +18,31 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ To link to your Freshbooks account (you will need your Freshbooks username and API token):
22
+
23
+ $ mytime setup
24
+
25
+ To initialize mytime in a project directory:
26
+
27
+ $ mytime init
28
+
29
+ To see project details:
30
+
31
+ $ mytime project
32
+
21
33
  To list log:
22
34
 
23
- $ mytime
35
+ $ mytime status
36
+
37
+ To submit custom time entry:
24
38
 
25
- To submit project time:
39
+ $ mytime commit [hrs] [custom_message]
40
+ $ mytime commit 1.5 "Add an additional note if desired"
26
41
 
27
- $ mytime commit "Add an additional note if desired"
42
+ To push your git logs from today for a given project:
43
+
44
+ $ mytime push [hrs]
45
+ $ mytime push 4.5
28
46
 
29
47
  ## Contributing
30
48
 
@@ -1,5 +1,6 @@
1
1
  require "mytime/version"
2
2
  require "mytime/setup"
3
+ require "mytime/config"
3
4
  require "mytime/client"
4
5
  require "mytime/timesheet"
5
6
  require 'ruby-freshbooks'
@@ -36,7 +37,7 @@ module Mytime
36
37
  push(args.first)
37
38
  when :project, :detail, :info
38
39
  puts "Project Details:"
39
- puts config_details(Dir.pwd).to_yaml
40
+ puts Config.details(Dir.pwd).to_yaml
40
41
  when :debug
41
42
  puts init?
42
43
  else
@@ -44,54 +45,14 @@ module Mytime
44
45
  end
45
46
  end
46
47
 
47
- # Save a .mytime config file. Overwrites any existing data
48
- #
49
- # Options:
50
- # contents: Required hash of account data to save
51
- #
52
- def save(contents)
53
- File.open(USER_FILE, 'a') do |file|
54
- file.write contents.to_yaml
55
- end
56
- end
57
-
58
- # Add yaml data to the existing .mytime config file
59
- #
60
- # Options:
61
- # contents: Required hash of data to add to config file
62
- #
63
- def add(contents)
64
- data = YAML.load_file USER_FILE
65
- merged_data = data.merge(contents)
66
- puts merged_data
67
- File.open(USER_FILE, 'w') do |file|
68
- file.write merged_data.to_yaml
69
- end
70
- end
71
-
72
- # Return details of .mytime config file
73
- #
74
- def config_details(path = "")
75
- return unless YAML.load_file(USER_FILE)
76
- data = YAML.load_file USER_FILE
77
- if path == ""
78
- data
79
- else
80
- data.each do |d|
81
- project = data.select{|key, hash| hash["project_path"] == path }
82
- return project.first[1] if project.any?
83
- end
84
- end
85
- end
86
-
87
48
  # Check if mytime is setup
88
49
  def setup?
89
- config_details.has_key?("account")
50
+ Config.details.has_key?("account")
90
51
  end
91
52
 
92
53
  # Check if mytime is initialized for this project
93
54
  def init?
94
- config_details(Dir.pwd).has_key?("project_id")
55
+ Config.details(Dir.pwd).has_key?("project_id")
95
56
  end
96
57
 
97
58
  def finish_setup
@@ -9,7 +9,7 @@ module Mytime
9
9
  # project_id: Optional project_id to restrict data returned
10
10
  #
11
11
  def project(project_id = nil)
12
- account = Mytime.config_details
12
+ account = Config.details
13
13
  c = FreshBooks::Client.new(account["account"], account["token"])
14
14
  if project_id.nil?
15
15
  c.project.list["projects"]
@@ -18,6 +18,16 @@ module Mytime
18
18
  end
19
19
  end
20
20
 
21
+ # Get task data from client API
22
+ #
23
+ # project_id: Required project_id to restrict data returned
24
+ #
25
+ def tasks(project_id)
26
+ account = Config.details
27
+ c = FreshBooks::Client.new(account["account"], account["token"])
28
+ c.task.list :project_id => project_id
29
+ end
30
+
21
31
  # Submit new time entry to client API
22
32
  #
23
33
  # Option:
@@ -25,15 +35,16 @@ module Mytime
25
35
  # message: Optional - message to send with time entry
26
36
  #
27
37
  def submit(hours, message = "")
28
- account = Mytime.config_details
38
+
39
+ account = Config.details
29
40
  c = FreshBooks::Client.new(account["account"], account["token"])
30
- project = Mytime.config_details(Dir.pwd)
41
+ project = Config.details(Dir.pwd)
31
42
  entry = c.time_entry.create(
32
43
  :time_entry => {
33
44
  project_id: project["project_id"],
34
45
  task_id: project["task_id"],
35
46
  hours: hours.to_f,
36
- notes: message.to_s,
47
+ notes: message.gsub(/\n/,"\n\n").to_s,
37
48
  date: Date.today.to_s
38
49
  }
39
50
  )
@@ -0,0 +1,59 @@
1
+ module Mytime
2
+
3
+ module Config
4
+ extend self
5
+
6
+ # Return details of .mytime config file
7
+ #
8
+ def details(path = "")
9
+ begin
10
+ data = YAML.load_file USER_FILE
11
+ if path == ""
12
+ data
13
+ else
14
+ data.each do |d|
15
+ project = data.select{|key, hash| hash["project_path"] == path }
16
+ return project.first[1] if project.any?
17
+ end
18
+ end
19
+ rescue Exception => e
20
+ {}
21
+ end
22
+ end
23
+
24
+ # Save a .mytime config file. Overwrites any existing data
25
+ #
26
+ # Options:
27
+ # contents: Required hash of account data to save
28
+ #
29
+ def save(contents)
30
+ begin
31
+ File.open(USER_FILE, 'a') do |file|
32
+ file.write contents.to_yaml
33
+ end
34
+ rescue
35
+ puts "Failed saving information! Please try again."
36
+ end
37
+ end
38
+
39
+ # Add yaml data to the existing .mytime config file
40
+ #
41
+ # Options:
42
+ # contents: Required hash of data to add to config file
43
+ #
44
+ def add(contents)
45
+ begin
46
+ data = YAML.load_file USER_FILE
47
+ merged_data = data.merge(contents)
48
+ puts merged_data
49
+ File.open(USER_FILE, 'w') do |file|
50
+ file.write merged_data.to_yaml
51
+ end
52
+ rescue
53
+ puts "Failed adding data. Please try again."
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -12,7 +12,7 @@ module Mytime
12
12
  account = Hash.new
13
13
  account["account"] = "#{account_name}.freshbooks.com"
14
14
  account["token"] = token
15
- self.save(account)
15
+ Config.save(account)
16
16
  end
17
17
 
18
18
  # Setup .mytime file to include project specific data
@@ -25,14 +25,18 @@ module Mytime
25
25
  end
26
26
  project_id = STDIN.gets.chomp
27
27
 
28
- project = Client.project(project_id)["project"]
29
- task_id = project["tasks"]["task"][0]["task_id"]
28
+ puts "Choose Task"
29
+ tasks = Client.tasks(project_id)['tasks']['task']
30
+ tasks.each do |task|
31
+ puts "#{task['task_id']}: #{task['name']}"
32
+ end
33
+ task_id = STDIN.gets.chomp
30
34
 
31
35
  project_details = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc)}
32
36
  project_details[project_id]["project_path"] = Dir.pwd
33
37
  project_details[project_id]["project_id"] = project_id
34
38
  project_details[project_id]["task_id"] = task_id
35
- self.add(project_details)
39
+ Config.add(project_details)
36
40
  end
37
41
 
38
42
  # Set configuration variables to values passed in the command line options
@@ -28,6 +28,10 @@ module Mytime
28
28
  #
29
29
  def push(hours)
30
30
  return finish_setup unless setup? && init?
31
+ if hours.nil?
32
+ puts "How many hours did you spend on these commits?"
33
+ hours = STDIN.gets.chomp
34
+ end
31
35
  puts Client.submit(hours, status)
32
36
  end
33
37
 
@@ -1,3 +1,3 @@
1
1
  module Mytime
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'awesome_print'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ require 'mytime'
8
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mytime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-freshbooks
@@ -43,10 +43,12 @@ files:
43
43
  - bin/mytime
44
44
  - lib/mytime.rb
45
45
  - lib/mytime/client.rb
46
+ - lib/mytime/config.rb
46
47
  - lib/mytime/setup.rb
47
48
  - lib/mytime/timesheet.rb
48
49
  - lib/mytime/version.rb
49
50
  - mytime.gemspec
51
+ - test/helper.rb
50
52
  homepage: ''
51
53
  licenses: []
52
54
  post_install_message:
@@ -72,4 +74,5 @@ signing_key:
72
74
  specification_version: 3
73
75
  summary: MyTime is a simple command line utility for submitting git commit history
74
76
  to a timesheet. Powered by the Freshbooks API.
75
- test_files: []
77
+ test_files:
78
+ - test/helper.rb