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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -17
  4. data/.rspec +3 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.md +4 -0
  7. data/README.md +99 -163
  8. data/Rakefile +5 -0
  9. data/TokiCLI.gemspec +5 -4
  10. data/bin/toki +2 -2
  11. data/lib/API/helpers.rb +27 -170
  12. data/lib/API/toki_api.rb +227 -0
  13. data/lib/API/toki_db.rb +67 -0
  14. data/lib/TokiCLI.rb +270 -5
  15. data/lib/TokiCLI/adnimport.rb +202 -0
  16. data/lib/TokiCLI/fileops.rb +187 -0
  17. data/lib/TokiCLI/status.rb +49 -37
  18. data/lib/TokiCLI/version.rb +1 -1
  19. data/lib/TokiCLI/view.rb +133 -86
  20. data/lib/TokiServer/.bowerrc +3 -0
  21. data/lib/TokiServer/.gitignore +2 -0
  22. data/lib/TokiServer/Gemfile +1 -0
  23. data/lib/TokiServer/bower.json +0 -0
  24. data/lib/TokiServer/bower_components/fastclick/.bower.json +4 -4
  25. data/lib/TokiServer/bower_components/fastclick/bower.json +1 -1
  26. data/lib/TokiServer/bower_components/fastclick/lib/fastclick.js +33 -2
  27. data/lib/TokiServer/bower_components/foundation/.bower.json +5 -4
  28. data/lib/TokiServer/bower_components/foundation/bower.json +2 -1
  29. data/lib/TokiServer/bower_components/foundation/css/foundation.css +2173 -922
  30. data/lib/TokiServer/bower_components/foundation/css/foundation.css.map +7 -0
  31. data/lib/TokiServer/bower_components/foundation/css/normalize.css +53 -16
  32. data/lib/TokiServer/bower_components/foundation/css/normalize.css.map +7 -0
  33. data/lib/TokiServer/bower_components/foundation/js/foundation.js +782 -542
  34. data/lib/TokiServer/bower_components/foundation/js/foundation.min.js +4 -3
  35. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.abide.js +45 -31
  36. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.accordion.js +12 -6
  37. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.alert.js +5 -5
  38. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.clearing.js +34 -10
  39. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.dropdown.js +83 -29
  40. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.equalizer.js +3 -3
  41. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.interchange.js +25 -12
  42. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.joyride.js +112 -40
  43. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.js +19 -5
  44. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.magellan.js +22 -11
  45. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.offcanvas.js +52 -8
  46. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.orbit.js +133 -271
  47. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.reveal.js +27 -20
  48. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.slider.js +73 -33
  49. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tab.js +88 -31
  50. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.tooltip.js +7 -5
  51. data/lib/TokiServer/bower_components/foundation/js/foundation/foundation.topbar.js +44 -24
  52. data/lib/TokiServer/bower_components/foundation/js/vendor/fastclick.js +2 -2
  53. data/lib/TokiServer/bower_components/foundation/js/vendor/modernizr.js +2 -2
  54. data/lib/TokiServer/bower_components/foundation/scss/foundation.scss +38 -38
  55. data/lib/TokiServer/bower_components/foundation/scss/foundation/_functions.scss +3 -3
  56. data/lib/TokiServer/bower_components/foundation/scss/foundation/_settings.scss +417 -271
  57. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_accordion.scss +110 -6
  58. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_alert-boxes.scss +2 -2
  59. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_block-grid.scss +2 -2
  60. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_breadcrumbs.scss +8 -3
  61. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_button-groups.scss +99 -9
  62. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_buttons.scss +66 -28
  63. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_clearing.scss +5 -5
  64. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown-buttons.scss +4 -4
  65. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_dropdown.scss +48 -35
  66. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_forms.scss +104 -32
  67. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_global.scss +48 -30
  68. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_grid.scss +19 -4
  69. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_icon-bar.scss +293 -0
  70. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_joyride.scss +11 -9
  71. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_keystrokes.scss +4 -4
  72. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_labels.scss +4 -2
  73. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_magellan.scss +1 -1
  74. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_offcanvas.scss +193 -35
  75. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_orbit.scss +92 -147
  76. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pagination.scss +22 -10
  77. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_panels.scss +10 -7
  78. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_pricing-tables.scss +11 -11
  79. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_progress-bars.scss +2 -2
  80. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_range-slider.scss +29 -9
  81. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal.scss +60 -56
  82. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_side-nav.scss +3 -2
  83. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_split-buttons.scss +2 -2
  84. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_sub-nav.scss +2 -2
  85. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switches.scss +226 -0
  86. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tables.scss +13 -7
  87. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tabs.scss +22 -8
  88. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_thumbs.scss +2 -4
  89. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_toolbar.scss +70 -0
  90. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_tooltips.scss +9 -7
  91. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_top-bar.scss +77 -44
  92. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_type.scss +21 -9
  93. data/lib/TokiServer/bower_components/modernizr/.bower.json +4 -4
  94. data/lib/TokiServer/bower_components/modernizr/feature-detects/workers-blobworkers.js +2 -2
  95. data/lib/TokiServer/bower_components/modernizr/grunt.js +1 -1
  96. data/lib/TokiServer/bower_components/modernizr/modernizr.js +2 -2
  97. data/lib/TokiServer/config.rb +0 -0
  98. data/lib/TokiServer/humans.txt +0 -0
  99. data/lib/TokiServer/{itunesicon.rb → itunesicons.rb} +25 -23
  100. data/lib/TokiServer/js/app.js +0 -0
  101. data/lib/TokiServer/public/stylesheets/app.css +2636 -1610
  102. data/lib/TokiServer/robots.txt +0 -0
  103. data/lib/TokiServer/scss/_settings.scss +0 -0
  104. data/lib/TokiServer/scss/app.scss +7 -1
  105. data/lib/TokiServer/tokiserver.rb +239 -244
  106. data/lib/TokiServer/views/activity.erb +42 -0
  107. data/lib/TokiServer/views/apps_total.erb +8 -2
  108. data/lib/TokiServer/views/error.erb +13 -4
  109. data/lib/TokiServer/views/index.erb +36 -27
  110. data/lib/TokiServer/views/logs_total.erb +34 -0
  111. data/spec/TokiCLI_spec.rb +354 -0
  112. data/spec/mock/mock.sqlite3 +0 -0
  113. data/spec/spec_helper.rb +26 -0
  114. metadata +78 -23
  115. data/lib/API/dbapi.rb +0 -488
  116. data/lib/TokiCLI/app.rb +0 -389
  117. data/lib/TokiCLI/authorize.rb +0 -77
  118. data/lib/TokiCLI/export.rb +0 -81
  119. data/lib/TokiCLI/get_channels.rb +0 -22
  120. data/lib/TokiCLI/get_messages.rb +0 -32
  121. data/lib/TokiCLI/import.rb +0 -122
  122. data/lib/TokiCLI/scan.rb +0 -19
  123. data/lib/TokiCLI/search_messages.rb +0 -23
  124. data/lib/TokiServer/README.md +0 -37
  125. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal-new.scss +0 -0
  126. data/lib/TokiServer/bower_components/foundation/scss/foundation/components/_switch.scss +0 -294
  127. data/lib/TokiServer/views/name_log.erb +0 -50
  128. data/lib/TokiServer/views/name_split.erb +0 -37
  129. data/lib/TokiServer/views/name_total.erb +0 -34
Binary file
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ # require 'TokiCLI'
7
+ require_relative '../lib/TokiCLI'
8
+ require_relative '../lib/API/toki_api'
9
+
10
+ require 'stringio'
11
+ def capture_stdout(&blk)
12
+ old = $stdout
13
+ $stdout = fake = StringIO.new
14
+ blk.call
15
+ fake.string
16
+ ensure
17
+ $stdout = old
18
+ end
19
+ def capture_stderr(&blk)
20
+ old = $stderr
21
+ $stderr = fake = StringIO.new
22
+ blk.call
23
+ fake.string
24
+ ensure
25
+ $stderr = old
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TokiCLI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-10 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -134,22 +134,70 @@ dependencies:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: 0.3.2
137
+ - !ruby/object:Gem::Dependency
138
+ name: sinatra-contrib
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '1.4'
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 1.4.2
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '1.4'
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 1.4.2
137
157
  - !ruby/object:Gem::Dependency
138
158
  name: bundler
139
159
  requirement: !ruby/object:Gem::Requirement
140
160
  requirements:
141
161
  - - "~>"
142
162
  - !ruby/object:Gem::Version
143
- version: '1.6'
163
+ version: '1.7'
144
164
  type: :development
145
165
  prerelease: false
146
166
  version_requirements: !ruby/object:Gem::Requirement
147
167
  requirements:
148
168
  - - "~>"
149
169
  - !ruby/object:Gem::Version
150
- version: '1.6'
170
+ version: '1.7'
151
171
  - !ruby/object:Gem::Dependency
152
172
  name: rake
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: '10.0'
178
+ type: :development
179
+ prerelease: false
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - "~>"
183
+ - !ruby/object:Gem::Version
184
+ version: '10.0'
185
+ - !ruby/object:Gem::Dependency
186
+ name: rspec
187
+ requirement: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - "~>"
190
+ - !ruby/object:Gem::Version
191
+ version: '3.0'
192
+ type: :development
193
+ prerelease: false
194
+ version_requirements: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - "~>"
197
+ - !ruby/object:Gem::Version
198
+ version: '3.0'
199
+ - !ruby/object:Gem::Dependency
200
+ name: coveralls
153
201
  requirement: !ruby/object:Gem::Requirement
154
202
  requirements:
155
203
  - - ">="
@@ -173,7 +221,10 @@ executables:
173
221
  extensions: []
174
222
  extra_rdoc_files: []
175
223
  files:
224
+ - ".coveralls.yml"
176
225
  - ".gitignore"
226
+ - ".rspec"
227
+ - ".travis.yml"
177
228
  - CHANGELOG.md
178
229
  - Gemfile
179
230
  - LICENSE.txt
@@ -181,22 +232,18 @@ files:
181
232
  - Rakefile
182
233
  - TokiCLI.gemspec
183
234
  - bin/toki
184
- - lib/API/dbapi.rb
185
235
  - lib/API/helpers.rb
236
+ - lib/API/toki_api.rb
237
+ - lib/API/toki_db.rb
186
238
  - lib/TokiCLI.rb
187
- - lib/TokiCLI/app.rb
188
- - lib/TokiCLI/authorize.rb
189
- - lib/TokiCLI/export.rb
190
- - lib/TokiCLI/get_channels.rb
191
- - lib/TokiCLI/get_messages.rb
192
- - lib/TokiCLI/import.rb
193
- - lib/TokiCLI/scan.rb
194
- - lib/TokiCLI/search_messages.rb
239
+ - lib/TokiCLI/adnimport.rb
240
+ - lib/TokiCLI/fileops.rb
195
241
  - lib/TokiCLI/status.rb
196
242
  - lib/TokiCLI/version.rb
197
243
  - lib/TokiCLI/view.rb
244
+ - lib/TokiServer/.bowerrc
245
+ - lib/TokiServer/.gitignore
198
246
  - lib/TokiServer/Gemfile
199
- - lib/TokiServer/README.md
200
247
  - lib/TokiServer/bower.json
201
248
  - lib/TokiServer/bower_components/fastclick/.bower.json
202
249
  - lib/TokiServer/bower_components/fastclick/LICENSE
@@ -206,7 +253,9 @@ files:
206
253
  - lib/TokiServer/bower_components/foundation/.bower.json
207
254
  - lib/TokiServer/bower_components/foundation/bower.json
208
255
  - lib/TokiServer/bower_components/foundation/css/foundation.css
256
+ - lib/TokiServer/bower_components/foundation/css/foundation.css.map
209
257
  - lib/TokiServer/bower_components/foundation/css/normalize.css
258
+ - lib/TokiServer/bower_components/foundation/css/normalize.css.map
210
259
  - lib/TokiServer/bower_components/foundation/js/foundation.js
211
260
  - lib/TokiServer/bower_components/foundation/js/foundation.min.js
212
261
  - lib/TokiServer/bower_components/foundation/js/foundation/foundation.abide.js
@@ -247,6 +296,7 @@ files:
247
296
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_forms.scss
248
297
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_global.scss
249
298
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_grid.scss
299
+ - lib/TokiServer/bower_components/foundation/scss/foundation/components/_icon-bar.scss
250
300
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_inline-lists.scss
251
301
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_joyride.scss
252
302
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_keystrokes.scss
@@ -259,15 +309,15 @@ files:
259
309
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_pricing-tables.scss
260
310
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_progress-bars.scss
261
311
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_range-slider.scss
262
- - lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal-new.scss
263
312
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_reveal.scss
264
313
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_side-nav.scss
265
314
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_split-buttons.scss
266
315
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_sub-nav.scss
267
- - lib/TokiServer/bower_components/foundation/scss/foundation/components/_switch.scss
316
+ - lib/TokiServer/bower_components/foundation/scss/foundation/components/_switches.scss
268
317
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_tables.scss
269
318
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_tabs.scss
270
319
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_thumbs.scss
320
+ - lib/TokiServer/bower_components/foundation/scss/foundation/components/_toolbar.scss
271
321
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_tooltips.scss
272
322
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_top-bar.scss
273
323
  - lib/TokiServer/bower_components/foundation/scss/foundation/components/_type.scss
@@ -538,20 +588,22 @@ files:
538
588
  - lib/TokiServer/bower_components/modernizr/test/qunit/run-qunit.js
539
589
  - lib/TokiServer/config.rb
540
590
  - lib/TokiServer/humans.txt
541
- - lib/TokiServer/itunesicon.rb
591
+ - lib/TokiServer/itunesicons.rb
542
592
  - lib/TokiServer/js/app.js
543
593
  - lib/TokiServer/public/stylesheets/app.css
544
594
  - lib/TokiServer/robots.txt
545
595
  - lib/TokiServer/scss/_settings.scss
546
596
  - lib/TokiServer/scss/app.scss
547
597
  - lib/TokiServer/tokiserver.rb
598
+ - lib/TokiServer/views/activity.erb
548
599
  - lib/TokiServer/views/apps_total.erb
549
600
  - lib/TokiServer/views/error.erb
550
601
  - lib/TokiServer/views/index.erb
551
602
  - lib/TokiServer/views/layout.erb
552
- - lib/TokiServer/views/name_log.erb
553
- - lib/TokiServer/views/name_split.erb
554
- - lib/TokiServer/views/name_total.erb
603
+ - lib/TokiServer/views/logs_total.erb
604
+ - spec/TokiCLI_spec.rb
605
+ - spec/mock/mock.sqlite3
606
+ - spec/spec_helper.rb
555
607
  homepage: https://github.com/ericdke/TokiCLI
556
608
  licenses:
557
609
  - MIT
@@ -564,7 +616,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
564
616
  requirements:
565
617
  - - ">="
566
618
  - !ruby/object:Gem::Version
567
- version: 2.0.0
619
+ version: '0'
568
620
  required_rubygems_version: !ruby/object:Gem::Requirement
569
621
  requirements:
570
622
  - - ">="
@@ -572,8 +624,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
572
624
  version: '0'
573
625
  requirements: []
574
626
  rubyforge_project:
575
- rubygems_version: 2.3.0
627
+ rubygems_version: 2.4.1
576
628
  signing_key:
577
629
  specification_version: 4
578
630
  summary: Toki.app command-line client and API server
579
- test_files: []
631
+ test_files:
632
+ - spec/TokiCLI_spec.rb
633
+ - spec/mock/mock.sqlite3
634
+ - spec/spec_helper.rb
@@ -1,488 +0,0 @@
1
- # encoding: utf-8
2
- module TokiCLI
3
- class DBAPI
4
-
5
- require 'ostruct'
6
- require 'amalgalite'
7
- require 'CFPropertyList'
8
- require 'terminal-table/import'
9
- require 'json'
10
- require 'fileutils'
11
- require_relative "../TokiCLI/version"
12
- require_relative "helpers"
13
-
14
- attr_accessor :helpers, :db, :table
15
-
16
- def initialize
17
- @helpers = Helpers.new
18
- @db = @helpers.db
19
- @table = @helpers.table
20
- end
21
-
22
- ## ENDPOINTS
23
-
24
- # Get the total time for an app given its exact bundle identifier
25
- def bundle_total bundle_id, orig = nil
26
- sec = (@db.execute("SELECT sum(totalSeconds) FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}'").flatten)[0]
27
- sec = 0 if sec.nil?
28
- args = if orig.nil?
29
- [bundle_id]
30
- else
31
- [bundle_id, orig]
32
- end
33
- { meta: {
34
- code: 200,
35
- request: {command: 'bundle_total', args: args, processed_at: Time.now}
36
- },
37
- data: {
38
- bundle: bundle_id,
39
- name: @helpers.find_app_name(bundle_id),
40
- total: {
41
- seconds: sec,
42
- time: @helpers.sec_to_time(sec)
43
- }
44
- }
45
- }.to_json
46
- end
47
-
48
- # Get the total time for an app given a (partial) name
49
- def name_total name
50
- bun = JSON.parse(get_bundle_from_name(name))
51
- if bun['meta']['code'] == 200
52
- bundle_total bun['data']['bundle'], name
53
- else
54
- @helpers.json_nodata
55
- end
56
- end
57
-
58
- # Get the total time for an app given its exact bundle identifier, since a specific day
59
- def bundle_total_since bundle_id, day, orig = nil
60
- since = (@db.execute("SELECT sum(totalSeconds) FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}' AND activeFrom >= #{Time.parse(day).to_i}").flatten)[0]
61
- since = 0 if since.nil?
62
- args = if orig.nil?
63
- [bundle_id, day]
64
- else
65
- [bundle_id, day, orig]
66
- end
67
- { meta: {
68
- code: 200,
69
- request: {command: 'bundle_total_since', args: args, processed_at: Time.now}
70
- },
71
- data: {
72
- bundle: bundle_id,
73
- name: @helpers.find_app_name(bundle_id),
74
- since: day,
75
- total: {
76
- seconds: since,
77
- time: @helpers.sec_to_time(since)
78
- }
79
- }
80
- }.to_json
81
- end
82
-
83
- # Get the total time for an app given a (partial) name, since a specific day
84
- def name_total_since name, day
85
- bun = JSON.parse(get_bundle_from_name(name))
86
- if bun['meta']['code'] == 200
87
- bundle_total_since bun['data']['bundle'], day, name
88
- else
89
- return_422 'name_total_since', [name, day]
90
- end
91
- end
92
-
93
- # Get the total time for an app given its exact bundle identifier, before a specific day
94
- def bundle_total_before bundle_id, day, orig = nil
95
- before = (@db.execute("SELECT sum(totalSeconds) FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}' AND activeFrom < #{Time.parse(day).to_i}").flatten)[0]
96
- before = 0 if before.nil?
97
- args = if orig.nil?
98
- [bundle_id, day]
99
- else
100
- [bundle_id, day, orig]
101
- end
102
- { meta: {
103
- code: 200,
104
- request: {command: 'bundle_total_before', args: args, processed_at: Time.now}
105
- },
106
- data: {
107
- bundle: bundle_id,
108
- name: @helpers.find_app_name(bundle_id),
109
- before: day,
110
- total: {
111
- seconds: before,
112
- time: @helpers.sec_to_time(before)
113
- }
114
- }
115
- }.to_json
116
- end
117
-
118
- # Get the total time for an app given a (partial) name, before a specific day
119
- def name_total_before name, day
120
- bun = JSON.parse(get_bundle_from_name(name))
121
- if bun['meta']['code'] == 200
122
- bundle_total_before bun['data']['bundle'], day, name
123
- else
124
- return_422 'name_total_before', [name, day]
125
- end
126
- end
127
-
128
- # Get the total time for an app given its exact bundle identifier, before and since a specific day
129
- def bundle_total_split bundle_id, day, orig = nil
130
- before = (@db.execute("SELECT sum(totalSeconds) FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}' AND activeFrom < #{Time.parse(day).to_i}").flatten)[0]
131
- since = (@db.execute("SELECT sum(totalSeconds) FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}' AND activeFrom >= #{Time.parse(day).to_i}").flatten)[0]
132
- before = 0 if before.nil?
133
- since = 0 if since.nil?
134
- args = if orig.nil?
135
- [bundle_id, day]
136
- else
137
- [bundle_id, day, orig]
138
- end
139
- { meta: {
140
- code: 200,
141
- request: {command: 'bundle_total_split', args: args, processed_at: Time.now}
142
- },
143
- data: {
144
- bundle: bundle_id,
145
- name: @helpers.find_app_name(bundle_id),
146
- split: day,
147
- total: {
148
- seconds: {
149
- before: before,
150
- since: since
151
- },
152
- time: {
153
- before: @helpers.sec_to_time(before),
154
- since: @helpers.sec_to_time(since)
155
- }
156
- }
157
- }
158
- }.to_json
159
- end
160
-
161
- # Get the total time for an app given a (partial) name, before and since a specific day
162
- def name_total_split name, day
163
- bun = JSON.parse(get_bundle_from_name(name))
164
- if bun['meta']['code'] == 200
165
- bundle_total_split bun['data']['bundle'], day, name
166
- else
167
- return_422 'name_total_split', [name, day]
168
- end
169
- end
170
-
171
- # Get the total time for an app given its exact bundle identifier, between two specific days
172
- def bundle_total_range bundle_id, day1, day2, orig = nil
173
- total = (@db.execute("SELECT sum(totalSeconds) FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}' AND activeFrom >= #{Time.parse(day1).to_i} AND activeFrom < #{Time.parse(day2).to_i}").flatten)[0]
174
- args = if orig.nil?
175
- [bundle_id, day1, day2]
176
- else
177
- [bundle_id, day1, day2, orig]
178
- end
179
- total = 0 if total.nil?
180
- { meta: {
181
- code: 200,
182
- request: {command: 'bundle_total_range', args: args, processed_at: Time.now}
183
- },
184
- data: {
185
- bundle: bundle_id,
186
- name: @helpers.find_app_name(bundle_id),
187
- from: day1,
188
- to: day2,
189
- total: {
190
- seconds: total,
191
- time: @helpers.sec_to_time(total)
192
- }
193
- }
194
- }.to_json
195
- end
196
-
197
- # Get the total time for an app given a (partial) name, between two specific days
198
- def name_total_range name, day1, day2
199
- bun = JSON.parse(get_bundle_from_name(name))
200
- if bun['meta']['code'] == 200
201
- bundle_total_range bun['data']['bundle'], day1, day2, name
202
- else
203
- return_422 'name_total_range', [name, day1, day2]
204
- end
205
- end
206
-
207
- # Get all apps used between day 1 and day 2
208
- def apps_range day1, day2
209
- result = []
210
- range = @db.execute("SELECT bundleIdentifier,sum(totalSeconds) FROM #{@table} WHERE activeFrom >= #{Time.parse(day1).to_i} AND activeFrom < #{Time.parse(day2).to_i} GROUP BY bundleIdentifier")
211
- range.each {|id,sec| result << {
212
- bundle: id,
213
- name: @helpers.find_app_name(id),
214
- total: {
215
- seconds: sec,
216
- time: @helpers.sec_to_time(sec)
217
- }}
218
- }
219
- if result.empty?
220
- return_422('apps_range', [day1, day2])
221
- else
222
- result.sort_by! {|obj| obj[:total][:seconds]}
223
- {
224
- meta: {
225
- code: 200,
226
- request: {command: 'apps_range', args: [day1, day2], processed_at: Time.now}
227
- },
228
- data: {
229
- from: day1,
230
- to: day2,
231
- apps: result
232
- }
233
- }.to_json
234
- end
235
- end
236
-
237
- # Get all apps used on a specific day
238
- def apps_day day
239
- date = DateTime.strptime(day, '%Y-%m-%d')
240
- response = @db.execute("SELECT bundleIdentifier,sum(totalSeconds) FROM #{@table} WHERE activeFrom >= #{date.to_time.to_i} AND activeFrom < #{date.next_day.to_time.to_i} GROUP BY bundleIdentifier")
241
- result = make_apps response
242
- if result.empty?
243
- return_422 'apps_day', [day]
244
- else
245
- {
246
- meta: {
247
- code: 200,
248
- request: {command: 'apps_day', args: [day], processed_at: Time.now}
249
- },
250
- data: {
251
- date: day,
252
- apps: result
253
- }
254
- }.to_json
255
- end
256
- end
257
-
258
- def apps_since day
259
- date = DateTime.strptime(day, '%Y-%m-%d')
260
- response = @db.execute("SELECT bundleIdentifier,sum(totalSeconds) FROM #{@table} WHERE activeFrom >= #{date.to_time.to_i} GROUP BY bundleIdentifier")
261
- result = make_apps response
262
- if result.empty?
263
- return_422 'apps_since', [day]
264
- else
265
- {
266
- meta: {
267
- code: 200,
268
- request: {command: 'apps_since', args: [day], processed_at: Time.now}
269
- },
270
- data: {
271
- since: day,
272
- apps: result
273
- }
274
- }.to_json
275
- end
276
- end
277
-
278
- def apps_before day
279
- date = DateTime.strptime(day, '%Y-%m-%d')
280
- response = @db.execute("SELECT bundleIdentifier,sum(totalSeconds) FROM #{@table} WHERE activeFrom < #{date.to_time.to_i} GROUP BY bundleIdentifier")
281
- result = make_apps response
282
- if result.empty?
283
- return_422 'apps_before', [day]
284
- else
285
- {
286
- meta: {
287
- code: 200,
288
- request: {command: 'apps_before', args: [day], processed_at: Time.now}
289
- },
290
- data: {
291
- before: day,
292
- apps: result
293
- }
294
- }.to_json
295
- end
296
- end
297
-
298
- # Get totals of all tracked apps
299
- def apps_total
300
- result = make_total
301
- {
302
- meta: {
303
- code: 200,
304
- request: {command: 'apps_total', args: [], processed_at: Time.now}
305
- },
306
- data: {
307
- apps: result
308
- }
309
- }.to_json
310
- end
311
-
312
- # Get totals of top tracked apps
313
- def apps_top number = 5
314
- result = make_total
315
- args = [number]
316
- index = -number
317
- apps = result[index..-1]
318
- if apps.nil?
319
- return_422 'apps_top', args
320
- else
321
- {
322
- meta: {
323
- code: 200,
324
- request: {command: 'apps_top', args: args, processed_at: Time.now}
325
- },
326
- data: {
327
- apps: apps
328
- }
329
- }.to_json
330
- end
331
- end
332
-
333
- def return_422 command_name, args
334
- {
335
- meta: {
336
- code: 422,
337
- request: {command: command_name, args: args, processed_at: Time.now},
338
- message: 'No data returned by this request'
339
- },
340
- data: {
341
- apps: []
342
- }
343
- }.to_json
344
- end
345
-
346
- # Get the complete log for an app
347
- def bundle_log bundle_id, orig = nil
348
- log = @db.execute("SELECT * FROM #{@table} WHERE bundleIdentifier IS '#{bundle_id}'")
349
- # id (INTEGER) 0, bundleIdentifier (VARCHAR) 1, activeFrom (INTEGER) 2, activeTo (INTEGER) 3, totalSeconds (INTEGER) 4, UUID (VARCHAR) 5, synced (INTEGER) 6, availableToSync (INTEGER) 7
350
- result = {}
351
- log.each do |arr|
352
- result[arr[0]] = {
353
- start: @helpers.epoch_to_date(arr[2]),
354
- duration: {
355
- seconds: arr[4],
356
- time: @helpers.seconds_to_time(arr[4])
357
- }
358
- }
359
- end
360
- args = if orig.nil?
361
- [bundle_id]
362
- else
363
- [bundle_id, orig]
364
- end
365
- { meta: {
366
- code: 200,
367
- request: {command: 'bundle_total', args: args, processed_at: Time.now}
368
- },
369
- data: {
370
- bundle: bundle_id,
371
- name: @helpers.find_app_name(bundle_id),
372
- log: result
373
- }
374
- }.to_json
375
- end
376
-
377
- # Get the complete log for an app, given a (partial) name
378
- def name_log name
379
- bun = JSON.parse(get_bundle_from_name(name))
380
- if bun['meta']['code'] == 200
381
- bundle_log bun['data']['bundle'], name
382
- else
383
- @helpers.json_nodata
384
- end
385
- end
386
-
387
-
388
- ## TOOLS
389
-
390
- # Get all data from database
391
- def get_all_data
392
- (@helpers.get_all_data).to_json
393
- end
394
-
395
- # Scan disk for installed apps
396
- def scan_apps
397
- apps = []
398
- (@helpers.scan).each do |id,name|
399
- apps << {bundle: id, name: name}
400
- end
401
- {
402
- meta: {
403
- code: 200,
404
- request: {
405
- command: 'scan_apps',
406
- processed_at: Time.now
407
- }
408
- },
409
- data: {
410
- apps: apps
411
- }
412
- }.to_json
413
- end
414
-
415
- # List of tracked apps
416
- # (Run scan_apps before if necessary)
417
- def tracked_apps
418
- apps, ids = [], (@db.execute("SELECT bundleIdentifier FROM #{@table}")).flatten.uniq!
419
- ids.each do |id|
420
- @helpers.bundles.has_key?(id) ? apps << {bundle: id, name: @helpers.bundles[id]} : apps << {bundle: id, name: id}
421
- end
422
- {
423
- meta: {
424
- code: 200,
425
- request: {
426
- command: 'tracked_apps',
427
- processed_at: Time.now
428
- }
429
- },
430
- data: {
431
- apps: apps
432
- }
433
- }.to_json
434
- end
435
-
436
- # Get bundle_id from app name or partial app name
437
- # (Run scan_apps before if necessary)
438
- def get_bundle_from_name name
439
- resp = @helpers.get_bundle_from_name name
440
- meta = {
441
- request: {
442
- command: 'get_bundle_from_name',
443
- args: [name],
444
- processed_at: Time.now
445
- }
446
- }
447
- resp.empty? ?
448
- {
449
- meta: meta.merge!({
450
- code: 404,
451
- error: { message: "Unable to find an app containing '#{name}'" }
452
- }),
453
- data: {}
454
- }.to_json :
455
- {
456
- meta: meta.merge!({code: 200}),
457
- data: {
458
- request: name,
459
- bundle: resp[1],
460
- name: resp[0]
461
- }
462
- }.to_json
463
- end
464
-
465
- private
466
-
467
- def make_total
468
- response = @db.execute("SELECT bundleIdentifier,sum(totalSeconds) FROM #{@table} GROUP BY bundleIdentifier")
469
- make_apps response
470
- end
471
-
472
- def make_apps response
473
- result = []
474
- response.each {|id,sec| result << {
475
- bundle: id,
476
- name: @helpers.find_app_name(id),
477
- total: {
478
- seconds: sec,
479
- time: @helpers.sec_to_time(sec)
480
- }
481
- }
482
- }
483
- result.sort_by! {|obj| obj[:total][:seconds]}
484
- result
485
- end
486
-
487
- end
488
- end