evados-tracker 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a49492cf7b2645dfcec699549d24e6d76eb0b9e
4
- data.tar.gz: 83584a19ebfd70071ca058a8d4e796fffef9c2ec
3
+ metadata.gz: 82536553d06ffde22ecc1c9f9b9f2617f0974eb0
4
+ data.tar.gz: b71458ef71e3e4b0d4e6fd0734e9549ab23c493e
5
5
  SHA512:
6
- metadata.gz: c4c12bb8b5a06ce03c4172fd001447b0101385d060e6f99a9285136c2067a7aa7d586359799e72e047bab3c36a7aecb2e72afd916253cfa2f47c2665155f99da
7
- data.tar.gz: 768c55b6d6328dded8adfc02949fff2f9294f59306cf13740ee58ec08cfe9f5238cbf3953f47d19c6de00dca8565f6f96a9cc30a59b5f8350dd9864d21786618
6
+ metadata.gz: 251aad0a2b4e31eb712344e179fdd3daa800394e16290cfec3f6e5191705c06cb2278e70d7eb70ef6b732f209481493661f441c7437a847fba3a3358a72658e2
7
+ data.tar.gz: 114069961fe55af332329f419cbab2ac2af06a1df39181c3ab77f1c82721942ab5aca7717429f570159d498cdb86beacccb13cdeaf622df9abac83fbe644d3f2
data/.gitignore CHANGED
@@ -15,7 +15,7 @@ doc
15
15
  # jeweler generated
16
16
  pkg
17
17
 
18
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
19
  #
20
20
  # * Create a file at ~/.gitignore
21
21
  # * Include files you want ignored
@@ -47,3 +47,14 @@ pkg
47
47
 
48
48
  # For rubinius:
49
49
  #*.rbc
50
+
51
+ *.gem
52
+ Gemfile.lock
53
+ doc/
54
+ lib/bundler/man
55
+ pkg
56
+ rdoc
57
+ spec/reports
58
+ test/tmp
59
+ test/version_tmp
60
+ tmp
data/bin/et CHANGED
@@ -5,36 +5,49 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  require 'thor'
6
6
  require 'evados_tracker'
7
7
 
8
- PATH_TO_KEY = Dir.home + "/.evados-tracker-key"
8
+ PATH_TO_KEY = Dir.home + "/.evados-tracker/.key"
9
9
 
10
10
  class CLI < Thor
11
- option :a
12
11
  def initialize(a, b, c)
13
12
  super(a, b, c)
14
13
  get_key!
15
14
  @tracker = EvadosTracker::Core.new(@key)
16
- @tracker.get_tasks
15
+ check_for_response_error @tracker.get_tasks
17
16
  end
18
17
 
19
18
  desc "ls", "list tasks"
20
19
  def ls
20
+ check_for_response_error @tracker.get_tasks
21
21
  @tracker.numerated_list.each {|t| puts "#{t[0]}. " + "#{t[1]['title']}"}
22
22
  end
23
23
 
24
- desc "start", "start task"
24
+ desc "start", "start task, with key -a start autocontinue"
25
+ method_options :a => :boolean
25
26
  def start(task_num)
26
- begin
27
- @tracker.current_isssue_id = @tracker.numerated_list["#{task_num}"]['id']
28
- pomodoro = @tracker.create_pomodoro
29
- @tracker.pomodoro_id = pomodoro["id"]
30
- one_pomodoro_iteration
31
- puts "You started doing #{@tracker.numerated_list[task_num.to_s]['title']}"
32
- end while options[:a]
27
+ check_rescue do
28
+ begin
29
+ @tracker.current_isssue_id = @tracker.numerated_list["#{task_num}"]['id']
30
+ pomodoro = @tracker.create_pomodoro
31
+ @tracker.pomodoro_id = pomodoro["id"]
32
+ puts "You started doing #{@tracker.numerated_list[task_num.to_s]['title']}"
33
+ one_pomodoro_iteration
34
+ end while options[:a]
35
+ end
33
36
  end
34
37
 
35
-
36
-
37
38
  private ##############
39
+ def check_for_response_error(response)
40
+ if response.is_a? Hash
41
+ case response["error"]
42
+ when "Invalid authentication token.", "You need to sign in or sign up before continuing."
43
+ puts "Invalid authentication token, try again."
44
+ File.delete(PATH_TO_KEY) if File.exists?(PATH_TO_KEY)
45
+ set_key!
46
+ @tracker.key = @key
47
+ check_for_response_error @tracker.get_tasks
48
+ end
49
+ end
50
+ end
38
51
 
39
52
  def one_pomodoro_iteration
40
53
  display_25_minutes_timer
@@ -53,23 +66,36 @@ private ##############
53
66
  :progress_mark => ' ',
54
67
  :remainder_mark => '・',
55
68
  :title => "Break")
56
- 100.times { progressbar.increment; sleep(3); progressbar.refresh }
69
+ 100.times { sleep(3); progressbar.refresh; progressbar.increment; }
57
70
  end
58
71
 
59
72
  def display_25_minutes_timer
60
- progressbar = ProgressBar.create
61
- 100.times { progressbar.increment; sleep(15); progressbar.refresh }
73
+ progressbar = ProgressBar.create( :format => '%a %b %p%% %t',
74
+ :title => "Work")
75
+ 100.times { sleep(15); progressbar.refresh; progressbar.increment; }
62
76
  end
63
77
 
64
78
  def get_key!
65
- if File.exists?(PATH_TO_KEY)
66
- @key = File.foreach(PATH_TO_KEY).first.chomp
67
- else
79
+ @key = File.foreach(PATH_TO_KEY).first.chomp if File.exists?(PATH_TO_KEY)
80
+ end
81
+
82
+ def set_key!
83
+ check_rescue do
68
84
  puts "Your api key: "
69
- @key = gets.chomp
85
+ @key = $stdin.gets.chomp
86
+ Dir.mkdir(Dir.home + "/.evados-tracker/") unless File.exists?(Dir.home + "/.evados-tracker/")
70
87
  File.open(PATH_TO_KEY, "a+") { |f| f.puts @key }
71
88
  end
72
89
  end
90
+
91
+ def check_rescue
92
+ begin
93
+ yield
94
+ rescue SystemExit, Interrupt
95
+ @tracker.delete_pomodoro
96
+ puts "\nBye!"
97
+ end
98
+ end
73
99
  end
74
100
 
75
101
  CLI.start(ARGV)
@@ -1,3 +1,3 @@
1
1
  module EvadosTracker
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -3,7 +3,7 @@ require 'ruby-progressbar'
3
3
 
4
4
  module EvadosTracker
5
5
  class Core
6
- attr_accessor :numerated_list, :current_isssue_id, :pomodoro_id
6
+ attr_accessor :numerated_list, :current_isssue_id, :pomodoro_id, :key
7
7
 
8
8
  def initialize(key)
9
9
  @key = key
@@ -13,43 +13,45 @@ module EvadosTracker
13
13
  end
14
14
 
15
15
  def get_tasks
16
- begin
17
- response = HTTParty.get("http://pm.evados.com/api/v1/issues.json?auth_token=" + @key)
16
+ check_rescue do
17
+ response = HTTParty.get("http://pm.evados.com/api/v1/issues.json?auth_token=" + "#{@key}")
18
18
  numerate_task_list response
19
- rescue StandardError
20
- p "Have no internet connection"
19
+ response
21
20
  end
22
21
  end
23
22
 
24
23
  def create_pomodoro
25
- begin
24
+ check_rescue do
26
25
  @pomodoro_id = HTTParty.post("http://pm.evados.com/api/v1/issues/" + "#{@current_isssue_id}" +
27
- "/pomodoros.json?auth_token=" + @key)
28
- rescue StandardError
29
- p "Have no internet connection"
26
+ "/pomodoros.json?auth_token=" + "#{@key}")
30
27
  end
31
28
  end
32
29
 
33
30
  def commit_pomodoro
34
- begin
35
- HTTParty.put("http://pm.evados.com/api/v1/issues/" + "#{@current_isssue_id}" +
36
- "/pomodoros/" + "#{@pomodoro_id}" + ".json?auth_token=" + @key)
37
- rescue StandardError
38
- p "Have no internet connection"
31
+ check_rescue do
32
+ response = HTTParty.put("http://pm.evados.com/api/v1/issues/" + "#{@current_isssue_id}" +
33
+ "/pomodoros/" + "#{@pomodoro_id}" + ".json?auth_token=" + "#{@key}")
39
34
  end
40
35
  end
41
36
 
42
37
  def delete_pomodoro
43
- begin
44
- HTTParty.delete("http://pm.evados.com/api/v1/issues/" + "#{@current_isssue_id}" +
45
- "/pomodoros/" + "#{@pomodoro_id}" + ".json?auth_token=" + @key)
46
- rescue StandardError
47
- p "Have no internet connection"
38
+ check_rescue do
39
+ response = HTTParty.delete("http://pm.evados.com/api/v1/issues/" + "#{@current_isssue_id}" +
40
+ "/pomodoros/" + "#{@pomodoro_id}" + ".json?auth_token=" + "#{@key}")
48
41
  end
49
42
  end
50
43
 
51
44
  private
52
45
 
46
+ def check_rescue
47
+ begin
48
+ yield
49
+ rescue SocketError
50
+ p "Have no internet connection"
51
+ yield
52
+ end
53
+ end
54
+
53
55
  def numerate_task_list(task_list)
54
56
  @numerated_list = {};
55
57
  task_list.each_with_index{ |t, index| @numerated_list["#{index + 1}"] = t }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evados-tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seva Rybakov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-14 00:00:00.000000000 Z
12
+ date: 2014-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -142,7 +142,6 @@ email:
142
142
  - codingfu@gmail.com
143
143
  - vmatiyko@gmail.com
144
144
  executables:
145
- - .et.swp
146
145
  - et
147
146
  extensions: []
148
147
  extra_rdoc_files: []
@@ -154,10 +153,8 @@ files:
154
153
  - LICENSE.txt
155
154
  - README.rdoc
156
155
  - Rakefile
157
- - bin/.et.swp
158
156
  - bin/et
159
157
  - evados_tracker.gemspec
160
- - lib/.evados_tracker.rb.swp
161
158
  - lib/evados_tracker.rb
162
159
  - lib/evados_tracker/core.rb
163
160
  - lib/evados_tracker/version.rb
data/bin/.et.swp DELETED
Binary file
Binary file