evados-tracker 0.2.2 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8768cfaf56bb541d670cd67ff0c58330a6128a59
4
- data.tar.gz: 2cbc29a89f420153a95137b05232b0aa2e4f1153
3
+ metadata.gz: eaa2edc5e8d9cb1439057aa6a0a73d761702d954
4
+ data.tar.gz: 65eda314798f566fb71253e958aa556625e73d6c
5
5
  SHA512:
6
- metadata.gz: cfda633fb6f0591ee9bcd4653efdc51d215ffbde467cb04b0a4f75918963b4f8de20991344d2bd8600486fd50dde99bfe838adf29e561eeacd8c636ced20e550
7
- data.tar.gz: cc1e13ca59a4781f4453a7e31cb9025c5e6cb7db878e5ba5f10dfed93335819dd5449588f499dd64844f68d76bff7615fe9c119e8b19aaf693792b3bcf4d2ada
6
+ metadata.gz: a3d7c57035910b3e46b670e9e94876b08c25cf76c743f17028a765678aa5c0021ad14b9139b69d2407753858624556773f4c361c4e014ad5295ce7e648b49ac2
7
+ data.tar.gz: 513829650e3816e35bf70369f7cbe3cd0fd623c5e67fe1dd9e788b426371f7ec9511c50987630bc1d45a2e2310723324638baf6bf94a9a220b608e9424b8e0d4
data/bin/et CHANGED
@@ -8,12 +8,14 @@ require 'json'
8
8
 
9
9
  PATH_TO_KEY = Dir.home + "/.evados-tracker/.key"
10
10
  PATH_TO_PREV_ISSUE = Dir.home + "/.evados-tracker/prev_issue.json"
11
+ PATH_TO_UNSAVED_POMODORO = Dir.home + "/.evados-tracker/unsaved_pomodoro.json"
11
12
 
12
13
  class CLI < Thor
13
14
  def initialize(a, b, c)
14
15
  super(a, b, c)
15
16
  get_key!
16
17
  @tracker = EvadosTracker::Core.new(@key)
18
+ check_unsaved_pomodoro
17
19
  check_for_response_error @tracker.get_tasks
18
20
  end
19
21
 
@@ -26,7 +28,7 @@ class CLI < Thor
26
28
  desc "start", "start task, with key -a start autocontinue"
27
29
  method_options :a => :boolean
28
30
  def start(task_num)
29
- check_rescue do
31
+ check_interrupt_rescue do
30
32
  @tracker.current_issue_id = @tracker.numerated_list["#{task_num}"]['id']
31
33
  @prev_issue = { @tracker.current_issue_id => @tracker.numerated_list[task_num.to_s]['title'] }
32
34
  hash_to_json
@@ -39,7 +41,7 @@ class CLI < Thor
39
41
  desc "resume", "resume to previous task, with key -a start autocontinue"
40
42
  method_options :a => :boolean
41
43
  def resume
42
- check_rescue do
44
+ check_interrupt_rescue do
43
45
  @prev_issue = json_to_hash
44
46
  @tracker.current_issue_id = @prev_issue.keys.first
45
47
  begin
@@ -70,15 +72,11 @@ private ##############
70
72
  end
71
73
 
72
74
  def one_pomodoro_iteration
73
- display_25_minutes_timer
74
- begin
75
- saved = @tracker.commit_pomodoro['is_finished']
76
- unless saved
77
- puts "Pomodoro save failed. Will attempt in 1 minute."
78
- sleep 300
79
- end
80
- end while !saved
81
- display_5_minute_timer
75
+ check_socket_rescue do
76
+ display_25_minutes_timer
77
+ @tracker.commit_pomodoro
78
+ display_5_minute_timer
79
+ end
82
80
  end
83
81
 
84
82
  def display_5_minute_timer
@@ -104,7 +102,7 @@ private ##############
104
102
  end
105
103
 
106
104
  def set_key!
107
- check_rescue do
105
+ check_interrupt_rescue do
108
106
  puts "Your api key: "
109
107
  @key = $stdin.gets.chomp
110
108
  Dir.mkdir(Dir.home + "/.evados-tracker/") unless File.exists?(Dir.home + "/.evados-tracker/")
@@ -112,7 +110,7 @@ private ##############
112
110
  end
113
111
  end
114
112
 
115
- def check_rescue
113
+ def check_interrupt_rescue
116
114
  begin
117
115
  yield
118
116
  rescue SystemExit, Interrupt
@@ -121,6 +119,20 @@ private ##############
121
119
  end
122
120
  end
123
121
 
122
+ def check_socket_rescue
123
+ begin
124
+ yield
125
+ rescue SocketError
126
+ p "Have no internet connection"
127
+ if @tracker.current_issue_id && @tracker.pomodoro_id
128
+ pomodoro = { @tracker.current_issue_id => @tracker.pomodoro_id }
129
+ File.delete(PATH_TO_UNSAVED_POMODORO) if File.exists?(PATH_TO_UNSAVED_POMODORO)
130
+ File.open(PATH_TO_UNSAVED_POMODORO, "a+") { |f| f.write pomodoro.to_json }
131
+ abort
132
+ end
133
+ end
134
+ end
135
+
124
136
  def hash_to_json
125
137
  File.delete(PATH_TO_PREV_ISSUE) if File.exists?(PATH_TO_PREV_ISSUE)
126
138
  File.open(PATH_TO_PREV_ISSUE, "a+") { |f| f.write @prev_issue.to_json }
@@ -134,6 +146,17 @@ private ##############
134
146
  abort
135
147
  end
136
148
  end
149
+
150
+ def check_unsaved_pomodoro
151
+ check_socket_rescue do
152
+ if File.exists? PATH_TO_UNSAVED_POMODORO
153
+ pomodoro = JSON.parse(IO.read PATH_TO_UNSAVED_POMODORO)
154
+ @tracker.current_issue_id = pomodoro.keys.first.to_i
155
+ @tracker.pomodoro_id = pomodoro[pomodoro.keys.first].to_i
156
+ File.delete(PATH_TO_UNSAVED_POMODORO) if @tracker.commit_pomodoro["is_finished"]
157
+ end
158
+ end
159
+ end
137
160
  end
138
161
 
139
162
  CLI.start(ARGV)
@@ -28,10 +28,8 @@ module EvadosTracker
28
28
  end
29
29
 
30
30
  def commit_pomodoro
31
- check_rescue do
32
- response = HTTParty.put("http://pm.evados.com/api/v1/issues/" + "#{@current_issue_id}" +
33
- "/pomodoros/" + "#{@pomodoro_id}" + ".json?auth_token=" + "#{@key}")
34
- end
31
+ response = HTTParty.put("http://pm.evados.com/api/v1/issues/" + "#{@current_issue_id}" +
32
+ "/pomodoros/" + "#{@pomodoro_id}" + ".json?auth_token=" + "#{@key}")
35
33
  end
36
34
 
37
35
  def delete_pomodoro
@@ -48,7 +46,7 @@ module EvadosTracker
48
46
  yield
49
47
  rescue SocketError
50
48
  p "Have no internet connection"
51
- yield
49
+ abort
52
50
  end
53
51
  end
54
52
 
@@ -1,3 +1,3 @@
1
1
  module EvadosTracker
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.21"
3
3
  end
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.2.2
4
+ version: 0.2.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seva Rybakov