TokiCLI 0.2.1 → 0.3.0
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 +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -17
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +99 -163
- data/Rakefile +5 -0
- data/TokiCLI.gemspec +5 -4
- data/bin/toki +2 -2
- data/lib/API/helpers.rb +27 -170
- data/lib/API/toki_api.rb +227 -0
- data/lib/API/toki_db.rb +67 -0
- data/lib/TokiCLI.rb +270 -5
- data/lib/TokiCLI/adnimport.rb +202 -0
- data/lib/TokiCLI/fileops.rb +187 -0
- data/lib/TokiCLI/status.rb +49 -37
- data/lib/TokiCLI/version.rb +1 -1
- data/lib/TokiCLI/view.rb +133 -86
- data/lib/TokiServer/.bowerrc +3 -0
- data/lib/TokiServer/.gitignore +2 -0
- data/lib/TokiServer/Gemfile +1 -0
- data/lib/TokiServer/bower.json +0 -0
- data/lib/TokiServer/bower_components/fastclick/.bower.json +4 -4
- data/lib/TokiServer/bower_components/fastclick/bower.json +1 -1
- data/lib/TokiServer/bower_components/fastclick/lib/fastclick.js +33 -2
- data/lib/TokiServer/bower_components/foundation/.bower.json +5 -4
- data/lib/TokiServer/bower_components/foundation/bower.json +2 -1
- data/lib/TokiServer/bower_components/foundation/css/foundation.css +2173 -922
- data/lib/TokiServer/bower_components/foundation/css/foundation.css.map +7 -0
- data/lib/TokiServer/bower_components/foundation/css/normalize.css +53 -16
- data/lib/TokiServer/bower_components/foundation/css/normalize.css.map +7 -0
- data/lib/TokiServer/bower_components/foundation/js/foundation.js +782 -542
- data/lib/TokiServer/bower_components/foundation/js/foundation.min.js +4 -3
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.abide.js +45 -31
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.accordion.js +12 -6
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.alert.js +5 -5
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.clearing.js +34 -10
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.dropdown.js +83 -29
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.equalizer.js +3 -3
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.interchange.js +25 -12
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.joyride.js +112 -40
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.js +19 -5
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.magellan.js +22 -11
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.offcanvas.js +52 -8
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.orbit.js +133 -271
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.reveal.js +27 -20
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.slider.js +73 -33
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tab.js +88 -31
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tooltip.js +7 -5
- data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.topbar.js +44 -24
- data/lib/TokiServer/bower_components/foundation/js/vendor/fastclick.js +2 -2
- data/lib/TokiServer/bower_components/foundation/js/vendor/modernizr.js +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation.scss +38 -38
- data/lib/TokiServer/bower_components/foundation/scss/foundation/_functions.scss +3 -3
- data/lib/TokiServer/bower_components/foundation/scss/foundation/_settings.scss +417 -271
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_accordion.scss +110 -6
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_alert-boxes.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_block-grid.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_breadcrumbs.scss +8 -3
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_button-groups.scss +99 -9
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_buttons.scss +66 -28
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_clearing.scss +5 -5
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown-buttons.scss +4 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown.scss +48 -35
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_forms.scss +104 -32
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_global.scss +48 -30
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_grid.scss +19 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_icon-bar.scss +293 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_joyride.scss +11 -9
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_keystrokes.scss +4 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_labels.scss +4 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_magellan.scss +1 -1
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_offcanvas.scss +193 -35
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_orbit.scss +92 -147
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pagination.scss +22 -10
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_panels.scss +10 -7
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pricing-tables.scss +11 -11
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_progress-bars.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_range-slider.scss +29 -9
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal.scss +60 -56
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_side-nav.scss +3 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_split-buttons.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_sub-nav.scss +2 -2
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switches.scss +226 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tables.scss +13 -7
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tabs.scss +22 -8
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_thumbs.scss +2 -4
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_toolbar.scss +70 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tooltips.scss +9 -7
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_top-bar.scss +77 -44
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_type.scss +21 -9
- data/lib/TokiServer/bower_components/modernizr/.bower.json +4 -4
- data/lib/TokiServer/bower_components/modernizr/feature-detects/workers-blobworkers.js +2 -2
- data/lib/TokiServer/bower_components/modernizr/grunt.js +1 -1
- data/lib/TokiServer/bower_components/modernizr/modernizr.js +2 -2
- data/lib/TokiServer/config.rb +0 -0
- data/lib/TokiServer/humans.txt +0 -0
- data/lib/TokiServer/{itunesicon.rb → itunesicons.rb} +25 -23
- data/lib/TokiServer/js/app.js +0 -0
- data/lib/TokiServer/public/stylesheets/app.css +2636 -1610
- data/lib/TokiServer/robots.txt +0 -0
- data/lib/TokiServer/scss/_settings.scss +0 -0
- data/lib/TokiServer/scss/app.scss +7 -1
- data/lib/TokiServer/tokiserver.rb +239 -244
- data/lib/TokiServer/views/activity.erb +42 -0
- data/lib/TokiServer/views/apps_total.erb +8 -2
- data/lib/TokiServer/views/error.erb +13 -4
- data/lib/TokiServer/views/index.erb +36 -27
- data/lib/TokiServer/views/logs_total.erb +34 -0
- data/spec/TokiCLI_spec.rb +354 -0
- data/spec/mock/mock.sqlite3 +0 -0
- data/spec/spec_helper.rb +26 -0
- metadata +78 -23
- data/lib/API/dbapi.rb +0 -488
- data/lib/TokiCLI/app.rb +0 -389
- data/lib/TokiCLI/authorize.rb +0 -77
- data/lib/TokiCLI/export.rb +0 -81
- data/lib/TokiCLI/get_channels.rb +0 -22
- data/lib/TokiCLI/get_messages.rb +0 -32
- data/lib/TokiCLI/import.rb +0 -122
- data/lib/TokiCLI/scan.rb +0 -19
- data/lib/TokiCLI/search_messages.rb +0 -23
- data/lib/TokiServer/README.md +0 -37
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal-new.scss +0 -0
- data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switch.scss +0 -294
- data/lib/TokiServer/views/name_log.erb +0 -50
- data/lib/TokiServer/views/name_split.erb +0 -37
- data/lib/TokiServer/views/name_total.erb +0 -34
data/lib/TokiCLI/app.rb
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
module TokiCLI
|
|
3
|
-
class App < Thor
|
|
4
|
-
package_name "TokiCLI"
|
|
5
|
-
%w{get_messages search_messages get_channels status view authorize export import scan ../API/dbapi}.each {|r| require_relative "#{r}"}
|
|
6
|
-
|
|
7
|
-
desc "version", "Toki version"
|
|
8
|
-
map "-v" => :version
|
|
9
|
-
def version
|
|
10
|
-
puts "\n-- TokiCLI --\n\nVersion:\t#{VERSION}\nUrl:\t\thttp://github.com/ericdke/TokiCLI\n\n"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
desc "serve", "Start a local Toki API server"
|
|
14
|
-
map "server" => :serve
|
|
15
|
-
def serve
|
|
16
|
-
require_relative '../TokiServer/tokiserver'
|
|
17
|
-
#View.new.clear
|
|
18
|
-
puts "\nStarting the Toki API server...\n\nPress [CTRL-C] to stop.\n\nThe index page URL is: http://localhost:4567\n\n"
|
|
19
|
-
TokiServer.run!
|
|
20
|
-
puts "\nToki API server has been shut down.\n\n"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
desc "auth", "App.net login"
|
|
24
|
-
def auth
|
|
25
|
-
begin
|
|
26
|
-
toki = DBAPI.new
|
|
27
|
-
adn = Authorize.new(toki.helpers.toki_path)
|
|
28
|
-
adn.authorize
|
|
29
|
-
rescue Interrupt
|
|
30
|
-
puts Status.canceled
|
|
31
|
-
exit
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
desc "scan", "Scan /Applications to resolve app names"
|
|
36
|
-
def scan
|
|
37
|
-
scanner = Scan.new DBAPI.new
|
|
38
|
-
scanner.scan({verbose: true})
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
desc "total", "Total usage of all apps"
|
|
42
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
43
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
44
|
-
def total
|
|
45
|
-
toki, view = DBAPI.new, View.new
|
|
46
|
-
apps = JSON.parse toki.apps_total
|
|
47
|
-
if apps['meta']['code'] == 200
|
|
48
|
-
view.total_table apps
|
|
49
|
-
else
|
|
50
|
-
puts "\nError:\n\n#{apps}\n\n"
|
|
51
|
-
exit
|
|
52
|
-
end
|
|
53
|
-
if (options[:json] || options[:csv])
|
|
54
|
-
export = Export.new toki, view
|
|
55
|
-
export.apps_total options, apps, 'total'
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
desc "top", "Most used apps"
|
|
60
|
-
option :number, aliases: '-n', type: :numeric, desc: 'Specify the number of apps'
|
|
61
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
62
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
63
|
-
def top
|
|
64
|
-
toki, view = DBAPI.new, View.new
|
|
65
|
-
apps = JSON.parse toki.apps_top(options[:number] || 5)
|
|
66
|
-
if apps['meta']['code'] == 200
|
|
67
|
-
view.total_table apps
|
|
68
|
-
else
|
|
69
|
-
puts "\nError:\n\n#{apps}\n\n"
|
|
70
|
-
exit
|
|
71
|
-
end
|
|
72
|
-
if (options[:json] || options[:csv])
|
|
73
|
-
export = Export.new toki, view
|
|
74
|
-
export.apps_total options, apps, 'top'
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
desc "day DATE", "All apps used on a specific day"
|
|
79
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
80
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
81
|
-
def day(*args)
|
|
82
|
-
abort(Status.specify_day) if args.empty?
|
|
83
|
-
begin
|
|
84
|
-
DateTime.strptime(args[0], '%Y-%m-%d')
|
|
85
|
-
rescue ArgumentError
|
|
86
|
-
abort(Status.specify_day)
|
|
87
|
-
end
|
|
88
|
-
toki, view = DBAPI.new, View.new
|
|
89
|
-
apps = JSON.parse toki.apps_day args[0]
|
|
90
|
-
if apps['meta']['code'] == 200
|
|
91
|
-
view.total_table apps
|
|
92
|
-
else
|
|
93
|
-
puts "\nError:\n\n#{apps}\n\n"
|
|
94
|
-
exit
|
|
95
|
-
end
|
|
96
|
-
if (options[:json] || options[:csv])
|
|
97
|
-
export = Export.new toki, view
|
|
98
|
-
export.apps_total options, apps, "day-#{args[0]}"
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
desc "since DATE", "All apps used since a specific day"
|
|
103
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
104
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
105
|
-
def since *args
|
|
106
|
-
abort(Status.specify_day) if args.empty?
|
|
107
|
-
begin
|
|
108
|
-
DateTime.strptime args[0], '%Y-%m-%d'
|
|
109
|
-
rescue ArgumentError
|
|
110
|
-
abort Status.specify_day
|
|
111
|
-
end
|
|
112
|
-
toki, view = DBAPI.new, View.new
|
|
113
|
-
apps = JSON.parse toki.apps_since args[0]
|
|
114
|
-
if apps['meta']['code'] == 200
|
|
115
|
-
view.total_table apps
|
|
116
|
-
else
|
|
117
|
-
puts "\nError:\n\n#{apps}\n\n"
|
|
118
|
-
exit
|
|
119
|
-
end
|
|
120
|
-
if (options[:json] || options[:csv])
|
|
121
|
-
export = Export.new toki, view
|
|
122
|
-
export.apps_total options, apps, "since-#{args[0]}"
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
desc "before DATE", "All apps used before a specific day"
|
|
127
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
128
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
129
|
-
def before *args
|
|
130
|
-
abort(Status.specify_day) if args.empty?
|
|
131
|
-
begin
|
|
132
|
-
DateTime.strptime args[0], '%Y-%m-%d'
|
|
133
|
-
rescue ArgumentError
|
|
134
|
-
abort Status.specify_day
|
|
135
|
-
end
|
|
136
|
-
toki, view = DBAPI.new, View.new
|
|
137
|
-
apps = JSON.parse toki.apps_before args[0]
|
|
138
|
-
if apps['meta']['code'] == 200
|
|
139
|
-
view.total_table apps
|
|
140
|
-
else
|
|
141
|
-
puts "\nError:\n\n#{apps}\n\n"
|
|
142
|
-
exit
|
|
143
|
-
end
|
|
144
|
-
if (options[:json] || options[:csv])
|
|
145
|
-
export = Export.new toki, view
|
|
146
|
-
export.apps_total options, apps, "before-#{args[0]}"
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
desc "range DATE1 DATE2", "All apps used between two specific days"
|
|
151
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
152
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
153
|
-
def range(*args)
|
|
154
|
-
abort(Status.specify_range) if args.empty? || args.length != 2
|
|
155
|
-
begin
|
|
156
|
-
DateTime.strptime(args[0], '%Y-%m-%d')
|
|
157
|
-
DateTime.strptime(args[1], '%Y-%m-%d')
|
|
158
|
-
rescue ArgumentError
|
|
159
|
-
abort(Status.specify_range)
|
|
160
|
-
end
|
|
161
|
-
toki, view = DBAPI.new, View.new
|
|
162
|
-
apps = JSON.parse toki.apps_range args[0], args[1]
|
|
163
|
-
if apps['meta']['code'] == 200
|
|
164
|
-
view.total_table apps
|
|
165
|
-
else
|
|
166
|
-
puts "\nError:\n\n#{apps}\n\n"
|
|
167
|
-
exit
|
|
168
|
-
end
|
|
169
|
-
if (options[:json] || options[:csv])
|
|
170
|
-
export = Export.new toki, view
|
|
171
|
-
export.apps_total options, apps, "range-#{args[0]}_#{args[1]}"
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
desc "log APP", "Complete log for an app"
|
|
176
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
177
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
178
|
-
option :bundle, aliases: '-b', type: :boolean, desc: "Specify the complete bundle identifier (in case the app name resolve doesn't work)"
|
|
179
|
-
def log(*args)
|
|
180
|
-
abort(Status.specify_name) if args.empty?
|
|
181
|
-
asked = args[0]
|
|
182
|
-
toki = DBAPI.new
|
|
183
|
-
view = View.new
|
|
184
|
-
log = if options[:bundle]
|
|
185
|
-
JSON.parse toki.bundle_log asked
|
|
186
|
-
else
|
|
187
|
-
JSON.parse toki.name_log asked
|
|
188
|
-
end
|
|
189
|
-
if log['meta']['code'] == 200
|
|
190
|
-
view.app_table asked, log
|
|
191
|
-
else
|
|
192
|
-
puts "\nError:\n\n#{log}\n\n"
|
|
193
|
-
exit
|
|
194
|
-
end
|
|
195
|
-
if (options[:json] || options[:csv])
|
|
196
|
-
export = Export.new toki, view
|
|
197
|
-
export.log options, log, "log-#{log['data']['bundle'].gsub('.', '_')}"
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
desc "app APP", "Total tracked time for an app"
|
|
202
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
203
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
204
|
-
option :bundle, aliases: '-b', type: :boolean, desc: "Specify the complete bundle identifier (in case the app name resolve doesn't work)"
|
|
205
|
-
def app *args
|
|
206
|
-
abort(Status.specify_name) if args.empty?
|
|
207
|
-
asked = args[0]
|
|
208
|
-
toki = DBAPI.new
|
|
209
|
-
view = View.new
|
|
210
|
-
app = if options[:bundle]
|
|
211
|
-
JSON.parse toki.bundle_total asked
|
|
212
|
-
else
|
|
213
|
-
JSON.parse toki.name_total asked
|
|
214
|
-
end
|
|
215
|
-
if app['meta']['code'] == 200
|
|
216
|
-
view.total_table app
|
|
217
|
-
else
|
|
218
|
-
puts "\nError:\n\n#{app}\n\n"
|
|
219
|
-
exit
|
|
220
|
-
end
|
|
221
|
-
if (options[:json] || options[:csv])
|
|
222
|
-
export = Export.new toki, view
|
|
223
|
-
export.app_total options, app, "app-#{app['data']['bundle'].gsub('.', '_')}"
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
desc "app_before APP DATE", "Total tracked time for an app before a specific day"
|
|
228
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
229
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
230
|
-
option :bundle, aliases: '-b', type: :boolean, desc: "Specify the complete bundle identifier (in case the app name resolve doesn't work)"
|
|
231
|
-
def app_before *args
|
|
232
|
-
abort('Error') if args.empty? #TODO: better and more complete
|
|
233
|
-
asked = args[0]
|
|
234
|
-
date = args[1]
|
|
235
|
-
begin
|
|
236
|
-
DateTime.strptime args[1], '%Y-%m-%d'
|
|
237
|
-
rescue ArgumentError
|
|
238
|
-
abort Status.specify_day
|
|
239
|
-
end
|
|
240
|
-
toki = DBAPI.new
|
|
241
|
-
view = View.new
|
|
242
|
-
app = if options[:bundle]
|
|
243
|
-
JSON.parse toki.bundle_total_before asked, date
|
|
244
|
-
else
|
|
245
|
-
JSON.parse toki.name_total_before asked, date
|
|
246
|
-
end
|
|
247
|
-
if app['meta']['code'] == 200
|
|
248
|
-
view.total_table app
|
|
249
|
-
else
|
|
250
|
-
puts "\nError:\n\n#{app}\n\n"
|
|
251
|
-
exit
|
|
252
|
-
end
|
|
253
|
-
if (options[:json] || options[:csv])
|
|
254
|
-
export = Export.new toki, view
|
|
255
|
-
export.app_total options, app, "app_before-#{app['data']['bundle'].gsub('.', '_')}_#{args[1]}"
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
desc "app_since APP DATE", "Total tracked time for an app since a specific day"
|
|
260
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
261
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
262
|
-
option :bundle, aliases: '-b', type: :boolean, desc: "Specify the complete bundle identifier (in case the app name resolve doesn't work)"
|
|
263
|
-
def app_since *args
|
|
264
|
-
abort('Error') if args.empty? #TODO: better and more complete
|
|
265
|
-
asked = args[0]
|
|
266
|
-
date = args[1]
|
|
267
|
-
begin
|
|
268
|
-
DateTime.strptime args[1], '%Y-%m-%d'
|
|
269
|
-
rescue ArgumentError
|
|
270
|
-
abort Status.specify_day
|
|
271
|
-
end
|
|
272
|
-
toki = DBAPI.new
|
|
273
|
-
view = View.new
|
|
274
|
-
app = if options[:bundle]
|
|
275
|
-
JSON.parse toki.bundle_total_since asked, date
|
|
276
|
-
else
|
|
277
|
-
JSON.parse toki.name_total_since asked, date
|
|
278
|
-
end
|
|
279
|
-
if app['meta']['code'] == 200
|
|
280
|
-
view.total_table app
|
|
281
|
-
else
|
|
282
|
-
puts "\nError:\n\n#{app}\n\n"
|
|
283
|
-
exit
|
|
284
|
-
end
|
|
285
|
-
if (options[:json] || options[:csv])
|
|
286
|
-
export = Export.new toki, view
|
|
287
|
-
export.app_total options, app, "app_since-#{app['data']['bundle'].gsub('.', '_')}_#{date}"
|
|
288
|
-
end
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
desc "app_day APP DATE", "Total tracked time for an app on a specific day"
|
|
292
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
293
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
294
|
-
option :bundle, aliases: '-b', type: :boolean, desc: "Specify the complete bundle identifier (in case the app name resolve doesn't work)"
|
|
295
|
-
def app_day *args
|
|
296
|
-
abort('Error') if args.empty? #TODO: better and more complete
|
|
297
|
-
asked = args[0]
|
|
298
|
-
date = args[1]
|
|
299
|
-
begin
|
|
300
|
-
DateTime.strptime args[1], '%Y-%m-%d'
|
|
301
|
-
rescue ArgumentError
|
|
302
|
-
abort Status.specify_day
|
|
303
|
-
end
|
|
304
|
-
toki = DBAPI.new
|
|
305
|
-
view = View.new
|
|
306
|
-
app = if options[:bundle]
|
|
307
|
-
JSON.parse toki.bundle_total_day asked, date
|
|
308
|
-
else
|
|
309
|
-
JSON.parse toki.name_total_day asked, date
|
|
310
|
-
end
|
|
311
|
-
if app['meta']['code'] == 200
|
|
312
|
-
view.total_table app
|
|
313
|
-
else
|
|
314
|
-
puts "\nError:\n\n#{app}\n\n"
|
|
315
|
-
exit
|
|
316
|
-
end
|
|
317
|
-
if (options[:json] || options[:csv])
|
|
318
|
-
export = Export.new toki, view
|
|
319
|
-
export.app_total options, app, "app_day-#{app['data']['bundle'].gsub('.', '_')}_#{date}"
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
desc "app_range APP DATE1 DATE2", "total tracked time for an app between two specific days"
|
|
324
|
-
option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file'
|
|
325
|
-
option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file'
|
|
326
|
-
option :bundle, aliases: '-b', type: :boolean, desc: "Specify the complete bundle identifier (in case the app name resolve doesn't work)"
|
|
327
|
-
def app_range *args
|
|
328
|
-
abort('Error') if args.empty? || args.length != 3
|
|
329
|
-
begin
|
|
330
|
-
DateTime.strptime(args[1], '%Y-%m-%d')
|
|
331
|
-
DateTime.strptime(args[2], '%Y-%m-%d')
|
|
332
|
-
rescue ArgumentError
|
|
333
|
-
abort(Status.specify_range)
|
|
334
|
-
end
|
|
335
|
-
toki = DBAPI.new
|
|
336
|
-
view = View.new
|
|
337
|
-
app = if options[:bundle]
|
|
338
|
-
JSON.parse toki.bundle_total_range args[0], args[1], args[2]
|
|
339
|
-
else
|
|
340
|
-
JSON.parse toki.name_total_range args[0], args[1], args[2]
|
|
341
|
-
end
|
|
342
|
-
if app['meta']['code'] == 200
|
|
343
|
-
view.total_table app
|
|
344
|
-
else
|
|
345
|
-
puts "\nError:\n\n#{app}\n\n"
|
|
346
|
-
exit
|
|
347
|
-
end
|
|
348
|
-
if (options[:json] || options[:csv])
|
|
349
|
-
export = Export.new toki, view
|
|
350
|
-
export.app_total options, app, "app_range-#{app['data']['bundle'].gsub('.', '_')}_#{args[1]}_#{args[2]}"
|
|
351
|
-
end
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
desc "restore", "Restore data from App.net and rebuild the Toki.app database"
|
|
355
|
-
def restore
|
|
356
|
-
toki_api = DBAPI.new
|
|
357
|
-
view = View.new
|
|
358
|
-
import = Import.new toki_api, view
|
|
359
|
-
import.restore get_token, get_channel_id
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
private
|
|
363
|
-
|
|
364
|
-
def get_token
|
|
365
|
-
filepath = Dir.home + '/.TokiCLI/config.json'
|
|
366
|
-
if File.exist?(filepath)
|
|
367
|
-
content = JSON.parse(File.read(filepath))
|
|
368
|
-
content['token']
|
|
369
|
-
else
|
|
370
|
-
clear
|
|
371
|
-
abort Status.run_auth
|
|
372
|
-
end
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
def get_channel_id #TODO return ch['counts']['messages'] too
|
|
376
|
-
channels = ADNChannels::GetChannels.new(get_token).get_channels
|
|
377
|
-
channel_id = ''
|
|
378
|
-
channels.each do |ch|
|
|
379
|
-
if ch['type'] == 'us.kkob.toki.sync-b'
|
|
380
|
-
channel_id = ch['id']
|
|
381
|
-
break
|
|
382
|
-
end
|
|
383
|
-
end
|
|
384
|
-
return channel_id.to_i unless channel_id == ''
|
|
385
|
-
abort Status.no_channel
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
end
|
|
389
|
-
end
|
data/lib/TokiCLI/authorize.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
require 'rest_client'
|
|
3
|
-
module TokiCLI
|
|
4
|
-
CLIENT_ID = 'm6AccJFM56ENCn58Vde9cSg3uSpbvAAs'
|
|
5
|
-
CALLBACK_URL = 'http://aya.io/toki_cli/auth.html'
|
|
6
|
-
class Authorize
|
|
7
|
-
def initialize home
|
|
8
|
-
@auth_url = "https://account.app.net/oauth/authenticate?client_id=#{TokiCLI::CLIENT_ID}&response_type=token&redirect_uri=#{TokiCLI::CALLBACK_URL}&scope=basic,messages&include_marker=1"
|
|
9
|
-
@home = home
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def authorize
|
|
13
|
-
puts "\e[H\e[2J"
|
|
14
|
-
old = Dir.home + '/.toki_token'
|
|
15
|
-
if File.exist?(old)
|
|
16
|
-
puts "The old authorization token isn't valid anymore: the file '#{old}' has been deleted.\n\n"
|
|
17
|
-
File.delete(old)
|
|
18
|
-
end
|
|
19
|
-
show_link
|
|
20
|
-
token = get_token
|
|
21
|
-
check_token(token)
|
|
22
|
-
puts "\n\nThanks! Contacting App.net...\n\n"
|
|
23
|
-
user = create_user_data(token, @home)
|
|
24
|
-
puts "Creating TokiCLI folder in '#{user.home_path}' ...\n\n"
|
|
25
|
-
Dir.mkdir("#{user.home_path}") unless Dir.exist?("#{user.home_path}")
|
|
26
|
-
puts "Saving user token...\n\n"
|
|
27
|
-
create_token_file(user)
|
|
28
|
-
puts "Done!\n\n"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def create_token_file(user)
|
|
34
|
-
data = {
|
|
35
|
-
token: user.token,
|
|
36
|
-
id: user.id,
|
|
37
|
-
username: user.username,
|
|
38
|
-
handle: user.handle,
|
|
39
|
-
home: user.home_path
|
|
40
|
-
}
|
|
41
|
-
File.write("#{user.home_path}/config.json", data.to_json)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def show_link
|
|
45
|
-
puts "\nPlease click this URL, or copy/paste it in a browser:\n\n"
|
|
46
|
-
puts @auth_url
|
|
47
|
-
puts "\n"
|
|
48
|
-
puts "then log in with your ADN credentials to authorize TokiCLI.\n\n"
|
|
49
|
-
puts "You will then be redirected to a page showing a 'user token'.\n\n"
|
|
50
|
-
puts "Copy the token then paste it here:\n"
|
|
51
|
-
print "> "
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def get_token
|
|
55
|
-
STDIN.gets.chomp()
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def check_token(token)
|
|
59
|
-
if token.empty? || token.nil?
|
|
60
|
-
puts "\n\nOops, something went wrong, I couldn't get the token. Please try again.\n\n"
|
|
61
|
-
exit
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def create_user_data(token, home_path)
|
|
66
|
-
resp = get_user(token)
|
|
67
|
-
model = Struct.new(:resp, :username, :id, :handle, :home_path, :token)
|
|
68
|
-
username = resp['data']['username']
|
|
69
|
-
model.new(resp, username, resp['data']['id'], "@" + username, home_path, token)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def get_user(token)
|
|
73
|
-
JSON.parse(RestClient.get("https://api.app.net/users/me?access_token=#{token}", :verify_ssl => OpenSSL::SSL::VERIFY_NONE) {|response, request, result| response })
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
end
|